https://github.com/frasercrmck created https://github.com/llvm/llvm-project/pull/146833
These changes were split off from #146503. This commit makes the output directories of libclc artefacts explicit. It creates a variable for the final output directory - LIBCLC_OUTPUT_LIBRARY_DIR - which has not changed. This allows future changes to alter the output directory more simply, such as by pointing it to somewhere inside clang's resource directory. This commit also changes the output directory of each target's intermediate builtins.*.bc files. They are now placed into each respective libclc target's object directory, rather than the top-level libclc binary directory. This should help keep the binary directory a bit tidier. >From 27ede3bfae2776deef2dfce803a5f500bf0c7278 Mon Sep 17 00:00:00 2001 From: Fraser Cormack <fra...@codeplay.com> Date: Thu, 3 Jul 2025 09:24:59 +0100 Subject: [PATCH] [libclc] Make library output directories explicit These changes were split off from #146503. This commit makes the output directories of libclc artefacts explicit. It creates a variable for the final output directory - LIBCLC_OUTPUT_LIBRARY_DIR - which has not changed. This allows future changes to alter the output directory more simply, such as by pointing it to somewhere inside clang's resource directory. This commit also changes the output directory of each target's intermediate builtins.*.bc files. They are now placed into each respective libclc target's object directory, rather than the top-level libclc binary directory. This should help keep the binary directory a bit tidier. --- libclc/CMakeLists.txt | 3 ++ libclc/cmake/modules/AddLibclc.cmake | 59 +++++++++++++++++----------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index c98e2043464d9..e2871d1b01a16 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -84,6 +84,9 @@ else() endif() endif() +# Setup the paths where libclc runtimes should be stored. +set( LIBCLC_OUTPUT_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) + if( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} ) message( WARNING "Using custom LLVM tools to build libclc: " "${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}, " diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index c521ea1589484..c4434c34a7fd7 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -120,14 +120,15 @@ function(link_bc) endif() add_custom_command( - OUTPUT ${ARG_TARGET}.bc - COMMAND ${llvm-link_exe} ${link_flags} -o ${ARG_TARGET}.bc ${LINK_INPUT_ARG} + OUTPUT ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc + COMMAND ${llvm-link_exe} ${link_flags} -o ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc ${LINK_INPUT_ARG} DEPENDS ${llvm-link_target} ${ARG_DEPENDENCIES} ${ARG_INPUTS} ${RSP_FILE} + WORKING_DIRECTORY ${LIBCLC_ARCH_OBJFILE_DIR} ) - add_custom_target( ${ARG_TARGET} ALL DEPENDS ${ARG_TARGET}.bc ) + add_custom_target( ${ARG_TARGET} ALL DEPENDS ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc ) set_target_properties( ${ARG_TARGET} PROPERTIES - TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.bc + TARGET_FILE ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc FOLDER "libclc/Device IR/Linking" ) endfunction() @@ -360,33 +361,39 @@ function(add_libclc_builtin_set) # llvm-spirv tool. if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 ) set( obj_suffix ${ARG_ARCH_SUFFIX}.spv ) - add_custom_command( OUTPUT ${obj_suffix} - COMMAND ${llvm-spirv_exe} ${spvflags} -o ${obj_suffix} ${builtins_link_lib} + set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} ) + add_custom_command( OUTPUT ${libclc_builtins_lib} + COMMAND ${llvm-spirv_exe} ${spvflags} -o ${libclc_builtins_lib} ${builtins_link_lib} DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt} + WORKING_DIRECTORY ${LIBCLC_OUTPUT_LIBRARY_DIR} ) else() # Non-SPIR-V targets add an extra step to optimize the bytecode set( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} ) - add_custom_command( OUTPUT ${builtins_opt_lib_tgt}.bc - COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${builtins_opt_lib_tgt}.bc + add_custom_command( OUTPUT ${LIBCLC_ARCH_OBJFILE_DIR}/${builtins_opt_lib_tgt}.bc + COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${LIBCLC_ARCH_OBJFILE_DIR}/${builtins_opt_lib_tgt}.bc ${builtins_link_lib} DEPENDS ${opt_target} ${builtins_link_lib} ${builtins_link_lib_tgt} + WORKING_DIRECTORY ${LIBCLC_ARCH_OBJFILE_DIR} ) add_custom_target( ${builtins_opt_lib_tgt} - ALL DEPENDS ${builtins_opt_lib_tgt}.bc + ALL DEPENDS ${LIBCLC_ARCH_OBJFILE_DIR}/${builtins_opt_lib_tgt}.bc ) set_target_properties( ${builtins_opt_lib_tgt} PROPERTIES - TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${builtins_opt_lib_tgt}.bc + TARGET_FILE ${LIBCLC_ARCH_OBJFILE_DIR}/${builtins_opt_lib_tgt}.bc FOLDER "libclc/Device IR/Opt" ) set( builtins_opt_lib $<TARGET_PROPERTY:${builtins_opt_lib_tgt},TARGET_FILE> ) set( obj_suffix ${ARG_ARCH_SUFFIX}.bc ) - add_custom_command( OUTPUT ${obj_suffix} - COMMAND ${prepare_builtins_exe} -o ${obj_suffix} ${builtins_opt_lib} - DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target} ) + set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} ) + add_custom_command( OUTPUT ${libclc_builtins_lib} + COMMAND ${prepare_builtins_exe} -o ${libclc_builtins_lib} ${builtins_opt_lib} + DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target} + WORKING_DIRECTORY ${LIBCLC_OUTPUT_LIBRARY_DIR} + ) endif() # Add a 'prepare' target @@ -402,7 +409,7 @@ function(add_libclc_builtin_set) add_dependencies( prepare-${ARG_TRIPLE} prepare-${obj_suffix} ) install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} + FILES ${libclc_builtins_lib} DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) @@ -418,20 +425,28 @@ function(add_libclc_builtin_set) # * clspv targets don't include all OpenCL builtins if( NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" ) add_test( NAME external-calls-${obj_suffix} - COMMAND ./check_external_calls.sh ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} ${LLVM_TOOLS_BINARY_DIR} + COMMAND ./check_external_calls.sh ${libclc_builtins_lib} ${LLVM_TOOLS_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) endif() foreach( a ${ARG_ALIASES} ) set( alias_suffix "${a}-${ARG_TRIPLE}.bc" ) add_custom_command( - OUTPUT ${alias_suffix} - COMMAND ${CMAKE_COMMAND} -E create_symlink ${obj_suffix} ${alias_suffix} - DEPENDS prepare-${obj_suffix} ) - add_custom_target( alias-${alias_suffix} ALL DEPENDS ${alias_suffix} ) - set_target_properties( alias-${alias_suffix} PROPERTIES FOLDER "libclc/Device IR/Aliases" ) - install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${alias_suffix} - DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) + OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} + COMMAND ${CMAKE_COMMAND} -E create_symlink ${libclc_builtins_lib} ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} + DEPENDS prepare-${obj_suffix} + WORKING_DIRECTORY ${LIBCLC_OUTPUT_LIBRARY_DIR} + ) + add_custom_target( alias-${alias_suffix} ALL + DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} + ) + set_target_properties( alias-${alias_suffix} + PROPERTIES FOLDER "libclc/Device IR/Aliases" + ) + install( + FILES ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix} + DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" + ) endforeach( a ) endfunction(add_libclc_builtin_set) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits