1 | # TODO: Set the install directory. |
2 | |
3 | include(ExternalProject) |
4 | |
5 | set(known_subdirs |
6 | "libcxx" |
7 | ) |
8 | |
9 | foreach (dir ${known_subdirs}) |
10 | if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt) |
11 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${dir}) |
12 | endif() |
13 | endforeach() |
14 | |
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) |
19 | else() |
20 | set(${out_var} ${CMAKE_COMMAND} --build . --target ${target} |
21 | --config $<CONFIGURATION> PARENT_SCOPE) |
22 | endif() |
23 | endfunction() |
24 | |
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}) |
33 | endif() |
34 | endif() |
35 | |
36 | if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/) |
37 | |
38 | # Add compiler-rt as an external project. |
39 | set(COMPILER_RT_PREFIX ${CMAKE_BINARY_DIR}/projects/compiler-rt) |
40 | |
41 | set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/compiler-rt-stamps/) |
42 | set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/compiler-rt-bins/) |
43 | |
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" |
48 | ) |
49 | |
50 | # Find all variables that start with COMPILER_RT and populate a variable with |
51 | # them. |
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}) |
58 | endif() |
59 | endforeach() |
60 | |
61 | set(compiler_rt_configure_deps) |
62 | if(TARGET cxx-headers) |
63 | list(APPEND compiler_rt_configure_deps "cxx-headers") |
64 | endif() |
65 | if(LLVM_INCLUDE_TESTS) |
66 | list(APPEND compiler_rt_configure_deps LLVMTestingSupport) |
67 | endif() |
68 | |
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_BUILD_TYPE=${CMAKE_BUILD_TYPE} |
79 | -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} |
80 | -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config |
81 | -DLLVM_LIT_ARGS=${LLVM_LIT_ARGS} |
82 | -DCOMPILER_RT_OUTPUT_DIR=${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION} |
83 | -DCOMPILER_RT_EXEC_OUTPUT_DIR=${LLVM_RUNTIME_OUTPUT_INTDIR} |
84 | -DCOMPILER_RT_INSTALL_PATH:STRING=lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION} |
85 | -DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS} |
86 | -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} |
87 | -DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX} |
88 | -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_RUNTIME_OUTPUT_INTDIR} |
89 | -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} |
90 | -DCMAKE_OSX_SYSROOT:PATH=${CMAKE_OSX_SYSROOT} |
91 | ${COMPILER_RT_PASSTHROUGH_VARIABLES} |
92 | INSTALL_COMMAND "" |
93 | STEP_TARGETS configure build |
94 | USES_TERMINAL_CONFIGURE 1 |
95 | USES_TERMINAL_BUILD 1 |
96 | USES_TERMINAL_INSTALL 1 |
97 | ) |
98 | |
99 | get_ext_project_build_command(run_clean_compiler_rt clean) |
100 | ExternalProject_Add_Step(compiler-rt clean |
101 | COMMAND ${run_clean_compiler_rt} |
102 | COMMENT "Cleaning compiler-rt..." |
103 | DEPENDEES configure |
104 | DEPENDERS build |
105 | DEPENDS clang |
106 | WORKING_DIRECTORY ${BINARY_DIR} |
107 | ) |
108 | |
109 | install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${BINARY_DIR}/cmake_install.cmake \)" |
110 | COMPONENT compiler-rt) |
111 | |
112 | add_llvm_install_targets(install-compiler-rt |
113 | DEPENDS compiler-rt |
114 | COMPONENT compiler-rt) |
115 | |
116 | # Add top-level targets that build specific compiler-rt runtimes. |
117 | set(COMPILER_RT_RUNTIMES fuzzer asan builtins dfsan lsan msan profile tsan ubsan ubsan-minimal) |
118 | foreach(runtime ${COMPILER_RT_RUNTIMES}) |
119 | get_ext_project_build_command(build_runtime_cmd ${runtime}) |
120 | add_custom_target(${runtime} |
121 | COMMAND ${build_runtime_cmd} |
122 | DEPENDS compiler-rt-configure |
123 | WORKING_DIRECTORY ${BINARY_DIR} |
124 | VERBATIM USES_TERMINAL) |
125 | endforeach() |
126 | |
127 | if(LLVM_INCLUDE_TESTS) |
128 | # Add binaries that compiler-rt tests depend on. |
129 | set(COMPILER_RT_TEST_DEPENDENCIES |
130 | FileCheck count not llvm-nm llvm-objdump llvm-symbolizer) |
131 | |
132 | # Add top-level targets for various compiler-rt test suites. |
133 | set(COMPILER_RT_TEST_SUITES check-fuzzer check-asan check-hwasan check-asan-dynamic check-dfsan |
134 | check-lsan check-msan check-sanitizer check-tsan check-ubsan check-ubsan-minimal |
135 | check-profile check-cfi check-cfi-and-supported check-safestack) |
136 | foreach(test_suite ${COMPILER_RT_TEST_SUITES}) |
137 | get_ext_project_build_command(run_test_suite ${test_suite}) |
138 | add_custom_target(${test_suite} |
139 | COMMAND ${run_test_suite} |
140 | DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES} |
141 | WORKING_DIRECTORY ${BINARY_DIR} |
142 | VERBATIM |
143 | USES_TERMINAL |
144 | ) |
145 | endforeach() |
146 | |
147 | # Add special target to run all compiler-rt test suites. |
148 | get_ext_project_build_command(run_check_compiler_rt check-all) |
149 | add_custom_target(check-compiler-rt |
150 | COMMAND ${run_check_compiler_rt} |
151 | DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES} |
152 | WORKING_DIRECTORY ${BINARY_DIR} |
153 | VERBATIM USES_TERMINAL) |
154 | |
155 | # Add special target to run all compiler-rt test suites. |
156 | get_ext_project_build_command(run_check_compiler_rt compiler-rt-test-depends) |
157 | add_custom_target(compiler-rt-test-depends |
158 | COMMAND ${run_check_compiler_rt} |
159 | DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES} |
160 | WORKING_DIRECTORY ${BINARY_DIR} |
161 | VERBATIM USES_TERMINAL) |
162 | set_property(GLOBAL APPEND PROPERTY LLVM_ADDITIONAL_TEST_DEPENDS compiler-rt-test-depends) |
163 | set_property(GLOBAL APPEND PROPERTY LLVM_ADDITIONAL_TEST_TARGETS check-compiler-rt) |
164 | endif() |
165 | endif() |
166 | |