Rename GetLanguageInfo to GetLanguageSpecificData (#117012)
[llvm-project.git] / clang / runtime / CMakeLists.txt
blob65fcdc2868f0318dd63e756c2243e4415dda2b9a
1 # TODO: Set the install directory.
3 include(ExternalProject)
5 set(known_subdirs
6   "libcxx"
7   )
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()
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 $<CONFIG> PARENT_SCOPE)
22   endif()
23 endfunction()
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()
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"
48     )
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()
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()
69   include(GetClangResourceDir)
70   get_clang_resource_dir(output_resource_dir PREFIX ${LLVM_BINARY_DIR})
71   get_clang_resource_dir(install_resource_dir)
72   ExternalProject_Add(compiler-rt
73     DEPENDS llvm-config clang ${compiler_rt_configure_deps}
74     PREFIX ${COMPILER_RT_PREFIX}
75     SOURCE_DIR ${COMPILER_RT_SRC_ROOT}
76     STAMP_DIR ${STAMP_DIR}
77     BINARY_DIR ${BINARY_DIR}
78     CMAKE_ARGS ${CLANG_COMPILER_RT_CMAKE_ARGS}
79                -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
80                -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
81                -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
82                -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
83                -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
84                -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
85                -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
86                -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config
87                -DLLVM_LIT_ARGS=${LLVM_LIT_ARGS}
88                -DCOMPILER_RT_OUTPUT_DIR=${output_resource_dir}
89                -DCOMPILER_RT_EXEC_OUTPUT_DIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
90                -DCOMPILER_RT_INSTALL_PATH:PATH=${install_resource_dir}
91                -DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
92                -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
93                -DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
94                -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
95                -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
96                -DCMAKE_OSX_SYSROOT:PATH=${CMAKE_OSX_SYSROOT}
97                ${COMPILER_RT_PASSTHROUGH_VARIABLES}
98     INSTALL_COMMAND ""
99     STEP_TARGETS configure build
100     USES_TERMINAL_CONFIGURE 1
101     USES_TERMINAL_BUILD 1
102     USES_TERMINAL_INSTALL 1
103     # Always run the build command so that incremental builds are correct.
104     BUILD_ALWAYS 1
105     )
107   get_ext_project_build_command(run_clean_compiler_rt clean)
108   ExternalProject_Add_Step(compiler-rt clean
109     COMMAND ${run_clean_compiler_rt}
110     COMMENT "Cleaning compiler-rt..."
111     DEPENDEES configure
112     DEPENDERS build
113     DEPENDS clang
114     WORKING_DIRECTORY ${BINARY_DIR}
115     )
117   install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${BINARY_DIR}/cmake_install.cmake \)"
118     COMPONENT compiler-rt)
120   add_llvm_install_targets(install-compiler-rt
121                            DEPENDS compiler-rt
122                            COMPONENT compiler-rt)
124   # Add top-level targets that build specific compiler-rt runtimes.
125   set(COMPILER_RT_RUNTIMES fuzzer asan builtins dfsan lsan msan profile tsan ubsan ubsan-minimal)
126   foreach(runtime ${COMPILER_RT_RUNTIMES})
127     get_ext_project_build_command(build_runtime_cmd ${runtime})
128     add_custom_target(${runtime}
129       COMMAND ${build_runtime_cmd}
130       DEPENDS compiler-rt-configure
131       WORKING_DIRECTORY ${BINARY_DIR}
132       VERBATIM USES_TERMINAL)
133   endforeach()
135   if(LLVM_INCLUDE_TESTS)
136     # Add binaries that compiler-rt tests depend on.
137     set(COMPILER_RT_TEST_DEPENDENCIES
138       FileCheck count not llvm-nm llvm-objdump llvm-symbolizer llvm-jitlink lli split-file)
140     # Add top-level targets for various compiler-rt test suites.
141     set(COMPILER_RT_TEST_SUITES
142         check-asan
143         check-asan-dynamic
144         check-cfi
145         check-cfi-and-supported
146         check-dfsan
147         check-fuzzer
148         check-gwp_asan
149         check-hwasan
150         check-lsan
151         check-msan
152         check-profile
153         check-safestack
154         check-sanitizer
155         check-tsan
156         check-ubsan
157         check-ubsan-minimal
158     )
159     foreach(test_suite ${COMPILER_RT_TEST_SUITES})
160       get_ext_project_build_command(run_test_suite ${test_suite})
161       add_custom_target(${test_suite}
162         COMMAND ${run_test_suite}
163         DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
164         WORKING_DIRECTORY ${BINARY_DIR}
165         VERBATIM
166         USES_TERMINAL
167         )
168     endforeach()
170     # Add special target to run all compiler-rt test suites.
171     get_ext_project_build_command(run_check_compiler_rt check-all)
172     add_custom_target(check-compiler-rt
173       COMMAND ${run_check_compiler_rt}
174       DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
175       WORKING_DIRECTORY ${BINARY_DIR}
176       VERBATIM USES_TERMINAL)
178     # Add special target to run all compiler-rt test suites.
179     get_ext_project_build_command(run_check_compiler_rt compiler-rt-test-depends)
180     add_custom_target(compiler-rt-test-depends
181       COMMAND ${run_check_compiler_rt}
182       DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
183       WORKING_DIRECTORY ${BINARY_DIR}
184       VERBATIM USES_TERMINAL)
185     set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_DEPENDS compiler-rt-test-depends)
186     set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_TARGETS check-compiler-rt)
187   endif()
188 endif()