[llvm] f3269a9 - [BOLT][CMake] Redo the build and install targets
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 1 07:48:13 PDT 2023
Author: Petr Hosek
Date: 2023-06-01T14:48:01Z
New Revision: f3269a94e729b02e9d7c07257c45b098506cca22
URL: https://github.com/llvm/llvm-project/commit/f3269a94e729b02e9d7c07257c45b098506cca22
DIFF: https://github.com/llvm/llvm-project/commit/f3269a94e729b02e9d7c07257c45b098506cca22.diff
LOG: [BOLT][CMake] Redo the build and install targets
The existing BOLT install targets are broken on Windows becase they
don't properly handle the output extension. We cannot use the existing
LLVM macros since those make assumptions that don't hold for BOLT. This
change instead implements custom macros following the approach used by
Clang and LLD.
Differential Revision: https://reviews.llvm.org/D151595
Added:
bolt/cmake/modules/AddBOLT.cmake
Modified:
bolt/CMakeLists.txt
bolt/test/CMakeLists.txt
bolt/tools/CMakeLists.txt
bolt/tools/bat-dump/CMakeLists.txt
bolt/tools/driver/CMakeLists.txt
bolt/tools/heatmap/CMakeLists.txt
bolt/tools/merge-fdata/CMakeLists.txt
clang/cmake/caches/Fuchsia-stage2.cmake
llvm/cmake/modules/AddLLVM.cmake
Removed:
################################################################################
diff --git a/bolt/CMakeLists.txt b/bolt/CMakeLists.txt
index a9bc770a95e93..2e702d40668b4 100644
--- a/bolt/CMakeLists.txt
+++ b/bolt/CMakeLists.txt
@@ -4,6 +4,9 @@ set(BOLT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(BOLT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_CXX_STANDARD 17)
+# Add path for custom modules.
+list(INSERT CMAKE_MODULE_PATH 0 "${BOLT_SOURCE_DIR}/cmake/modules")
+
# Determine default set of targets to build -- the intersection of
# those BOLT supports and those LLVM is targeting.
set(BOLT_TARGETS_TO_BUILD_all "AArch64;X86")
@@ -111,6 +114,15 @@ endif()
find_program(GNU_LD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.bfd ld.bfd DOC "GNU ld")
+include(AddBOLT)
+
+option(BOLT_BUILD_TOOLS
+ "Build the BOLT tools. If OFF, just generate build targets." ON)
+
+add_custom_target(bolt)
+set_target_properties(bolt PROPERTIES FOLDER "BOLT")
+add_llvm_install_targets(install-bolt DEPENDS bolt COMPONENT bolt)
+
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include
diff --git a/bolt/cmake/modules/AddBOLT.cmake b/bolt/cmake/modules/AddBOLT.cmake
new file mode 100644
index 0000000000000..1f69b9046320a
--- /dev/null
+++ b/bolt/cmake/modules/AddBOLT.cmake
@@ -0,0 +1,36 @@
+include(GNUInstallDirs)
+include(LLVMDistributionSupport)
+
+macro(add_bolt_executable name)
+ add_llvm_executable(${name} ${ARGN})
+ set_target_properties(${name} PROPERTIES FOLDER "BOLT")
+endmacro()
+
+macro(add_bolt_tool name)
+ if (NOT BOLT_BUILD_TOOLS)
+ set(EXCLUDE_FROM_ALL ON)
+ endif()
+
+ add_bolt_executable(${name} ${ARGN})
+
+ if (BOLT_BUILD_TOOLS)
+ get_target_export_arg(${name} BOLT export_to_bolttargets)
+ install(TARGETS ${name}
+ ${export_to_bolttargets}
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+ COMPONENT bolt)
+
+ if(NOT LLVM_ENABLE_IDE)
+ add_llvm_install_targets(install-${name}
+ DEPENDS ${name}
+ COMPONENT bolt)
+ endif()
+ set_property(GLOBAL APPEND PROPERTY BOLT_EXPORTS ${name})
+ endif()
+endmacro()
+
+macro(add_bolt_tool_symlink name dest)
+ llvm_add_tool_symlink(BOLT ${name} ${dest} ALWAYS_GENERATE)
+ # Always generate install targets
+ llvm_install_symlink(BOLT ${name} ${dest} ALWAYS_GENERATE COMPONENT bolt)
+endmacro()
diff --git a/bolt/test/CMakeLists.txt b/bolt/test/CMakeLists.txt
index 216a785b7d69f..89862fd59eb8e 100644
--- a/bolt/test/CMakeLists.txt
+++ b/bolt/test/CMakeLists.txt
@@ -37,7 +37,6 @@ list(APPEND BOLT_TEST_DEPS
lld
llvm-config
llvm-bolt
- llvm-bolt
diff
llvm-bolt-heatmap
llvm-bat-dump
llvm-dwarfdump
@@ -52,7 +51,6 @@ list(APPEND BOLT_TEST_DEPS
llvm-objcopy
merge-fdata
not
- perf2bolt
split-file
yaml2obj
)
diff --git a/bolt/tools/CMakeLists.txt b/bolt/tools/CMakeLists.txt
index 52050fb8b0056..22ea3b9bd805f 100644
--- a/bolt/tools/CMakeLists.txt
+++ b/bolt/tools/CMakeLists.txt
@@ -2,16 +2,6 @@ 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(llvm-bolt-fuzzer)
add_subdirectory(bat-dump)
diff --git a/bolt/tools/bat-dump/CMakeLists.txt b/bolt/tools/bat-dump/CMakeLists.txt
index 71d4f3e64ccda..037b7d2662ae4 100644
--- a/bolt/tools/bat-dump/CMakeLists.txt
+++ b/bolt/tools/bat-dump/CMakeLists.txt
@@ -3,7 +3,7 @@ set(LLVM_LINK_COMPONENTS
Support
)
-add_llvm_tool(llvm-bat-dump
+add_bolt_executable(llvm-bat-dump
bat-dump.cpp
DISABLE_LLVM_LINK_LLVM_DYLIB
@@ -13,5 +13,3 @@ target_link_libraries(llvm-bat-dump
PRIVATE
LLVMBOLTProfile
)
-
-set_target_properties(llvm-bat-dump PROPERTIES FOLDER "BOLT")
diff --git a/bolt/tools/driver/CMakeLists.txt b/bolt/tools/driver/CMakeLists.txt
index 1c596194ffe80..9bf9ff85edc7b 100644
--- a/bolt/tools/driver/CMakeLists.txt
+++ b/bolt/tools/driver/CMakeLists.txt
@@ -30,22 +30,6 @@ target_link_libraries(llvm-bolt
add_bolt_tool_symlink(perf2bolt llvm-bolt)
add_bolt_tool_symlink(llvm-bolt
diff llvm-bolt)
-set(BOLT_DEPENDS
- llvm-bolt
- perf2bolt
- llvm-bolt
diff
- )
-
-add_custom_target(bolt DEPENDS ${BOLT_DEPENDS})
-install(PROGRAMS
- ${CMAKE_BINARY_DIR}/bin/llvm-bolt
- ${CMAKE_BINARY_DIR}/bin/perf2bolt
- ${CMAKE_BINARY_DIR}/bin/llvm-bolt
diff
- DESTINATION ${CMAKE_INSTALL_BINDIR}
- COMPONENT bolt
- )
-add_llvm_install_targets(install-bolt DEPENDS bolt COMPONENT bolt)
-set_target_properties(bolt PROPERTIES FOLDER "BOLT")
-set_target_properties(install-bolt PROPERTIES FOLDER "BOLT")
+add_dependencies(bolt llvm-bolt)
-include_directories( ${BOLT_SOURCE_DIR}/lib )
+include_directories(${BOLT_SOURCE_DIR}/lib)
diff --git a/bolt/tools/heatmap/CMakeLists.txt b/bolt/tools/heatmap/CMakeLists.txt
index 9f52ddb02102e..acddc7a50e8b1 100644
--- a/bolt/tools/heatmap/CMakeLists.txt
+++ b/bolt/tools/heatmap/CMakeLists.txt
@@ -17,4 +17,4 @@ target_link_libraries(llvm-bolt-heatmap
LLVMBOLTUtils
)
-set_target_properties(llvm-bolt-heatmap PROPERTIES FOLDER "BOLT")
+add_dependencies(bolt llvm-bolt-heatmap)
diff --git a/bolt/tools/merge-fdata/CMakeLists.txt b/bolt/tools/merge-fdata/CMakeLists.txt
index 9405acb6ab68d..f6a87a2268982 100644
--- a/bolt/tools/merge-fdata/CMakeLists.txt
+++ b/bolt/tools/merge-fdata/CMakeLists.txt
@@ -8,14 +8,8 @@ add_bolt_tool(merge-fdata
DEPENDS
intrinsics_gen
)
-set_target_properties(merge-fdata PROPERTIES FOLDER "BOLT")
add_dependencies(bolt merge-fdata)
-install(PROGRAMS
- ${CMAKE_BINARY_DIR}/bin/merge-fdata
- DESTINATION ${CMAKE_INSTALL_BINDIR}
- COMPONENT bolt
- )
# Emit relocations for BOLT meta test (bolt/test/runtime/meta-merge-fdata.test)
if (BOLT_INCLUDE_TESTS AND UNIX AND NOT APPLE)
diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake
index 6d868abf21202..78c123f191305 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -6,7 +6,7 @@ set(LLVM_TARGETS_TO_BUILD X86;ARM;AArch64;RISCV CACHE STRING "")
set(PACKAGE_VENDOR Fuchsia CACHE STRING "")
-set(_FUCHSIA_ENABLE_PROJECTS "clang;clang-tools-extra;lld;llvm;polly")
+set(_FUCHSIA_ENABLE_PROJECTS "bolt;clang;clang-tools-extra;lld;llvm;polly")
set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
@@ -329,6 +329,7 @@ set(LLVM_TOOLCHAIN_TOOLS
CACHE STRING "")
set(LLVM_Toolchain_DISTRIBUTION_COMPONENTS
+ bolt
clang
lld
clang-apply-replacements
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 91d2c8bac6e03..5dadac02bee81 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -2121,7 +2121,7 @@ function(llvm_install_symlink project name dest)
if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)
add_llvm_install_targets(install-${name}
DEPENDS ${name} ${dest}
- COMPONENT ${name}
+ COMPONENT ${component}
SYMLINK ${dest})
endif()
endfunction()
More information about the llvm-commits
mailing list