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}/)
|
2015-10-13 00:34:23 +08:00
|
|
|
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
|
|
|
|
)
|
2014-02-27 17:09:39 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# 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()
|
|
|
|
|
2014-02-27 17:09:39 +08:00
|
|
|
ExternalProject_Add(compiler-rt
|
2015-12-17 02:42:14 +08:00
|
|
|
DEPENDS llvm-config clang
|
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
|
|
|
|
-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-03-01 22:10:38 +08:00
|
|
|
-Dcmake_3_2_USES_TERMINAL=${cmake_3_2_USES_TERMINAL}
|
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
|
2015-10-13 00:34:23 +08:00
|
|
|
${cmake_3_4_USES_TERMINAL_OPTIONS}
|
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)
|
|
|
|
|
|
|
|
add_custom_target(install-compiler-rt
|
|
|
|
DEPENDS compiler-rt
|
|
|
|
COMMAND "${CMAKE_COMMAND}"
|
|
|
|
-DCMAKE_INSTALL_COMPONENT=compiler-rt
|
|
|
|
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
2014-03-21 21:09:25 +08:00
|
|
|
|
|
|
|
# Add top-level targets that build specific compiler-rt runtimes.
|
|
|
|
set(COMPILER_RT_RUNTIMES asan builtins dfsan lsan msan profile tsan ubsan)
|
|
|
|
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}
|
2014-03-21 21:09:25 +08:00
|
|
|
VERBATIM)
|
|
|
|
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.
|
|
|
|
set(COMPILER_RT_TEST_SUITES check-asan check-asan-dynamic check-dfsan
|
2016-03-01 23:33:52 +08:00
|
|
|
check-lsan check-msan check-sanitizer check-tsan check-ubsan
|
|
|
|
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
|
|
|
|
${cmake_3_2_USES_TERMINAL}
|
|
|
|
)
|
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}
|
2014-03-21 21:09:25 +08:00
|
|
|
VERBATIM)
|
2015-10-13 00:34:23 +08:00
|
|
|
endif()
|
2014-02-27 17:09:39 +08:00
|
|
|
endif()
|
2016-02-25 04:46:36 +08:00
|
|
|
|
|
|
|
set(src "${CMAKE_CURRENT_SOURCE_DIR}/vtables_blacklist.txt")
|
|
|
|
set(dst "${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/vtables_blacklist.txt")
|
|
|
|
add_custom_command(OUTPUT ${dst}
|
|
|
|
DEPENDS ${src}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
|
|
|
|
COMMENT "Copying vtables blacklist")
|
|
|
|
add_custom_target(vtables_blacklist DEPENDS ${dst})
|
2016-04-12 23:09:17 +08:00
|
|
|
set_target_properties(vtables_blacklist PROPERTIES FOLDER "Misc")
|
2016-02-26 11:07:33 +08:00
|
|
|
if(TARGET clang)
|
|
|
|
add_dependencies(clang vtables_blacklist)
|
|
|
|
endif()
|
2016-02-25 04:46:36 +08:00
|
|
|
install(FILES ${src} DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION})
|