llvm.org GIT mirror llvm / 567f85d
[CMake][runtimes] Support monorepo layout with runtimes build We introduce a new variable LLVM_ENABLE_RUNTIMES which works similarly to LLVM_ENABLE_PROJECTS and allows specifying runtimes that will be enabled in the runtimes build. Differential Revision: https://reviews.llvm.org/D40233 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319107 91177308-0d34-0410-b5e6-96231b3b80d8 Petr Hosek 2 years ago
1 changed file(s) with 46 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
1313 list(APPEND runtimes ${entry})
1414 endif()
1515 endforeach()
16
17 # Side-by-side subprojects layout.
18 set(LLVM_ALL_RUNTIMES "libcxx;libcxxabi;libunwind;compiler-rt")
19 set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
20 "Semicolon-separated list of runtimes to build (${LLVM_ALL_RUNTIMES}), or \"all\".")
21 if(LLVM_ENABLE_RUNTIMES STREQUAL "all" )
22 set(LLVM_ENABLE_RUNTIMES ${LLVM_ALL_RUNTIMES})
23 endif()
24 foreach(proj ${LLVM_ENABLE_RUNTIMES})
25 set(proj_dir "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
26 if(IS_DIRECTORY ${proj_dir} AND EXISTS ${proj_dir}/CMakeLists.txt)
27 list(APPEND runtimes ${proj_dir})
28 else()
29 message(FATAL_ERROR "LLVM_ENABLE_RUNTIMES requests ${proj} but directory not found: ${proj_dir}")
30 endif()
31 string(TOUPPER "${proj}" canon_name)
32 STRING(REGEX REPLACE "-" "_" canon_name ${canon_name})
33 set(LLVM_EXTERNAL_${canon_name}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
34 endforeach()
35
36 function(get_compiler_rt_path path)
37 foreach(entry ${runtimes})
38 get_filename_component(projName ${entry} NAME)
39 if("${projName}" MATCHES "compiler-rt")
40 set(${path} ${entry} PARENT_SCOPE)
41 return()
42 endif()
43 endforeach()
44 endfunction()
1645
1746 # If this file is acting as a top-level CMake invocation, this code path is
1847 # triggered by the external project call for the runtimes target below.
3766 # to make this work smoothly we ensure that compiler-rt is added first in
3867 # the list of sub-projects. This allows other sub-projects to have checks
3968 # like `if(TARGET asan)` to enable building with asan.
40 foreach(entry ${runtimes})
41 if("${entry}" MATCHES "compiler-rt")
42 set(compiler_rt_path ${entry})
43 break()
44 endif()
45 endforeach()
69 get_compiler_rt_path(compiler_rt_path)
4670 if(compiler_rt_path)
4771 list(REMOVE_ITEM runtimes ${compiler_rt_path})
4872 if(NOT LLVM_BUILD_COMPILER_RT)
99123 set(${canon_name}_STANDALONE_BUILD On)
100124
101125 if(LLVM_RUNTIMES_TARGET)
102 if(NOT "${entry}" MATCHES "compiler-rt")
126 if(NOT "${projName}" MATCHES "compiler-rt")
103127 set(${canon_name}_INSTALL_PREFIX "lib/${LLVM_RUNTIMES_PREFIX}/" CACHE STRING "" FORCE)
104128 endif()
105129 endif()
119143 get_filename_component(projName ${entry} NAME)
120144
121145 if(LLVM_RUNTIMES_TARGET)
122 if(NOT "${entry}" MATCHES "compiler-rt")
146 if(NOT "${projName}" MATCHES "compiler-rt")
123147 set(LLVM_BINARY_DIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_PREFIX}")
124148 set(LLVM_LIBDIR_SUFFIX "${LLVM_RUNTIMES_LIBDIR_SUFFIX}")
125149 set(LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_PREFIX}lib${LLVM_RUNTIMES_LIBDIR_SUFFIX}")
133157 set_property(GLOBAL PROPERTY LLVM_LIT_DEPENDS)
134158 set_property(GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
135159
136 add_subdirectory(${projName})
160 add_subdirectory(${entry} ${projName})
137161
138162 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
139163 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
146170 list(APPEND RUNTIMES_LIT_EXTRA_ARGS ${LLVM_LIT_EXTRA_ARGS})
147171
148172 if(LLVM_RUNTIMES_TARGET)
149 if(NOT "${entry}" MATCHES "compiler-rt")
173 if(NOT "${projName}" MATCHES "compiler-rt")
150174 set(LLVM_BINARY_DIR "${SAFE_LLVM_BINARY_DIR}")
151175 set(LLVM_LIBRARY_OUTPUT_INTDIR "${SAFE_LLVM_LIBRARY_OUTPUT_INTDIR}")
152176 set(LLVM_RUNTIME_OUTPUT_INTDIR "${SAFE_LLVM_RUNTIME_OUTPUT_INTDIR}")
204228 set(EXTRA_ARGS EXCLUDE_FROM_ALL)
205229 endif()
206230
207 function(builtin_default_target)
231 function(builtin_default_target compiler_rt_path)
208232 llvm_ExternalProject_Add(builtins
209 ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt/lib/builtins
233 ${compiler_rt_path}/lib/builtins
210234 CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
211235 -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
212236 -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
218242 ${EXTRA_ARGS})
219243 endfunction()
220244
221 function(builtin_register_target target)
245 function(builtin_register_target compiler_rt_path target)
222246 string(REPLACE "-" ";" builtin_target_list ${target})
223247 foreach(item ${builtin_target_list})
224248 string(TOLOWER "${item}" item_lower)
236260 endforeach()
237261
238262 llvm_ExternalProject_Add(builtins-${target}
239 ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt/lib/builtins
263 ${compiler_rt_path}/lib/builtins
240264 CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
241265 -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
242266 -DCMAKE_C_COMPILER_TARGET=${target}
253277 # If compiler-rt is present we need to build the builtin libraries first. This
254278 # is required because the other runtimes need the builtin libraries present
255279 # before the just-built compiler can pass the configuration tests.
256 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt)
280 get_compiler_rt_path(compiler_rt_path)
281 if(compiler_rt_path)
257282 if(NOT LLVM_BUILTIN_TARGETS)
258 builtin_default_target()
283 builtin_default_target(${compiler_rt_path})
259284 else()
260285 if("default" IN_LIST LLVM_BUILTIN_TARGETS)
261 builtin_default_target()
286 builtin_default_target(${compiler_rt_path})
262287 list(REMOVE_ITEM LLVM_BUILTIN_TARGETS "default")
263288 else()
264289 add_custom_target(builtins)
266291 endif()
267292
268293 foreach(target ${LLVM_BUILTIN_TARGETS})
269 builtin_register_target(${target})
294 builtin_register_target(${compiler_rt_path} ${target})
270295
271296 add_dependencies(builtins builtins-${target})
272297 add_dependencies(install-builtins install-builtins-${target})
325350 -DCMAKE_C_COMPILER_WORKS=ON
326351 -DCMAKE_CXX_COMPILER_WORKS=ON
327352 -DCMAKE_ASM_COMPILER_WORKS=ON
328 PASSTHROUGH_PREFIXES ${ARG_PREFIXES}
353 PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
354 ${ARG_PREFIXES}
329355 EXTRA_TARGETS ${extra_targets}
330356 ${test_targets}
331357 ${SUB_COMPONENTS}
398424 -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
399425 -DLLVM_RUNTIMES_TARGET=${name}
400426 ${${name}_extra_args}
427 PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
401428 TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib
402429 EXTRA_TARGETS ${${name}_extra_targets}
403430 ${${name}_test_targets}