[clang][dataflow] Replace one remaining call to deprecated `addToFlowCondition()...
[llvm-project.git] / bolt / CMakeLists.txt
blobf163d45342874d0e8dd2a64a292e735ddf3cd626
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 # Add path for custom modules.
8 list(INSERT CMAKE_MODULE_PATH 0 "${BOLT_SOURCE_DIR}/cmake/modules")
10 # Determine default set of targets to build -- the intersection of
11 # those BOLT supports and those LLVM is targeting.
12 set(BOLT_TARGETS_TO_BUILD_all "AArch64;X86;RISCV")
13 set(BOLT_TARGETS_TO_BUILD_default)
14 foreach (tgt ${BOLT_TARGETS_TO_BUILD_all})
15   if (tgt IN_LIST LLVM_TARGETS_TO_BUILD)
16     list(APPEND BOLT_TARGETS_TO_BUILD_default ${tgt})
17   endif()
18 endforeach()
20 # Allow the user to specify the BOLT targets, and then check that LLVM
21 # is indeed targeting those.
22 set(BOLT_TARGETS_TO_BUILD "${BOLT_TARGETS_TO_BUILD_default}"
23   CACHE STRING "Targets for BOLT to support.")
24 if (NOT BOLT_TARGETS_TO_BUILD)
25   message(FATAL_ERROR "BOLT enabled but BOLT_TARGETS_TO_BUILD is empty")
26 endif()
27 foreach (tgt ${BOLT_TARGETS_TO_BUILD})
28   if (NOT tgt IN_LIST LLVM_TARGETS_TO_BUILD)
29     message(FATAL_ERROR "BOLT target '${tgt}' is not in LLVM_TARGETS_TO_BUILD")
30   endif()
31   message(STATUS "Targeting ${tgt} in llvm-bolt")
32 endforeach()
34 set(BOLT_ENABLE_RUNTIME_default OFF)
35 if ((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
36     OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
37     AND (CMAKE_SYSTEM_NAME STREQUAL "Linux"
38       OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
39     AND (NOT CMAKE_CROSSCOMPILING))
40   set(BOLT_ENABLE_RUNTIME_default ON)
41 endif()
42 option(BOLT_ENABLE_RUNTIME "Enable BOLT runtime" ${BOLT_ENABLE_RUNTIME_default})
43 if (BOLT_ENABLE_RUNTIME)
44   # Some systems prevent reading /proc/self/map_files
45   execute_process(COMMAND ls /proc/self/map_files
46     RESULT_VARIABLE LS OUTPUT_QUIET ERROR_QUIET)
47   if (LS)
48     set(BOLT_ENABLE_RUNTIME OFF)
49     message(WARNING
50       "BOLT runtime is disabled as /proc/self/map_files is unreadable.")
51   endif()
52 endif()
54 set(BOLT_CLANG_EXE "" CACHE FILEPATH "Path to clang executable for the target \
55 architecture for use in BOLT tests")
56 set(BOLT_LLD_EXE "" CACHE FILEPATH "Path to lld executable for the target \
57 architecture for use in BOLT tests")
59 set(BOLT_INCLUDE_TESTS OFF)
60 if (LLVM_INCLUDE_TESTS)
61   set(BOLT_CLANG_PRESENT OFF)
62   set(BOLT_LLD_PRESENT OFF)
64   if ("clang" IN_LIST LLVM_ENABLE_PROJECTS AND BOLT_CLANG_EXE)
65     message(WARNING "BOLT_CLANG_EXE is set and clang project is enabled. \
66           BOLT_CLANG_EXE will be used for BOLT tests.")
67   endif()
68   if ("clang" IN_LIST LLVM_ENABLE_PROJECTS OR BOLT_CLANG_EXE)
69     set(BOLT_CLANG_PRESENT ON)
70   endif()
72   if ("lld" IN_LIST LLVM_ENABLE_PROJECTS AND BOLT_LLD_EXE)
73     message(WARNING "BOLT_LLD_EXE is set and lld project is enabled. \
74           BOLT_LLD_EXE will be used for BOLT tests.")
75   endif()
76   if ("lld" IN_LIST LLVM_ENABLE_PROJECTS OR BOLT_LLD_EXE)
77     set(BOLT_LLD_PRESENT ON)
78   endif()
80   if (BOLT_CLANG_PRESENT AND BOLT_LLD_PRESENT)
81     set(BOLT_INCLUDE_TESTS ON)
82   else()
83     message(WARNING "Not including BOLT tests since clang or lld is disabled. \
84           Add clang and lld to LLVM_ENABLE_PROJECTS or provide paths to clang \
85           and lld binaries in BOLT_CLANG_EXE and BOLT_LLD_EXE.")
86   endif()
87 endif()
89 if (BOLT_ENABLE_RUNTIME)
90   message(STATUS "Building BOLT runtime libraries for X86")
91   set(extra_args "")
92   if(CMAKE_SYSROOT)
93     list(APPEND extra_args -DCMAKE_SYSROOT=${CMAKE_SYSROOT})
94   endif()
95   ExternalProject_Add(bolt_rt
96     SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/runtime"
97     STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-stamps
98     BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins
99     CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
100                -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
101                -DCMAKE_BUILD_TYPE=Release
102                -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
103                -DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
104                -DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR}
105                ${extra_args}
106     INSTALL_COMMAND ""
107     BUILD_ALWAYS True
108     )
109   install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins/cmake_install.cmake \)"
110     COMPONENT bolt)
111   add_llvm_install_targets(install-bolt_rt
112     DEPENDS bolt_rt bolt
113     COMPONENT bolt)
114 endif()
116 find_program(GNU_LD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.bfd ld.bfd DOC "GNU ld")
118 include(AddBOLT)
120 option(BOLT_BUILD_TOOLS
121   "Build the BOLT tools. If OFF, just generate build targets." ON)
123 add_custom_target(bolt)
124 set_target_properties(bolt PROPERTIES FOLDER "BOLT")
125 add_llvm_install_targets(install-bolt DEPENDS bolt COMPONENT bolt)
127 include_directories(
128   ${CMAKE_CURRENT_SOURCE_DIR}/include
129   ${CMAKE_CURRENT_BINARY_DIR}/include
130   )
132 add_subdirectory(lib)
133 add_subdirectory(tools)
135 if (BOLT_INCLUDE_TESTS)
136   if (EXISTS ${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include/gtest/gtest.h)
137     add_subdirectory(unittests)
138     list(APPEND BOLT_TEST_DEPS BoltUnitTests)
139   endif()
140   add_subdirectory(test)
141 endif()
143 option(BOLT_INCLUDE_DOCS "Generate build targets for the BOLT docs."
144        ${LLVM_INCLUDE_DOCS})
145 if (BOLT_INCLUDE_DOCS)
146   add_subdirectory(docs)
147 endif()
149 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc.in
150                ${CMAKE_CURRENT_BINARY_DIR}/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc @ONLY)