2010-12-16 11:28:42 +08:00
|
|
|
# TODO: Set the install directory.
|
|
|
|
|
2014-02-27 17:09:39 +08:00
|
|
|
include(ExternalProject)
|
|
|
|
|
2010-12-16 11:28:42 +08:00
|
|
|
set(known_subdirs
|
2011-10-01 04:24:28 +08:00
|
|
|
"libcxx"
|
2010-12-16 11:28:42 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
foreach (dir ${known_subdirs})
|
|
|
|
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt)
|
|
|
|
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${dir})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2014-02-27 17:09:39 +08:00
|
|
|
|
2014-03-21 21:09:25 +08:00
|
|
|
function(get_ext_project_build_command out_var target)
|
|
|
|
if (CMAKE_GENERATOR MATCHES "Make")
|
|
|
|
# Use special command for Makefiles to support parallelism.
|
|
|
|
set(${out_var} "$(MAKE)" "${target}" PARENT_SCOPE)
|
|
|
|
else()
|
|
|
|
set(${out_var} ${CMAKE_COMMAND} --build . --target ${target}
|
|
|
|
--config $<CONFIGURATION> PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2014-02-27 17:09:39 +08:00
|
|
|
set(COMPILER_RT_SRC_ROOT ${LLVM_MAIN_SRC_DIR}/projects/compiler-rt)
|
2016-03-01 22:08:13 +08:00
|
|
|
# Fallback to the external path, if the other one isn't available.
|
|
|
|
# This is the same behavior (try "internal", then check the LLVM_EXTERNAL_...
|
|
|
|
# variable) as in add_llvm_external_project
|
|
|
|
if(NOT EXISTS ${COMPILER_RT_SRC_ROOT})
|
2016-03-01 23:07:19 +08:00
|
|
|
# We don't want to set it if LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR is ""
|
|
|
|
if(${LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR})
|
|
|
|
set(COMPILER_RT_SRC_ROOT ${LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR})
|
|
|
|
endif()
|
2016-03-01 22:08:13 +08:00
|
|
|
endif()
|
|
|
|
|
2014-02-27 17:09:39 +08:00
|
|
|
if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
|
|
|
|
|
|
|
|
# Add compiler-rt as an external project.
|
|
|
|
set(COMPILER_RT_PREFIX ${CMAKE_BINARY_DIR}/projects/compiler-rt)
|
2015-10-13 00:34:23 +08:00
|
|
|
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2015-10-14 02:17:30 +08:00
|
|
|
# Find all variables that start with COMPILER_RT and populate a variable with
|
|
|
|
# them.
|
|
|
|
get_cmake_property(variableNames VARIABLES)
|
2015-11-24 07:34:13 +08:00
|
|
|
foreach(variableName ${variableNames})
|
|
|
|
if(variableName MATCHES "^COMPILER_RT")
|
|
|
|
string(REPLACE ";" "\;" value "${${variableName}}")
|
2015-10-14 02:17:30 +08:00
|
|
|
list(APPEND COMPILER_RT_PASSTHROUGH_VARIABLES
|
2015-12-04 03:47:25 +08:00
|
|
|
-D${variableName}=${value})
|
2015-10-14 02:17:30 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2018-06-29 02:35:25 +08:00
|
|
|
if(TARGET cxx-headers)
|
|
|
|
set(COMPILER_RT_LIBCXX_DEPENDENCY "cxx-headers")
|
|
|
|
endif()
|
|
|
|
|
2014-02-27 17:09:39 +08:00
|
|
|
ExternalProject_Add(compiler-rt
|
2018-06-29 02:35:25 +08:00
|
|
|
DEPENDS llvm-config clang ${COMPILER_RT_LIBCXX_DEPENDENCY}
|
2014-02-27 17:09:39 +08:00
|
|
|
PREFIX ${COMPILER_RT_PREFIX}
|
|
|
|
SOURCE_DIR ${COMPILER_RT_SRC_ROOT}
|
2015-10-13 00:34:23 +08:00
|
|
|
STAMP_DIR ${STAMP_DIR}
|
|
|
|
BINARY_DIR ${BINARY_DIR}
|
|
|
|
CMAKE_ARGS ${CLANG_COMPILER_RT_CMAKE_ARGS}
|
|
|
|
-DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
|
2014-02-27 17:09:39 +08:00
|
|
|
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
|
2015-10-13 00:34:23 +08:00
|
|
|
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
2015-12-10 06:46:25 +08:00
|
|
|
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
|
2014-02-27 17:09:39 +08:00
|
|
|
-DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config
|
2016-06-29 01:00:49 +08:00
|
|
|
-DLLVM_LIT_ARGS=${LLVM_LIT_ARGS}
|
2014-02-27 17:09:39 +08:00
|
|
|
-DCOMPILER_RT_OUTPUT_DIR=${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}
|
|
|
|
-DCOMPILER_RT_EXEC_OUTPUT_DIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
|
2015-10-21 00:39:25 +08:00
|
|
|
-DCOMPILER_RT_INSTALL_PATH:STRING=lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}
|
2014-02-27 17:09:39 +08:00
|
|
|
-DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
|
2015-10-13 00:34:23 +08:00
|
|
|
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
|
2016-06-07 04:18:38 +08:00
|
|
|
-DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
|
2017-09-16 06:10:46 +08:00
|
|
|
-DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
|
2016-11-15 06:38:57 +08:00
|
|
|
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
|
2016-12-16 07:20:54 +08:00
|
|
|
-DCMAKE_OSX_SYSROOT:PATH=${CMAKE_OSX_SYSROOT}
|
2015-10-14 02:17:30 +08:00
|
|
|
${COMPILER_RT_PASSTHROUGH_VARIABLES}
|
2014-02-27 17:09:39 +08:00
|
|
|
INSTALL_COMMAND ""
|
2014-03-21 21:09:25 +08:00
|
|
|
STEP_TARGETS configure build
|
2016-06-10 06:38:42 +08:00
|
|
|
USES_TERMINAL_CONFIGURE 1
|
|
|
|
USES_TERMINAL_BUILD 1
|
|
|
|
USES_TERMINAL_INSTALL 1
|
2014-02-27 17:09:39 +08:00
|
|
|
)
|
2015-10-13 00:34:23 +08:00
|
|
|
|
|
|
|
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}
|
2014-02-27 17:09:39 +08:00
|
|
|
)
|
|
|
|
|
2015-10-21 00:39:25 +08:00
|
|
|
install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${BINARY_DIR}/cmake_install.cmake \)"
|
2015-10-13 00:34:23 +08:00
|
|
|
COMPONENT compiler-rt)
|
|
|
|
|
2017-12-01 06:35:02 +08:00
|
|
|
add_llvm_install_targets(install-compiler-rt
|
|
|
|
DEPENDS compiler-rt
|
|
|
|
COMPONENT compiler-rt)
|
2014-03-21 21:09:25 +08:00
|
|
|
|
|
|
|
# Add top-level targets that build specific compiler-rt runtimes.
|
2017-10-14 06:03:09 +08:00
|
|
|
set(COMPILER_RT_RUNTIMES fuzzer asan builtins dfsan lsan msan profile tsan ubsan ubsan-minimal)
|
2014-03-21 21:09:25 +08:00
|
|
|
foreach(runtime ${COMPILER_RT_RUNTIMES})
|
|
|
|
get_ext_project_build_command(build_runtime_cmd ${runtime})
|
|
|
|
add_custom_target(${runtime}
|
|
|
|
COMMAND ${build_runtime_cmd}
|
|
|
|
DEPENDS compiler-rt-configure
|
2015-10-13 00:34:23 +08:00
|
|
|
WORKING_DIRECTORY ${BINARY_DIR}
|
2016-06-29 04:30:52 +08:00
|
|
|
VERBATIM USES_TERMINAL)
|
2014-03-21 21:09:25 +08:00
|
|
|
endforeach()
|
|
|
|
|
2015-10-13 00:34:23 +08:00
|
|
|
if(LLVM_INCLUDE_TESTS)
|
|
|
|
# Add binaries that compiler-rt tests depend on.
|
|
|
|
set(COMPILER_RT_TEST_DEPENDENCIES
|
2015-12-08 06:45:36 +08:00
|
|
|
FileCheck count not llvm-nm llvm-objdump llvm-symbolizer)
|
2015-10-13 00:34:23 +08:00
|
|
|
|
|
|
|
# Add top-level targets for various compiler-rt test suites.
|
2017-10-14 07:50:53 +08:00
|
|
|
set(COMPILER_RT_TEST_SUITES check-fuzzer check-asan check-asan-dynamic check-dfsan
|
2017-09-02 04:37:20 +08:00
|
|
|
check-lsan check-msan check-sanitizer check-tsan check-ubsan check-ubsan-minimal
|
2016-03-01 23:33:52 +08:00
|
|
|
check-profile check-cfi check-cfi-and-supported check-safestack)
|
2015-10-13 00:34:23 +08:00
|
|
|
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}
|
2016-03-01 22:08:18 +08:00
|
|
|
VERBATIM
|
2016-06-09 06:20:43 +08:00
|
|
|
USES_TERMINAL
|
2016-03-01 22:08:18 +08:00
|
|
|
)
|
2015-10-13 00:34:23 +08:00
|
|
|
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}
|
2014-03-21 21:09:25 +08:00
|
|
|
DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
|
2015-10-13 00:34:23 +08:00
|
|
|
WORKING_DIRECTORY ${BINARY_DIR}
|
2016-06-29 02:32:22 +08:00
|
|
|
VERBATIM USES_TERMINAL)
|
2016-09-02 02:28:49 +08:00
|
|
|
|
|
|
|
# Add special target to run all compiler-rt test suites.
|
|
|
|
get_ext_project_build_command(run_check_compiler_rt compiler-rt-test-depends)
|
|
|
|
add_custom_target(compiler-rt-test-depends
|
|
|
|
COMMAND ${run_check_compiler_rt}
|
|
|
|
DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
|
|
|
|
WORKING_DIRECTORY ${BINARY_DIR}
|
|
|
|
VERBATIM USES_TERMINAL)
|
|
|
|
set_property(GLOBAL APPEND PROPERTY LLVM_ADDITIONAL_TEST_DEPENDS compiler-rt-test-depends)
|
|
|
|
set_property(GLOBAL APPEND PROPERTY LLVM_ADDITIONAL_TEST_TARGETS check-compiler-rt)
|
2015-10-13 00:34:23 +08:00
|
|
|
endif()
|
2014-02-27 17:09:39 +08:00
|
|
|
endif()
|