207
|
1 # This file handles building LLVM runtime sub-projects.
|
|
2 cmake_minimum_required(VERSION 3.13.4)
|
|
3 project(Runtimes C CXX ASM)
|
|
4
|
|
5 set(LLVM_ALL_RUNTIMES "compiler-rt;libc;libcxx;libcxxabi;libunwind;openmp")
|
|
6 set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
|
|
7 "Semicolon-separated list of runtimes to build (${LLVM_ALL_RUNTIMES}), or \"all\".")
|
|
8 if(LLVM_ENABLE_RUNTIMES STREQUAL "all" )
|
|
9 set(LLVM_ENABLE_RUNTIMES ${LLVM_ALL_RUNTIMES})
|
|
10 endif()
|
|
11
|
|
12 foreach(proj ${LLVM_ENABLE_RUNTIMES})
|
|
13 set(proj_dir "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}")
|
|
14 if(IS_DIRECTORY ${proj_dir} AND EXISTS ${proj_dir}/CMakeLists.txt)
|
|
15 list(APPEND runtimes ${proj_dir})
|
|
16 else()
|
|
17 message(FATAL_ERROR "LLVM_ENABLE_RUNTIMES requests ${proj} but directory not found: ${proj_dir}")
|
|
18 endif()
|
|
19 string(TOUPPER "${proj}" canon_name)
|
|
20 STRING(REGEX REPLACE "-" "_" canon_name ${canon_name})
|
|
21 set(LLVM_EXTERNAL_${canon_name}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}")
|
|
22 endforeach()
|
|
23
|
|
24 function(runtime_register_component name)
|
|
25 set_property(GLOBAL APPEND PROPERTY SUB_COMPONENTS ${name})
|
|
26 endfunction()
|
|
27
|
|
28 find_package(LLVM PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
|
|
29 find_package(Clang PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
|
|
30
|
|
31 # Add path for custom and the LLVM build's modules to the CMake module path.
|
|
32 list(INSERT CMAKE_MODULE_PATH 0
|
|
33 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
|
34 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
|
|
35 "${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake"
|
|
36 "${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake/modules"
|
|
37 )
|
|
38
|
|
39 function(get_compiler_rt_path path)
|
|
40 foreach(entry ${runtimes})
|
|
41 get_filename_component(projName ${entry} NAME)
|
|
42 if("${projName}" MATCHES "compiler-rt")
|
|
43 set(${path} ${entry} PARENT_SCOPE)
|
|
44 return()
|
|
45 endif()
|
|
46 endforeach()
|
|
47 endfunction()
|
|
48
|
|
49 # Some of the runtimes will conditionally use the compiler-rt sanitizers
|
|
50 # to make this work smoothly we ensure that compiler-rt is added first in
|
|
51 # the list of sub-projects. This allows other sub-projects to have checks
|
|
52 # like `if(TARGET asan)` to enable building with asan.
|
|
53 get_compiler_rt_path(compiler_rt_path)
|
|
54 if(compiler_rt_path)
|
|
55 list(REMOVE_ITEM runtimes ${compiler_rt_path})
|
|
56 if(NOT DEFINED LLVM_BUILD_COMPILER_RT OR LLVM_BUILD_COMPILER_RT)
|
|
57 list(INSERT runtimes 0 ${compiler_rt_path})
|
|
58 endif()
|
|
59 endif()
|
|
60
|
|
61 # Setting these variables will allow the sub-build to put their outputs into
|
|
62 # the library and bin directories of the top-level build.
|
|
63 set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_DIR})
|
|
64 set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_TOOLS_BINARY_DIR})
|
|
65
|
|
66 # This variable makes sure that e.g. llvm-lit is found.
|
|
67 set(LLVM_MAIN_SRC_DIR ${LLVM_BUILD_MAIN_SRC_DIR})
|
|
68 set(LLVM_CMAKE_PATH ${LLVM_MAIN_SRC_DIR}/cmake/modules)
|
|
69
|
|
70 # This variable is used by individual runtimes to locate LLVM files.
|
|
71 set(LLVM_PATH ${LLVM_BUILD_MAIN_SRC_DIR})
|
|
72
|
|
73 if(APPLE)
|
|
74 set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
|
|
75 endif()
|
|
76
|
|
77 include(CheckLibraryExists)
|
|
78 include(CheckCCompilerFlag)
|
|
79
|
|
80 # Disable use of the installed C++ standard library when building runtimes. If
|
|
81 # MSVC is true, we must be using the clang-cl driver, which doesn't understand
|
|
82 # these flags.
|
|
83 if (NOT MSVC)
|
|
84 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++ -nostdlib++")
|
|
85 endif()
|
|
86
|
|
87 # Avoid checking whether the compiler is working.
|
|
88 set(LLVM_COMPILER_CHECKED ON)
|
|
89
|
|
90 # Handle common options used by all runtimes.
|
|
91 include(AddLLVM)
|
|
92 include(HandleLLVMOptions)
|
|
93
|
|
94 find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
|
95
|
|
96 # Use libtool instead of ar if you are both on an Apple host, and targeting Apple.
|
|
97 if(CMAKE_HOST_APPLE AND APPLE)
|
|
98 include(UseLibtool)
|
|
99 endif()
|
|
100
|
|
101 # This can be used to detect whether we're in the runtimes build.
|
|
102 set(LLVM_RUNTIMES_BUILD ON)
|
|
103
|
|
104 foreach(entry ${runtimes})
|
|
105 get_filename_component(projName ${entry} NAME)
|
|
106
|
|
107 # TODO: Clean this up as part of an interface standardization
|
|
108 string(REPLACE "-" "_" canon_name ${projName})
|
|
109 string(TOUPPER ${canon_name} canon_name)
|
|
110
|
|
111 # TODO: compiler-rt has to use standalone build for now. We tried to remove
|
|
112 # this in D57992 but this broke the build because compiler-rt assumes that
|
|
113 # LLVM and Clang are configured in the same build to set up dependencies. We
|
|
114 # should clean up the compiler-rt build and remove this eventually.
|
|
115 if ("${canon_name}" STREQUAL "COMPILER_RT")
|
|
116 set(${canon_name}_STANDALONE_BUILD ON)
|
|
117 endif()
|
|
118
|
|
119 if(LLVM_RUNTIMES_LIBDIR_SUBDIR)
|
|
120 set(${canon_name}_LIBDIR_SUBDIR "${LLVM_RUNTIMES_LIBDIR_SUBDIR}" CACHE STRING "" FORCE)
|
|
121 endif()
|
|
122
|
|
123 # Setting a variable to let sub-projects detect which other projects
|
|
124 # will be included under here.
|
|
125 set(HAVE_${canon_name} ON)
|
|
126 endforeach()
|
|
127
|
|
128 # We do this in two loops so that HAVE_* is set for each runtime before the
|
|
129 # other runtimes are added.
|
|
130 foreach(entry ${runtimes})
|
|
131 get_filename_component(projName ${entry} NAME)
|
|
132
|
|
133 # Between each sub-project we want to cache and clear the LIT properties
|
|
134 set_property(GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
|
|
135 set_property(GLOBAL PROPERTY LLVM_LIT_PARAMS)
|
|
136 set_property(GLOBAL PROPERTY LLVM_LIT_DEPENDS)
|
|
137 set_property(GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
|
|
138
|
|
139 add_subdirectory(${entry} ${projName})
|
|
140
|
|
141 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
|
|
142 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
|
|
143 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
|
|
144 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
|
|
145
|
|
146 list(APPEND RUNTIMES_LIT_TESTSUITES ${LLVM_LIT_TESTSUITES})
|
|
147 list(APPEND RUNTIMES_LIT_PARAMS ${LLVM_LIT_PARAMS})
|
|
148 list(APPEND RUNTIMES_LIT_DEPENDS ${LLVM_LIT_DEPENDS})
|
|
149 list(APPEND RUNTIMES_LIT_EXTRA_ARGS ${LLVM_LIT_EXTRA_ARGS})
|
|
150 endforeach()
|
|
151
|
|
152 if(LLVM_INCLUDE_TESTS)
|
|
153 # Add a global check rule now that all subdirectories have been traversed
|
|
154 # and we know the total set of lit testsuites.
|
|
155
|
|
156 add_lit_target(check-runtimes
|
|
157 "Running all regression tests"
|
|
158 ${RUNTIMES_LIT_TESTSUITES}
|
|
159 PARAMS ${RUNTIMES_LIT_PARAMS}
|
|
160 DEPENDS ${RUNTIMES_LIT_DEPENDS}
|
|
161 ARGS ${RUNTIMES_LIT_EXTRA_ARGS}
|
|
162 )
|
|
163 add_custom_target(runtimes-test-depends DEPENDS ${RUNTIMES_LIT_DEPENDS})
|
|
164 endif()
|
|
165
|
|
166 get_property(SUB_COMPONENTS GLOBAL PROPERTY SUB_COMPONENTS)
|
|
167 if(SUB_COMPONENTS)
|
|
168 list(REMOVE_DUPLICATES SUB_COMPONENTS)
|
|
169 foreach(component ${SUB_COMPONENTS})
|
|
170 if(NOT TARGET ${component})
|
|
171 message(SEND_ERROR "Missing target for runtime component ${component}!")
|
|
172 continue()
|
|
173 endif()
|
|
174
|
|
175 if(TARGET check-${component})
|
|
176 list(APPEND SUB_CHECK_TARGETS check-${component})
|
|
177 endif()
|
|
178
|
|
179 if(TARGET install-${component})
|
|
180 list(APPEND SUB_INSTALL_TARGETS install-${component})
|
|
181 endif()
|
|
182 if(TARGET install-${component}-stripped)
|
|
183 list(APPEND SUB_INSTALL_TARGETS install-${component}-stripped)
|
|
184 endif()
|
|
185 endforeach()
|
|
186
|
|
187 if(LLVM_RUNTIMES_TARGET)
|
|
188 configure_file(
|
|
189 ${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
|
|
190 ${LLVM_BINARY_DIR}/runtimes/${LLVM_RUNTIMES_TARGET}/Components.cmake)
|
|
191 else()
|
|
192 configure_file(
|
|
193 ${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
|
|
194 ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
|
|
195 endif()
|
|
196 endif()
|