2019-07-24 21:03:43 +00:00
|
|
|
include(ExternalProject)
|
|
|
|
|
2018-06-22 20:50:07 +00:00
|
|
|
set(BOLT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
set(BOLT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
2022-08-08 06:12:16 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2018-06-22 20:50:07 +00:00
|
|
|
|
2023-05-26 22:11:24 +00:00
|
|
|
# Add path for custom modules.
|
|
|
|
list(INSERT CMAKE_MODULE_PATH 0 "${BOLT_SOURCE_DIR}/cmake/modules")
|
|
|
|
|
2023-04-20 19:22:18 +00:00
|
|
|
# Determine default set of targets to build -- the intersection of
|
|
|
|
# those BOLT supports and those LLVM is targeting.
|
2023-06-16 09:49:19 +00:00
|
|
|
set(BOLT_TARGETS_TO_BUILD_all "AArch64;X86;RISCV")
|
2023-04-20 19:22:18 +00:00
|
|
|
set(BOLT_TARGETS_TO_BUILD_default)
|
|
|
|
foreach (tgt ${BOLT_TARGETS_TO_BUILD_all})
|
|
|
|
if (tgt IN_LIST LLVM_TARGETS_TO_BUILD)
|
|
|
|
list(APPEND BOLT_TARGETS_TO_BUILD_default ${tgt})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# Allow the user to specify the BOLT targets, and then check that LLVM
|
|
|
|
# is indeed targeting those.
|
|
|
|
set(BOLT_TARGETS_TO_BUILD "${BOLT_TARGETS_TO_BUILD_default}"
|
|
|
|
CACHE STRING "Targets for BOLT to support.")
|
|
|
|
if (NOT BOLT_TARGETS_TO_BUILD)
|
|
|
|
message(FATAL_ERROR "BOLT enabled but BOLT_TARGETS_TO_BUILD is empty")
|
|
|
|
endif()
|
|
|
|
foreach (tgt ${BOLT_TARGETS_TO_BUILD})
|
|
|
|
if (NOT tgt IN_LIST LLVM_TARGETS_TO_BUILD)
|
|
|
|
message(FATAL_ERROR "BOLT target '${tgt}' is not in LLVM_TARGETS_TO_BUILD")
|
|
|
|
endif()
|
|
|
|
message(STATUS "Targeting ${tgt} in llvm-bolt")
|
|
|
|
endforeach()
|
|
|
|
|
2023-04-19 20:08:25 +00:00
|
|
|
set(BOLT_ENABLE_RUNTIME_default OFF)
|
2023-04-14 12:51:05 +00:00
|
|
|
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"
|
2023-04-19 20:08:25 +00:00
|
|
|
AND (CMAKE_SYSTEM_NAME STREQUAL "Linux"
|
|
|
|
OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
2023-04-20 19:22:18 +00:00
|
|
|
AND "X86" IN_LIST BOLT_TARGETS_TO_BUILD)
|
2023-04-19 20:08:25 +00:00
|
|
|
set(BOLT_ENABLE_RUNTIME_default ON)
|
|
|
|
endif()
|
|
|
|
option(BOLT_ENABLE_RUNTIME "Enable BOLT runtime" ${BOLT_ENABLE_RUNTIME_default})
|
|
|
|
if (BOLT_ENABLE_RUNTIME)
|
|
|
|
# Some systems prevent reading /proc/self/map_files
|
|
|
|
execute_process(COMMAND ls /proc/self/map_files
|
|
|
|
RESULT_VARIABLE LS OUTPUT_QUIET ERROR_QUIET)
|
|
|
|
if (LS)
|
|
|
|
set(BOLT_ENABLE_RUNTIME OFF)
|
|
|
|
message(WARNING
|
|
|
|
"BOLT runtime is disabled as /proc/self/map_files is unreadable.")
|
|
|
|
endif()
|
2021-12-23 13:59:35 +00:00
|
|
|
endif()
|
2019-07-24 21:03:43 +00:00
|
|
|
|
2022-01-14 22:18:43 +00:00
|
|
|
set(BOLT_CLANG_EXE "" CACHE FILEPATH "Path to clang executable for the target \
|
|
|
|
architecture for use in BOLT tests")
|
|
|
|
set(BOLT_LLD_EXE "" CACHE FILEPATH "Path to lld executable for the target \
|
|
|
|
architecture for use in BOLT tests")
|
|
|
|
|
2021-12-23 13:59:35 +00:00
|
|
|
set(BOLT_INCLUDE_TESTS OFF)
|
|
|
|
if (LLVM_INCLUDE_TESTS)
|
2022-04-23 16:16:53 +00:00
|
|
|
set(BOLT_CLANG_PRESENT OFF)
|
|
|
|
set(BOLT_LLD_PRESENT OFF)
|
|
|
|
|
|
|
|
if ("clang" IN_LIST LLVM_ENABLE_PROJECTS AND BOLT_CLANG_EXE)
|
|
|
|
message(WARNING "BOLT_CLANG_EXE is set and clang project is enabled. \
|
|
|
|
BOLT_CLANG_EXE will be used for BOLT tests.")
|
|
|
|
endif()
|
2022-01-14 22:18:43 +00:00
|
|
|
if ("clang" IN_LIST LLVM_ENABLE_PROJECTS OR BOLT_CLANG_EXE)
|
2022-04-23 16:16:53 +00:00
|
|
|
set(BOLT_CLANG_PRESENT ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if ("lld" IN_LIST LLVM_ENABLE_PROJECTS AND BOLT_LLD_EXE)
|
|
|
|
message(WARNING "BOLT_LLD_EXE is set and lld project is enabled. \
|
|
|
|
BOLT_LLD_EXE will be used for BOLT tests.")
|
|
|
|
endif()
|
|
|
|
if ("lld" IN_LIST LLVM_ENABLE_PROJECTS OR BOLT_LLD_EXE)
|
|
|
|
set(BOLT_LLD_PRESENT ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (BOLT_CLANG_PRESENT AND BOLT_LLD_PRESENT)
|
|
|
|
set(BOLT_INCLUDE_TESTS ON)
|
2021-12-23 13:59:35 +00:00
|
|
|
else()
|
2022-04-23 16:16:53 +00:00
|
|
|
message(WARNING "Not including BOLT tests since clang or lld is disabled. \
|
|
|
|
Add clang and lld to LLVM_ENABLE_PROJECTS or provide paths to clang \
|
|
|
|
and lld binaries in BOLT_CLANG_EXE and BOLT_LLD_EXE.")
|
2021-10-26 19:26:23 +00:00
|
|
|
endif()
|
2021-12-23 13:59:35 +00:00
|
|
|
endif()
|
2021-11-12 02:14:53 +00:00
|
|
|
|
2021-12-23 13:59:35 +00:00
|
|
|
if (BOLT_ENABLE_RUNTIME)
|
|
|
|
message(STATUS "Building BOLT runtime libraries for X86")
|
2023-05-17 05:41:42 +00:00
|
|
|
set(extra_args "")
|
|
|
|
if(CMAKE_SYSROOT)
|
|
|
|
list(APPEND extra_args -DCMAKE_SYSROOT=${CMAKE_SYSROOT})
|
|
|
|
endif()
|
2021-12-23 13:59:35 +00:00
|
|
|
ExternalProject_Add(bolt_rt
|
|
|
|
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/runtime"
|
|
|
|
STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-stamps
|
|
|
|
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins
|
|
|
|
CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
|
|
|
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
|
|
|
-DCMAKE_BUILD_TYPE=Release
|
|
|
|
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
|
2022-10-30 17:25:04 +00:00
|
|
|
-DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
|
2023-05-17 05:41:42 +00:00
|
|
|
-DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR}
|
|
|
|
${extra_args}
|
|
|
|
INSTALL_COMMAND ""
|
2021-12-23 13:59:35 +00:00
|
|
|
BUILD_ALWAYS True
|
|
|
|
)
|
|
|
|
install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins/cmake_install.cmake \)"
|
|
|
|
COMPONENT bolt)
|
|
|
|
add_llvm_install_targets(install-bolt_rt
|
|
|
|
DEPENDS bolt_rt bolt
|
|
|
|
COMPONENT bolt)
|
|
|
|
endif()
|
2021-10-08 18:47:10 +00:00
|
|
|
|
2022-04-03 16:11:31 +00:00
|
|
|
find_program(GNU_LD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.bfd ld.bfd DOC "GNU ld")
|
|
|
|
|
2023-05-26 22:11:24 +00:00
|
|
|
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)
|
|
|
|
|
2021-12-23 13:59:35 +00:00
|
|
|
include_directories(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include
|
|
|
|
)
|
2021-11-12 02:14:53 +00:00
|
|
|
|
2021-12-23 13:59:35 +00:00
|
|
|
add_subdirectory(lib)
|
|
|
|
add_subdirectory(tools)
|
2021-11-12 02:14:53 +00:00
|
|
|
|
2021-12-23 13:59:35 +00:00
|
|
|
if (BOLT_INCLUDE_TESTS)
|
2022-11-15 22:44:32 +00:00
|
|
|
if (EXISTS ${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include/gtest/gtest.h)
|
2022-01-26 20:45:46 +00:00
|
|
|
add_subdirectory(unittests)
|
|
|
|
list(APPEND BOLT_TEST_DEPS BoltUnitTests)
|
|
|
|
endif()
|
2021-12-23 13:59:35 +00:00
|
|
|
add_subdirectory(test)
|
2021-10-26 19:26:23 +00:00
|
|
|
endif()
|
2021-12-23 23:23:39 +00:00
|
|
|
|
|
|
|
option(BOLT_INCLUDE_DOCS "Generate build targets for the BOLT docs."
|
|
|
|
${LLVM_INCLUDE_DOCS})
|
|
|
|
if (BOLT_INCLUDE_DOCS)
|
|
|
|
add_subdirectory(docs)
|
|
|
|
endif()
|
2022-10-30 17:25:04 +00:00
|
|
|
|
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc @ONLY)
|