[BOLT] Improve cmake configs for opensource

Summary:
Change cmake config in BOLT to only support Linux. In other
platforms, we print a warning that we won't build BOLT.  Change
configs to determine whether we will build BOLT runtime libs. This
only happens in x86 hosts. If true, we will build the runtime and
enable bolt-runtime tests. New tests that depend on the bolt_rt lib
needs to be marked REQUIRES:bolt-runtime. I updated the relevant
tests.  Fix cmake to do not crash when building llvm with a target
that BOLT does not support.

(cherry picked from FBD31935760)
This commit is contained in:
Rafael Auler
2021-10-26 12:26:23 -07:00
committed by Maksim Panchenko
parent a34c753fe7
commit 0559dab546
14 changed files with 82 additions and 35 deletions

View File

@@ -4,29 +4,55 @@ set(BOLT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(BOLT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_CXX_STANDARD 14)
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}
-DCMAKE_INSTALL_PREFIX=${LLVM_BINARY_DIR}
# You might want to set this to True if actively developing bolt_rt, otherwise
# cmake will not rebuild it after source code changes
BUILD_ALWAYS True
)
if (NOT CMAKE_HOST_SYSTEM_NAME MATCHES Linux)
message(WARNING "Not building BOLT on unsupported platform")
else()
set(BOLT_ENABLE_RUNTIME OFF)
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
set(BOLT_ENABLE_RUNTIME ON)
endif()
include_directories( ${BOLT_SOURCE_DIR}/include )
set(BOLT_INCLUDE_TESTS OFF)
if (LLVM_INCLUDE_TESTS)
string(FIND "${LLVM_ENABLE_PROJECTS}" "clang" POSITION)
if (NOT ${POSITION} EQUAL -1)
string(FIND "${LLVM_ENABLE_PROJECTS}" "lld" POSITION)
if (NOT ${POSITION} EQUAL -1)
set(BOLT_INCLUDE_TESTS ON)
else()
message(WARNING "Not including BOLT tests since lld is disabled")
endif()
else()
message(WARNING "Not including BOLT tests since clang is disabled")
endif()
endif()
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_rt)
if (BOLT_ENABLE_RUNTIME)
message(STATUS "Building BOLT runtime libraries for X86")
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}
-DCMAKE_INSTALL_PREFIX=${LLVM_BINARY_DIR}
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_rt)
add_llvm_install_targets(install-bolt_rt
DEPENDS bolt_rt
COMPONENT bolt_rt)
endif()
add_llvm_install_targets(install-bolt_rt
DEPENDS bolt_rt
COMPONENT bolt_rt)
include_directories( ${BOLT_SOURCE_DIR}/include )
add_subdirectory(lib)
add_subdirectory(test)
add_subdirectory(tools)
add_subdirectory(lib)
add_subdirectory(tools)
if (BOLT_INCLUDE_TESTS)
add_subdirectory(test)
endif()
endif()