1 # TODO: Set the install directory.
3 include(ExternalProject)
9 foreach (dir ${known_subdirs})
10 if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt)
11 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${dir})
15 function(get_ext_project_build_command out_var target)
16 if (CMAKE_GENERATOR MATCHES "Make")
17 # Use special command for Makefiles to support parallelism.
18 set(${out_var} "$(MAKE)" "${target}" PARENT_SCOPE)
20 set(${out_var} ${CMAKE_COMMAND} --build . --target ${target}
21 --config $<CONFIG> PARENT_SCOPE)
25 set(COMPILER_RT_SRC_ROOT ${LLVM_MAIN_SRC_DIR}/projects/compiler-rt)
26 # Fallback to the external path, if the other one isn't available.
27 # This is the same behavior (try "internal", then check the LLVM_EXTERNAL_...
28 # variable) as in add_llvm_external_project
29 if(NOT EXISTS ${COMPILER_RT_SRC_ROOT})
30 # We don't want to set it if LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR is ""
31 if(LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR)
32 set(COMPILER_RT_SRC_ROOT ${LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR})
36 if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
38 # Add compiler-rt as an external project.
39 set(COMPILER_RT_PREFIX ${CMAKE_BINARY_DIR}/projects/compiler-rt)
41 set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/compiler-rt-stamps/)
42 set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/compiler-rt-bins/)
44 add_custom_target(compiler-rt-clear
45 COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR}
46 COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR}
47 COMMENT "Clobberring compiler-rt build and stamp directories"
50 # Find all variables that start with COMPILER_RT and populate a variable with
52 get_cmake_property(variableNames VARIABLES)
53 foreach(variableName ${variableNames})
54 if(variableName MATCHES "^COMPILER_RT")
55 string(REPLACE ";" "\;" value "${${variableName}}")
56 list(APPEND COMPILER_RT_PASSTHROUGH_VARIABLES
57 -D${variableName}=${value})
61 set(compiler_rt_configure_deps)
62 if(TARGET cxx-headers)
63 list(APPEND compiler_rt_configure_deps "cxx-headers")
65 if(LLVM_INCLUDE_TESTS)
66 list(APPEND compiler_rt_configure_deps LLVMTestingSupport)
69 ExternalProject_Add(compiler-rt
70 DEPENDS llvm-config clang ${compiler_rt_configure_deps}
71 PREFIX ${COMPILER_RT_PREFIX}
72 SOURCE_DIR ${COMPILER_RT_SRC_ROOT}
73 STAMP_DIR ${STAMP_DIR}
74 BINARY_DIR ${BINARY_DIR}
75 CMAKE_ARGS ${CLANG_COMPILER_RT_CMAKE_ARGS}
76 -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
77 -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
78 -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
79 -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
80 -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
81 -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
82 -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
83 -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config
84 -DLLVM_LIT_ARGS=${LLVM_LIT_ARGS}
85 -DCOMPILER_RT_OUTPUT_DIR=${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}
86 -DCOMPILER_RT_EXEC_OUTPUT_DIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
87 -DCOMPILER_RT_INSTALL_PATH:PATH=lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}
88 -DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
89 -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
90 -DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
91 -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
92 -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
93 -DCMAKE_OSX_SYSROOT:PATH=${CMAKE_OSX_SYSROOT}
94 ${COMPILER_RT_PASSTHROUGH_VARIABLES}
96 STEP_TARGETS configure build
97 USES_TERMINAL_CONFIGURE 1
99 USES_TERMINAL_INSTALL 1
100 # Always run the build command so that incremental builds are correct.
104 get_ext_project_build_command(run_clean_compiler_rt clean)
105 ExternalProject_Add_Step(compiler-rt clean
106 COMMAND ${run_clean_compiler_rt}
107 COMMENT "Cleaning compiler-rt..."
111 WORKING_DIRECTORY ${BINARY_DIR}
114 install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${BINARY_DIR}/cmake_install.cmake \)"
115 COMPONENT compiler-rt)
117 add_llvm_install_targets(install-compiler-rt
119 COMPONENT compiler-rt)
121 # Add top-level targets that build specific compiler-rt runtimes.
122 set(COMPILER_RT_RUNTIMES fuzzer asan builtins dfsan lsan msan profile tsan ubsan ubsan-minimal)
123 foreach(runtime ${COMPILER_RT_RUNTIMES})
124 get_ext_project_build_command(build_runtime_cmd ${runtime})
125 add_custom_target(${runtime}
126 COMMAND ${build_runtime_cmd}
127 DEPENDS compiler-rt-configure
128 WORKING_DIRECTORY ${BINARY_DIR}
129 VERBATIM USES_TERMINAL)
132 if(LLVM_INCLUDE_TESTS)
133 # Add binaries that compiler-rt tests depend on.
134 set(COMPILER_RT_TEST_DEPENDENCIES
135 FileCheck count not llvm-nm llvm-objdump llvm-symbolizer llvm-jitlink lli)
137 # Add top-level targets for various compiler-rt test suites.
138 set(COMPILER_RT_TEST_SUITES check-fuzzer check-asan check-hwasan check-asan-dynamic check-dfsan
139 check-lsan check-msan check-sanitizer check-tsan check-ubsan check-ubsan-minimal
140 check-profile check-cfi check-cfi-and-supported check-safestack check-gwp_asan)
141 foreach(test_suite ${COMPILER_RT_TEST_SUITES})
142 get_ext_project_build_command(run_test_suite ${test_suite})
143 add_custom_target(${test_suite}
144 COMMAND ${run_test_suite}
145 DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
146 WORKING_DIRECTORY ${BINARY_DIR}
152 # Add special target to run all compiler-rt test suites.
153 get_ext_project_build_command(run_check_compiler_rt check-all)
154 add_custom_target(check-compiler-rt
155 COMMAND ${run_check_compiler_rt}
156 DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
157 WORKING_DIRECTORY ${BINARY_DIR}
158 VERBATIM USES_TERMINAL)
160 # Add special target to run all compiler-rt test suites.
161 get_ext_project_build_command(run_check_compiler_rt compiler-rt-test-depends)
162 add_custom_target(compiler-rt-test-depends
163 COMMAND ${run_check_compiler_rt}
164 DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
165 WORKING_DIRECTORY ${BINARY_DIR}
166 VERBATIM USES_TERMINAL)
167 set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_DEPENDS compiler-rt-test-depends)
168 set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_TARGETS check-compiler-rt)