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 set(BOLT_ENABLE_RUNTIME OFF)
8 if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
9 AND "X86" IN_LIST LLVM_TARGETS_TO_BUILD)
10 set(BOLT_ENABLE_RUNTIME ON)
13 set(BOLT_CLANG_EXE "" CACHE FILEPATH "Path to clang executable for the target \
14 architecture for use in BOLT tests")
15 set(BOLT_LLD_EXE "" CACHE FILEPATH "Path to lld executable for the target \
16 architecture for use in BOLT tests")
18 set(BOLT_INCLUDE_TESTS OFF)
19 if (LLVM_INCLUDE_TESTS)
20 set(BOLT_CLANG_PRESENT OFF)
21 set(BOLT_LLD_PRESENT OFF)
23 if ("clang" IN_LIST LLVM_ENABLE_PROJECTS AND BOLT_CLANG_EXE)
24 message(WARNING "BOLT_CLANG_EXE is set and clang project is enabled. \
25 BOLT_CLANG_EXE will be used for BOLT tests.")
27 if ("clang" IN_LIST LLVM_ENABLE_PROJECTS OR BOLT_CLANG_EXE)
28 set(BOLT_CLANG_PRESENT ON)
31 if ("lld" IN_LIST LLVM_ENABLE_PROJECTS AND BOLT_LLD_EXE)
32 message(WARNING "BOLT_LLD_EXE is set and lld project is enabled. \
33 BOLT_LLD_EXE will be used for BOLT tests.")
35 if ("lld" IN_LIST LLVM_ENABLE_PROJECTS OR BOLT_LLD_EXE)
36 set(BOLT_LLD_PRESENT ON)
39 if (BOLT_CLANG_PRESENT AND BOLT_LLD_PRESENT)
40 set(BOLT_INCLUDE_TESTS ON)
42 message(WARNING "Not including BOLT tests since clang or lld is disabled. \
43 Add clang and lld to LLVM_ENABLE_PROJECTS or provide paths to clang \
44 and lld binaries in BOLT_CLANG_EXE and BOLT_LLD_EXE.")
48 if (BOLT_ENABLE_RUNTIME)
49 message(STATUS "Building BOLT runtime libraries for X86")
50 ExternalProject_Add(bolt_rt
51 SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/runtime"
52 STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-stamps
53 BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins
54 CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
55 -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
56 -DCMAKE_BUILD_TYPE=Release
57 -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
58 -DCMAKE_INSTALL_PREFIX=${LLVM_BINARY_DIR}
59 -DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
62 install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins/cmake_install.cmake \)"
64 add_llvm_install_targets(install-bolt_rt
69 find_program(GNU_LD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.bfd ld.bfd DOC "GNU ld")
72 ${CMAKE_CURRENT_SOURCE_DIR}/include
73 ${CMAKE_CURRENT_BINARY_DIR}/include
77 add_subdirectory(tools)
79 if (BOLT_INCLUDE_TESTS)
80 if (EXISTS ${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include/gtest/gtest.h)
81 add_subdirectory(unittests)
82 list(APPEND BOLT_TEST_DEPS BoltUnitTests)
84 add_subdirectory(test)
87 option(BOLT_INCLUDE_DOCS "Generate build targets for the BOLT docs."
89 if (BOLT_INCLUDE_DOCS)
90 add_subdirectory(docs)
93 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc.in
94 ${CMAKE_CURRENT_BINARY_DIR}/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc @ONLY)