Ericson2314 created this revision. Ericson2314 added reviewers: beanz, compnerd, phosek. Herald added subscribers: ayermolo, sdasgup3, wenzhicui, wrengr, Chia-hungDuan, dcaballe, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, lucyrfox, mgester, arpith-jacob, antiagainst, shauheen, mravishankar, rriddle, mehdi_amini, mgorny. Herald added a reviewer: antiagainst. Herald added a reviewer: sscalpone. Herald added a reviewer: rafauler. Herald added a reviewer: Amir. Herald added a reviewer: maksfb. Herald added a project: Flang. Ericson2314 requested review of this revision. Herald added a reviewer: jdoerfert. Herald added subscribers: llvm-commits, openmp-commits, cfe-commits, yota9, sstefan1, stephenneuendorffer, nicolasvasilache, jdoerfert. Herald added projects: clang, OpenMP, MLIR, LLVM.
First of all, `LLVM_TOOLS_INSTALL_DIR` put there breaks our NixOS builds, because `LLVM_TOOLS_INSTALL_DIR` defined the same as `CMAKE_INSTALL_BINDIR` becomes an *absolute* path, and then when downstream projects try to install there too this breaks because our builds always install to fresh directories for isolation's sake. Second of all, note that `LLVM_TOOLS_INSTALL_DIR` stands out against the other specially crafted `LLVM_CONFIG_*` variables substituted in `llvm/cmake/modules/LLVMConfig.cmake.in`. @beanz added it in d0e1c2a550ef348aae036d0fe78cab6f038c420c to fix a dangling reference in `AddLLVM`, but I am suspicious of how this variable doesn't follow the pattern. Those other ones are carefully made to be build-time vs install-time variables depending on which `LLVMConfig.cmake` is being generated, are carefully made relative as appropriate, etc. etc. For my NixOS use-case they are also fine because they are never used as downstream install variables, only for reading not writing. To avoid the problems I face, and restore symmetry, I deleted the exported and arranged to have many `${project}_TOOLS_INSTALL_DIR`s. `AddLLVM` now instead expects each project to define its own, and they do so based on `CMAKE_INSTALL_BINDIR`. `LLVMConfig` still exports `LLVM_TOOLS_BINARY_DIR` which is the location for the tools defined in the usual way, matching the other remaining exported variables. For the `AddLLVM` changes, I tried to copy the existing pattern of internal vs non-internal or for LLVM vs for downstream function/macro names, but it would good to confirm I did that correctly. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D117977 Files: bolt/tools/CMakeLists.txt bolt/tools/driver/CMakeLists.txt bolt/tools/merge-fdata/CMakeLists.txt clang/CMakeLists.txt clang/cmake/modules/AddClang.cmake flang/CMakeLists.txt flang/cmake/modules/AddFlang.cmake lld/CMakeLists.txt lld/cmake/modules/AddLLD.cmake llvm/cmake/modules/AddLLVM.cmake llvm/cmake/modules/CMakeLists.txt llvm/cmake/modules/LLVMConfig.cmake.in llvm/cmake/modules/TableGen.cmake mlir/CMakeLists.txt mlir/cmake/modules/AddMLIR.cmake mlir/tools/mlir-cpu-runner/CMakeLists.txt mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt mlir/tools/mlir-lsp-server/CMakeLists.txt mlir/tools/mlir-opt/CMakeLists.txt mlir/tools/mlir-pdll/CMakeLists.txt mlir/tools/mlir-reduce/CMakeLists.txt mlir/tools/mlir-spirv-cpu-runner/CMakeLists.txt mlir/tools/mlir-translate/CMakeLists.txt mlir/tools/mlir-vulkan-runner/CMakeLists.txt openmp/libomptarget/tools/deviceinfo/CMakeLists.txt openmp/tools/CMakeLists.txt
Index: openmp/tools/CMakeLists.txt =================================================================== --- openmp/tools/CMakeLists.txt +++ openmp/tools/CMakeLists.txt @@ -1,3 +1,17 @@ +set(OPENMP_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')") +mark_as_advanced(OPENMP_TOOLS_INSTALL_DIR) + +# Move these macros to AddOpenMP if such a CMake module is ever created. + +macro(add_openmp_tool name) + llvm_add_tool(OPENMP ${ARGV}) +endmacro() + +macro(add_openmp_tool_symlink name) + llvm_add_tool_symlink(OPENMP ${ARGV}) +endmacro() + # Discover the tools that use CMake in the subdirectories. # Note that explicit cmake invocation is required every time a new tool # is added or removed. Index: openmp/libomptarget/tools/deviceinfo/CMakeLists.txt =================================================================== --- openmp/libomptarget/tools/deviceinfo/CMakeLists.txt +++ openmp/libomptarget/tools/deviceinfo/CMakeLists.txt @@ -12,7 +12,7 @@ libomptarget_say("Building the llvm-omp-device-info tool") -add_llvm_tool(llvm-omp-device-info llvm-omp-device-info.cpp) +llvm_add_tool(OPENMP llvm-omp-device-info llvm-omp-device-info.cpp) llvm_update_compile_flags(llvm-omp-device-info) Index: mlir/tools/mlir-vulkan-runner/CMakeLists.txt =================================================================== --- mlir/tools/mlir-vulkan-runner/CMakeLists.txt +++ mlir/tools/mlir-vulkan-runner/CMakeLists.txt @@ -88,7 +88,7 @@ LIST(APPEND targets_to_link "LLVM${t}") ENDFOREACH(t) - add_llvm_tool(mlir-vulkan-runner + add_mlir_tool(mlir-vulkan-runner mlir-vulkan-runner.cpp DEPENDS Index: mlir/tools/mlir-translate/CMakeLists.txt =================================================================== --- mlir/tools/mlir-translate/CMakeLists.txt +++ mlir/tools/mlir-translate/CMakeLists.txt @@ -5,7 +5,7 @@ get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) -add_llvm_tool(mlir-translate +add_mlir_tool(mlir-translate mlir-translate.cpp ) llvm_update_compile_flags(mlir-translate) Index: mlir/tools/mlir-spirv-cpu-runner/CMakeLists.txt =================================================================== --- mlir/tools/mlir-spirv-cpu-runner/CMakeLists.txt +++ mlir/tools/mlir-spirv-cpu-runner/CMakeLists.txt @@ -5,7 +5,7 @@ if (MLIR_ENABLE_SPIRV_CPU_RUNNER) message(STATUS "Building SPIR-V CPU runner") - add_llvm_tool(mlir-spirv-cpu-runner + add_mlir_tool(mlir-spirv-cpu-runner mlir-spirv-cpu-runner.cpp ) Index: mlir/tools/mlir-reduce/CMakeLists.txt =================================================================== --- mlir/tools/mlir-reduce/CMakeLists.txt +++ mlir/tools/mlir-reduce/CMakeLists.txt @@ -17,7 +17,7 @@ MLIRReduceLib ) -add_llvm_tool(mlir-reduce +add_mlir_tool(mlir-reduce mlir-reduce.cpp DEPENDS Index: mlir/tools/mlir-pdll/CMakeLists.txt =================================================================== --- mlir/tools/mlir-pdll/CMakeLists.txt +++ mlir/tools/mlir-pdll/CMakeLists.txt @@ -3,7 +3,7 @@ MLIRPDLLParser ) -add_llvm_tool(mlir-pdll +add_mlir_tool(mlir-pdll mlir-pdll.cpp DEPENDS Index: mlir/tools/mlir-opt/CMakeLists.txt =================================================================== --- mlir/tools/mlir-opt/CMakeLists.txt +++ mlir/tools/mlir-opt/CMakeLists.txt @@ -60,7 +60,7 @@ ${LIBS} ) -add_llvm_tool(mlir-opt +add_mlir_tool(mlir-opt mlir-opt.cpp DEPENDS Index: mlir/tools/mlir-lsp-server/CMakeLists.txt =================================================================== --- mlir/tools/mlir-lsp-server/CMakeLists.txt +++ mlir/tools/mlir-lsp-server/CMakeLists.txt @@ -41,7 +41,7 @@ MLIRIR ) -add_llvm_tool(mlir-lsp-server +add_mlir_tool(mlir-lsp-server mlir-lsp-server.cpp DEPENDS Index: mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt =================================================================== --- mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt +++ mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt @@ -4,7 +4,7 @@ ) # New mlir-linalg-ods-yaml-gen. -add_llvm_tool(mlir-linalg-ods-yaml-gen +add_mlir_tool(mlir-linalg-ods-yaml-gen mlir-linalg-ods-yaml-gen.cpp ) llvm_update_compile_flags(mlir-linalg-ods-yaml-gen) Index: mlir/tools/mlir-cpu-runner/CMakeLists.txt =================================================================== --- mlir/tools/mlir-cpu-runner/CMakeLists.txt +++ mlir/tools/mlir-cpu-runner/CMakeLists.txt @@ -5,7 +5,7 @@ native ) -add_llvm_tool(mlir-cpu-runner +add_mlir_tool(mlir-cpu-runner mlir-cpu-runner.cpp ) llvm_update_compile_flags(mlir-cpu-runner) Index: mlir/cmake/modules/AddMLIR.cmake =================================================================== --- mlir/cmake/modules/AddMLIR.cmake +++ mlir/cmake/modules/AddMLIR.cmake @@ -196,6 +196,10 @@ endif() endfunction(add_mlir_library) +macro(add_mlir_tool name) + llvm_add_tool(MLIR ${ARGV}) +endmacro() + # Sets a variable with a transformed list of link libraries such individual # libraries will be dynamically excluded when evaluated on a final library # which defines an MLIR_AGGREGATE_EXCLUDE_LIBS which contains any of the Index: mlir/CMakeLists.txt =================================================================== --- mlir/CMakeLists.txt +++ mlir/CMakeLists.txt @@ -32,6 +32,10 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") endif() +set(MLIR_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')") +mark_as_advanced(MLIR_TOOLS_INSTALL_DIR) + set(MLIR_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) set(MLIR_MAIN_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include ) Index: llvm/cmake/modules/TableGen.cmake =================================================================== --- llvm/cmake/modules/TableGen.cmake +++ llvm/cmake/modules/TableGen.cmake @@ -189,7 +189,7 @@ install(TARGETS ${target} ${export_to_llvmexports} COMPONENT ${target} - RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR}) + RUNTIME DESTINATION "${${project}_TOOLS_INSTALL_DIR}") if(NOT LLVM_ENABLE_IDE) add_llvm_install_targets("install-${target}" DEPENDS ${target} Index: llvm/cmake/modules/LLVMConfig.cmake.in =================================================================== --- llvm/cmake/modules/LLVMConfig.cmake.in +++ llvm/cmake/modules/LLVMConfig.cmake.in @@ -123,7 +123,6 @@ set(LLVM_BINARY_DIR "@LLVM_CONFIG_BINARY_DIR@") set(LLVM_CMAKE_DIR "@LLVM_CONFIG_CMAKE_DIR@") set(LLVM_TOOLS_BINARY_DIR "@LLVM_CONFIG_TOOLS_BINARY_DIR@") -set(LLVM_TOOLS_INSTALL_DIR "@LLVM_TOOLS_INSTALL_DIR@") set(LLVM_HAVE_OPT_VIEWER_MODULES @LLVM_HAVE_OPT_VIEWER_MODULES@) set(LLVM_CONFIGURATION_TYPES @CMAKE_CONFIGURATION_TYPES@) set(LLVM_ENABLE_SHARED_LIBS @BUILD_SHARED_LIBS@) Index: llvm/cmake/modules/CMakeLists.txt =================================================================== --- llvm/cmake/modules/CMakeLists.txt +++ llvm/cmake/modules/CMakeLists.txt @@ -131,7 +131,6 @@ set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}") extend_path(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}") -extend_path(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}" "${LLVM_TOOLS_INSTALL_DIR}") # Generate a default location for lit if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS) Index: llvm/cmake/modules/AddLLVM.cmake =================================================================== --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -1239,7 +1239,7 @@ ) endif() -macro(add_llvm_tool name) +macro(llvm_add_tool project name) if( NOT LLVM_BUILD_TOOLS ) set(EXCLUDE_FROM_ALL ON) endif() @@ -1250,7 +1250,7 @@ get_target_export_arg(${name} LLVM export_to_llvmexports) install(TARGETS ${name} ${export_to_llvmexports} - RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR} + RUNTIME DESTINATION ${${project}_TOOLS_INSTALL_DIR} COMPONENT ${name}) if (NOT LLVM_ENABLE_IDE) @@ -1264,7 +1264,11 @@ set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) endif() set_target_properties(${name} PROPERTIES FOLDER "Tools") -endmacro(add_llvm_tool name) +endmacro(llvm_add_tool project name) + +macro(add_llvm_tool name) + llvm_add_tool(LLVM ${ARGV}) +endmacro() macro(add_llvm_example name) @@ -1913,7 +1917,7 @@ endfunction() -function(llvm_install_symlink name dest) +function(llvm_install_symlink project name dest) cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) foreach(path ${CMAKE_MODULE_PATH}) if(EXISTS ${path}/LLVMInstallSymlink.cmake) @@ -1936,7 +1940,7 @@ set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) install(SCRIPT ${INSTALL_SYMLINK} - CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})" + CODE "install_symlink(${full_name} ${full_dest} ${${project}_TOOLS_INSTALL_DIR})" COMPONENT ${component}) if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE) @@ -1947,7 +1951,7 @@ endif() endfunction() -function(add_llvm_tool_symlink link_name target) +function(llvm_add_tool_symlink project link_name target) cmake_parse_arguments(ARG "ALWAYS_GENERATE" "OUTPUT_DIR" "" ${ARGN}) set(dest_binary "$<TARGET_FILE:${target}>") @@ -2019,11 +2023,15 @@ endif() if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) - llvm_install_symlink(${link_name} ${target}) + llvm_install_symlink("${project}" ${link_name} ${target}) endif() endif() endfunction() +function(add_llvm_tool_symlink link_name target) + llvm_add_tool_symlink(LLVM ${ARGV}) +endfunction() + function(llvm_externalize_debuginfo name) if(NOT LLVM_EXTERNALIZE_DEBUGINFO) return() Index: lld/cmake/modules/AddLLD.cmake =================================================================== --- lld/cmake/modules/AddLLD.cmake +++ lld/cmake/modules/AddLLD.cmake @@ -60,7 +60,7 @@ endmacro() macro(add_lld_symlink name dest) - add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + llvm_add_tool_symlink(LLD ${name} ${dest} ALWAYS_GENERATE) # Always generate install targets - llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) + llvm_install_symlink(LLD ${name} ${dest} ALWAYS_GENERATE) endmacro() Index: lld/CMakeLists.txt =================================================================== --- lld/CMakeLists.txt +++ lld/CMakeLists.txt @@ -146,6 +146,10 @@ endif() endif() # standalone +set(LLD_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')") +mark_as_advanced(LLD_TOOLS_INSTALL_DIR) + set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(LLD_INCLUDE_DIR ${LLD_SOURCE_DIR}/include ) set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) Index: flang/cmake/modules/AddFlang.cmake =================================================================== --- flang/cmake/modules/AddFlang.cmake +++ flang/cmake/modules/AddFlang.cmake @@ -122,8 +122,8 @@ endmacro() macro(add_flang_symlink name dest) - add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + llvm_add_tool_symlink(FLANG ${name} ${dest} ALWAYS_GENERATE) # Always generate install targets - llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) + llvm_install_symlink(FLANG ${name} ${dest} ALWAYS_GENERATE) endmacro() Index: flang/CMakeLists.txt =================================================================== --- flang/CMakeLists.txt +++ flang/CMakeLists.txt @@ -203,6 +203,11 @@ include_directories(SYSTEM ${MLIR_INCLUDE_DIR}) include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR}) endif() + +set(FLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')") +mark_as_advanced(FLANG_TOOLS_INSTALL_DIR) + set(FLANG_INTRINSIC_MODULES_DIR ${CMAKE_BINARY_DIR}/include/flang) set(FLANG_INCLUDE_DIR ${FLANG_BINARY_DIR}/include) Index: clang/cmake/modules/AddClang.cmake =================================================================== --- clang/cmake/modules/AddClang.cmake +++ clang/cmake/modules/AddClang.cmake @@ -173,9 +173,9 @@ endmacro() macro(add_clang_symlink name dest) - add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + llvm_add_tool_symlink(CLANG ${name} ${dest} ALWAYS_GENERATE) # Always generate install targets - llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) + llvm_install_symlink(CLANG name} ${dest} ALWAYS_GENERATE) endmacro() function(clang_target_link_libraries target type) Index: clang/CMakeLists.txt =================================================================== --- clang/CMakeLists.txt +++ clang/CMakeLists.txt @@ -348,6 +348,10 @@ # The libdir suffix must exactly match whatever LLVM's configuration used. set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}") +set(CLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')") +mark_as_advanced(CLANG_TOOLS_INSTALL_DIR) + set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) Index: bolt/tools/merge-fdata/CMakeLists.txt =================================================================== --- bolt/tools/merge-fdata/CMakeLists.txt +++ bolt/tools/merge-fdata/CMakeLists.txt @@ -1,6 +1,6 @@ set(LLVM_LINK_COMPONENTS Support) -add_llvm_tool(merge-fdata +add_bolt_tool(merge-fdata merge-fdata.cpp DEPENDS Index: bolt/tools/driver/CMakeLists.txt =================================================================== --- bolt/tools/driver/CMakeLists.txt +++ bolt/tools/driver/CMakeLists.txt @@ -14,16 +14,16 @@ set(BOLT_DRIVER_DEPS "") endif() -add_llvm_tool(llvm-bolt +add_bolt_tool(llvm-bolt llvm-bolt.cpp DEPENDS ${BOLT_DRIVER_DEPS} ) -add_llvm_tool_symlink(perf2bolt llvm-bolt) -add_llvm_tool_symlink(llvm-boltdiff llvm-bolt) -add_llvm_tool_symlink(llvm-bolt-heatmap llvm-bolt) +add_bolt_tool_symlink(perf2bolt llvm-bolt) +add_bolt_tool_symlink(llvm-boltdiff llvm-bolt) +add_bolt_tool_symlink(llvm-bolt-heatmap llvm-bolt) set(BOLT_DEPENDS llvm-bolt Index: bolt/tools/CMakeLists.txt =================================================================== --- bolt/tools/CMakeLists.txt +++ bolt/tools/CMakeLists.txt @@ -1,2 +1,16 @@ +set(BOLT_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')") +mark_as_advanced(BOLT_TOOLS_INSTALL_DIR) + +# Move these macros to AddBolt if such a CMake module is ever created. + +macro(add_bolt_tool name) + llvm_add_tool(BOLT ${ARGV}) +endmacro() + +macro(add_bolt_tool_symlink name) + llvm_add_tool_symlink(BOLT ${ARGV}) +endmacro() + add_subdirectory(driver) add_subdirectory(merge-fdata)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits