1 include(ExternalProject)
3 set(BOLT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
4 set(BOLT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
5 set(CMAKE_CXX_STANDARD 17)
7 # Determine default set of targets to build -- the intersection of
8 # those BOLT supports and those LLVM is targeting.
9 set(BOLT_TARGETS_TO_BUILD_all "AArch64;X86")
10 set(BOLT_TARGETS_TO_BUILD_default)
11 foreach (tgt ${BOLT_TARGETS_TO_BUILD_all})
12 if (tgt IN_LIST LLVM_TARGETS_TO_BUILD)
13 list(APPEND BOLT_TARGETS_TO_BUILD_default ${tgt})
17 # Allow the user to specify the BOLT targets, and then check that LLVM
18 # is indeed targeting those.
19 set(BOLT_TARGETS_TO_BUILD "${BOLT_TARGETS_TO_BUILD_default}"
20 CACHE STRING "Targets for BOLT to support.")
21 if (NOT BOLT_TARGETS_TO_BUILD)
22 message(FATAL_ERROR "BOLT enabled but BOLT_TARGETS_TO_BUILD is empty")
24 foreach (tgt ${BOLT_TARGETS_TO_BUILD})
25 if (NOT tgt IN_LIST LLVM_TARGETS_TO_BUILD)
26 message(FATAL_ERROR "BOLT target '${tgt}' is not in LLVM_TARGETS_TO_BUILD")
28 message(STATUS "Targeting ${tgt} in llvm-bolt")
31 set(BOLT_ENABLE_RUNTIME_default OFF)
32 if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
33 AND (CMAKE_SYSTEM_NAME STREQUAL "Linux"
34 OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
35 AND "X86" IN_LIST BOLT_TARGETS_TO_BUILD)
36 set(BOLT_ENABLE_RUNTIME_default ON)
38 option(BOLT_ENABLE_RUNTIME "Enable BOLT runtime" ${BOLT_ENABLE_RUNTIME_default})
39 if (BOLT_ENABLE_RUNTIME)
40 # Some systems prevent reading /proc/self/map_files
41 execute_process(COMMAND ls /proc/self/map_files
42 RESULT_VARIABLE LS OUTPUT_QUIET ERROR_QUIET)
44 set(BOLT_ENABLE_RUNTIME OFF)
46 "BOLT runtime is disabled as /proc/self/map_files is unreadable.")
50 set(BOLT_CLANG_EXE "" CACHE FILEPATH "Path to clang executable for the target \
51 architecture for use in BOLT tests")
52 set(BOLT_LLD_EXE "" CACHE FILEPATH "Path to lld executable for the target \
53 architecture for use in BOLT tests")
55 set(BOLT_INCLUDE_TESTS OFF)
56 if (LLVM_INCLUDE_TESTS)
57 set(BOLT_CLANG_PRESENT OFF)
58 set(BOLT_LLD_PRESENT OFF)
60 if ("clang" IN_LIST LLVM_ENABLE_PROJECTS AND BOLT_CLANG_EXE)
61 message(WARNING "BOLT_CLANG_EXE is set and clang project is enabled. \
62 BOLT_CLANG_EXE will be used for BOLT tests.")
64 if ("clang" IN_LIST LLVM_ENABLE_PROJECTS OR BOLT_CLANG_EXE)
65 set(BOLT_CLANG_PRESENT ON)
68 if ("lld" IN_LIST LLVM_ENABLE_PROJECTS AND BOLT_LLD_EXE)
69 message(WARNING "BOLT_LLD_EXE is set and lld project is enabled. \
70 BOLT_LLD_EXE will be used for BOLT tests.")
72 if ("lld" IN_LIST LLVM_ENABLE_PROJECTS OR BOLT_LLD_EXE)
73 set(BOLT_LLD_PRESENT ON)
76 if (BOLT_CLANG_PRESENT AND BOLT_LLD_PRESENT)
77 set(BOLT_INCLUDE_TESTS ON)
79 message(WARNING "Not including BOLT tests since clang or lld is disabled. \
80 Add clang and lld to LLVM_ENABLE_PROJECTS or provide paths to clang \
81 and lld binaries in BOLT_CLANG_EXE and BOLT_LLD_EXE.")
85 if (BOLT_ENABLE_RUNTIME)
86 message(STATUS "Building BOLT runtime libraries for X86")
87 ExternalProject_Add(bolt_rt
88 SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/runtime"
89 STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-stamps
90 BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins
91 CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
92 -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
93 -DCMAKE_BUILD_TYPE=Release
94 -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
95 -DCMAKE_INSTALL_PREFIX=${LLVM_BINARY_DIR}
96 -DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
99 install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins/cmake_install.cmake \)"
101 add_llvm_install_targets(install-bolt_rt
106 find_program(GNU_LD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.bfd ld.bfd DOC "GNU ld")
109 ${CMAKE_CURRENT_SOURCE_DIR}/include
110 ${CMAKE_CURRENT_BINARY_DIR}/include
113 add_subdirectory(lib)
114 add_subdirectory(tools)
116 if (BOLT_INCLUDE_TESTS)
117 if (EXISTS ${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include/gtest/gtest.h)
118 add_subdirectory(unittests)
119 list(APPEND BOLT_TEST_DEPS BoltUnitTests)
121 add_subdirectory(test)
124 option(BOLT_INCLUDE_DOCS "Generate build targets for the BOLT docs."
125 ${LLVM_INCLUDE_DOCS})
126 if (BOLT_INCLUDE_DOCS)
127 add_subdirectory(docs)
130 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc.in
131 ${CMAKE_CURRENT_BINARY_DIR}/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc @ONLY)