mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-02 18:58:15 +00:00
[CMake] Bug 14109 - CMake build for compiler-rt should use just-built clang
Summary: Many small improvements to LLVM_BUILD_EXTERNAL_COMPILER_RT. * Works correctly with Ninja by working around CMake Bug 14771 (https://cmake.org/Bug/view.php?id=14771) * Has install-compiler-rt target, and installs as part of the default install target * Sets the install paths properly so that it matches the non-standalone build * Only generate the test targets if(LLVM_INCLUDE_TESTS) Reviewers: samsonov, Bigcheese Differential Revision: http://reviews.llvm.org/D13399 llvm-svn: 250064
This commit is contained in:
parent
150def9787
commit
a1566a414a
@ -24,52 +24,66 @@ endfunction()
|
||||
|
||||
set(COMPILER_RT_SRC_ROOT ${LLVM_MAIN_SRC_DIR}/projects/compiler-rt)
|
||||
if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
|
||||
if(CMAKE_GENERATOR MATCHES "Ninja")
|
||||
message(FATAL_ERROR
|
||||
"Ninja generator can't build compiler-rt as ExternalProject."
|
||||
"Unset LLVM_BUILD_EXTERNAL_COMPILER_RT, or don't use Ninja."
|
||||
"See http://www.cmake.org/Bug/view.php?id=14771")
|
||||
if(CMAKE_VERSION VERSION_GREATER 3.3.20150708)
|
||||
set(cmake_3_4_USES_TERMINAL_OPTIONS
|
||||
USES_TERMINAL_CONFIGURE 1
|
||||
USES_TERMINAL_BUILD 1
|
||||
USES_TERMINAL_INSTALL 1
|
||||
)
|
||||
endif()
|
||||
|
||||
# Add compiler-rt as an external project.
|
||||
set(COMPILER_RT_PREFIX ${CMAKE_BINARY_DIR}/projects/compiler-rt)
|
||||
|
||||
|
||||
set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/compiler-rt-stamps/)
|
||||
set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/compiler-rt-bins/)
|
||||
|
||||
add_custom_target(compiler-rt-clear
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR}
|
||||
COMMENT "Clobberring compiler-rt build and stamp directories"
|
||||
)
|
||||
|
||||
ExternalProject_Add(compiler-rt
|
||||
PREFIX ${COMPILER_RT_PREFIX}
|
||||
SOURCE_DIR ${COMPILER_RT_SRC_ROOT}
|
||||
CMAKE_ARGS -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
|
||||
STAMP_DIR ${STAMP_DIR}
|
||||
BINARY_DIR ${BINARY_DIR}
|
||||
CMAKE_ARGS ${CLANG_COMPILER_RT_CMAKE_ARGS}
|
||||
-DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
|
||||
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
||||
-DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config
|
||||
-DCOMPILER_RT_OUTPUT_DIR=${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}
|
||||
-DCOMPILER_RT_EXEC_OUTPUT_DIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
|
||||
-DCOMPILER_RT_INSTALL_PATH=lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}
|
||||
-DCOMPILER_RT_INSTALL_PATH=${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}
|
||||
-DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
|
||||
-DCOMPILER_RT_ENABLE_WERROR=ON
|
||||
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
|
||||
INSTALL_COMMAND ""
|
||||
STEP_TARGETS configure build
|
||||
)
|
||||
# Due to a bug, DEPENDS in ExternalProject_Add doesn't work
|
||||
# in CMake 2.8.9 and 2.8.10.
|
||||
add_dependencies(compiler-rt llvm-config clang)
|
||||
|
||||
# Add a custom step to always re-configure compiler-rt (in case some of its
|
||||
# sources have changed).
|
||||
ExternalProject_Add_Step(compiler-rt force-reconfigure
|
||||
DEPENDERS configure
|
||||
ALWAYS 1
|
||||
${cmake_3_4_USES_TERMINAL_OPTIONS}
|
||||
)
|
||||
|
||||
ExternalProject_Add_Step(compiler-rt clobber
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory <BINARY_DIR>
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory <BINARY_DIR>
|
||||
COMMENT "Clobberring compiler-rt build directory..."
|
||||
DEPENDERS configure
|
||||
DEPENDS ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
|
||||
)
|
||||
get_ext_project_build_command(run_clean_compiler_rt clean)
|
||||
ExternalProject_Add_Step(compiler-rt clean
|
||||
COMMAND ${run_clean_compiler_rt}
|
||||
COMMENT "Cleaning compiler-rt..."
|
||||
DEPENDEES configure
|
||||
DEPENDERS build
|
||||
DEPENDS clang
|
||||
WORKING_DIRECTORY ${BINARY_DIR}
|
||||
)
|
||||
|
||||
ExternalProject_Get_Property(compiler-rt BINARY_DIR)
|
||||
set(COMPILER_RT_BINARY_DIR ${BINARY_DIR})
|
||||
add_dependencies(compiler-rt-configure clang llvm-config)
|
||||
|
||||
install(CODE "execute_process\(COMMAND ${CMAKE_COMMAND} -P ${BINARY_DIR}/cmake_install.cmake \)"
|
||||
COMPONENT compiler-rt)
|
||||
|
||||
add_custom_target(install-compiler-rt
|
||||
DEPENDS compiler-rt
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
-DCMAKE_INSTALL_COMPONENT=compiler-rt
|
||||
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
||||
|
||||
# Add top-level targets that build specific compiler-rt runtimes.
|
||||
set(COMPILER_RT_RUNTIMES asan builtins dfsan lsan msan profile tsan ubsan)
|
||||
@ -78,31 +92,33 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
|
||||
add_custom_target(${runtime}
|
||||
COMMAND ${build_runtime_cmd}
|
||||
DEPENDS compiler-rt-configure
|
||||
WORKING_DIRECTORY ${COMPILER_RT_BINARY_DIR}
|
||||
WORKING_DIRECTORY ${BINARY_DIR}
|
||||
VERBATIM)
|
||||
endforeach()
|
||||
|
||||
# Add binaries that compiler-rt tests depend on.
|
||||
set(COMPILER_RT_TEST_DEPENDENCIES
|
||||
FileCheck count not llvm-nm llvm-symbolizer)
|
||||
if(LLVM_INCLUDE_TESTS)
|
||||
# Add binaries that compiler-rt tests depend on.
|
||||
set(COMPILER_RT_TEST_DEPENDENCIES
|
||||
FileCheck count not llvm-nm llvm-symbolizer)
|
||||
|
||||
# Add top-level targets for various compiler-rt test suites.
|
||||
set(COMPILER_RT_TEST_SUITES check-asan check-asan-dynamic check-dfsan
|
||||
check-lsan check-msan check-sanitizer check-tsan check-ubsan)
|
||||
foreach(test_suite ${COMPILER_RT_TEST_SUITES})
|
||||
get_ext_project_build_command(run_test_suite ${test_suite})
|
||||
add_custom_target(${test_suite}
|
||||
COMMAND ${run_test_suite}
|
||||
# Add top-level targets for various compiler-rt test suites.
|
||||
set(COMPILER_RT_TEST_SUITES check-asan check-asan-dynamic check-dfsan
|
||||
check-lsan check-msan check-sanitizer check-tsan check-ubsan)
|
||||
foreach(test_suite ${COMPILER_RT_TEST_SUITES})
|
||||
get_ext_project_build_command(run_test_suite ${test_suite})
|
||||
add_custom_target(${test_suite}
|
||||
COMMAND ${run_test_suite}
|
||||
DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
|
||||
WORKING_DIRECTORY ${BINARY_DIR}
|
||||
VERBATIM)
|
||||
endforeach()
|
||||
|
||||
# Add special target to run all compiler-rt test suites.
|
||||
get_ext_project_build_command(run_check_compiler_rt check-all)
|
||||
add_custom_target(check-compiler-rt
|
||||
COMMAND ${run_check_compiler_rt}
|
||||
DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
|
||||
WORKING_DIRECTORY ${COMPILER_RT_BINARY_DIR}
|
||||
WORKING_DIRECTORY ${BINARY_DIR}
|
||||
VERBATIM)
|
||||
endforeach()
|
||||
|
||||
# Add special target to run all compiler-rt test suites.
|
||||
get_ext_project_build_command(run_check_compiler_rt check-all)
|
||||
add_custom_target(check-compiler-rt
|
||||
COMMAND ${run_check_compiler_rt}
|
||||
DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
|
||||
WORKING_DIRECTORY ${COMPILER_RT_BINARY_DIR}
|
||||
VERBATIM)
|
||||
endif()
|
||||
endif()
|
||||
|
Loading…
Reference in New Issue
Block a user