llvm.org GIT mirror llvm / 39247cb
[CMake] Support multi-target runtimes build This changes adds support for building runtimes for multiple different targets using LLVM runtimes directory. The implementation follow the model used already by the builtins build which already supports this option. To specify the runtimes targets to be built, use the LLVM_RUNTIME_TARGETS variable, where the valuae is the list of targets to build runtimes for. To pass a per target variable to the runtimes build, you can set RUNTIMES_<target>_<variable> where <variable> will be passed to the runtimes build for <target>. Each runtime target (except for the default one) will be installed into lib/<target> subdirectory. Build targets will be suffixed with the target name. Differential Revision: https://reviews.llvm.org/D32816 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307731 91177308-0d34-0410-b5e6-96231b3b80d8 Petr Hosek 2 years ago
3 changed file(s) with 169 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
194194
195195 # Add top-level targets
196196 foreach(target ${ARG_EXTRA_TARGETS})
197 string(REPLACE ":" ";" target_list ${target})
198 list(GET target_list 0 target)
199 list(LENGTH target_list target_list_len)
200 if(${target_list_len} GREATER 1)
201 list(GET target_list 1 target_name)
202 else()
203 set(target_name "${target}")
204 endif()
197205 llvm_ExternalProject_BuildCmd(build_runtime_cmd ${target} ${BINARY_DIR})
198 add_custom_target(${target}
206 add_custom_target(${target_name}
199207 COMMAND ${build_runtime_cmd}
200208 DEPENDS ${name}-configure
201209 WORKING_DIRECTORY ${BINARY_DIR}
6161 set(LLVM_MAIN_SRC_DIR ${LLVM_BUILD_MAIN_SRC_DIR})
6262
6363 if(APPLE)
64 set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
64 set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
6565 endif()
6666
6767 set(SAFE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
9595 # The subdirectories need to treat this as standalone builds
9696 set(${canon_name}_STANDALONE_BUILD On)
9797
98 if(LLVM_RUNTIMES_TARGET)
99 if(NOT "${entry}" MATCHES "compiler-rt")
100 set(${canon_name}_INSTALL_PREFIX "lib/${LLVM_RUNTIMES_TARGET}/" CACHE STRING "" FORCE)
101 endif()
102 endif()
103
98104 # Setting a variable to let sub-projects detect which other projects
99105 # will be included under here.
100106 set(HAVE_${canon_name} On)
101107 endforeach()
102108
109 set(SAFE_LLVM_BINARY_DIR ${LLVM_BINARY_DIR})
110 set(SAFE_LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
111 set(SAFE_LLVM_RUNTIMES_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
112
103113 # We do this in two loops so that HAVE_* is set for each runtime before the
104114 # other runtimes are added.
105115 foreach(entry ${runtimes})
106116 get_filename_component(projName ${entry} NAME)
117
118 if(LLVM_RUNTIMES_TARGET)
119 if(NOT "${entry}" MATCHES "compiler-rt")
120 set(LLVM_BINARY_DIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_TARGET}")
121 set(LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_TARGET}/lib")
122 set(LLVM_RUNTIME_OUTPUT_INTDIR "${LLVM_TOOLS_BINARY_DIR}/${LLVM_RUNTIMES_TARGET}")
123 endif()
124 endif()
107125
108126 # Between each sub-project we want to cache and clear the LIT properties
109127 set_property(GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
122140 list(APPEND RUNTIMES_LIT_PARAMS ${LLVM_LIT_PARAMS})
123141 list(APPEND RUNTIMES_LIT_DEPENDS ${LLVM_LIT_DEPENDS})
124142 list(APPEND RUNTIMES_LIT_EXTRA_ARGS ${LLVM_LIT_EXTRA_ARGS})
143
144 if(LLVM_RUNTIMES_TARGET)
145 if(NOT "${entry}" MATCHES "compiler-rt")
146 set(LLVM_BINARY_DIR "${SAFE_LLVM_BINARY_DIR}")
147 set(LLVM_LIBRARY_OUTPUT_INTDIR "${SAFE_LLVM_LIBRARY_OUTPUT_INTDIR}")
148 set(LLVM_RUNTIME_OUTPUT_INTDIR "${SAFE_LLVM_RUNTIME_OUTPUT_INTDIR}")
149 endif()
150 endif()
125151 endforeach()
126152
127153 if(LLVM_INCLUDE_TESTS)
146172 message(SEND_ERROR "Missing target for runtime component ${component}!")
147173 continue()
148174 endif()
149 if(LLVM_INCLUDE_TESTS AND NOT TARGET check-${component})
150 message(SEND_ERROR "Missing check target for runtime component ${component}!")
151 continue()
175
176 if(TARGET check-${component})
177 list(APPEND SUB_CHECK_TARGETS check-${component})
152178 endif()
153179
154180 if(TARGET install-${component})
156182 endif()
157183 endforeach()
158184
159 configure_file(
160 ${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
161 ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
185 if(LLVM_RUNTIMES_TARGET)
186 configure_file(
187 ${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
188 ${LLVM_BINARY_DIR}/runtimes/${LLVM_RUNTIMES_TARGET}/Components.cmake)
189 else()
190 configure_file(
191 ${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
192 ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
193 endif()
162194 endif()
163195
164196 else() # if this is included from LLVM's CMake
165 include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
166 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
167197 include(LLVMExternalProjectUtils)
168198
169199 if(NOT LLVM_BUILD_RUNTIMES)
189219 add_custom_target(builtins)
190220 add_custom_target(install-builtins)
191221 foreach(target ${LLVM_BUILTIN_TARGETS})
222 if(target STREQUAL "default")
223 set(target ${LLVM_DEFAULT_TARGET_TRIPLE})
224 endif()
225
192226 string(REPLACE "-" ";" builtin_target_list ${target})
193227 foreach(item ${builtin_target_list})
194228 string(TOLOWER "${item}" item_lower)
245279 list(APPEND runtime_names ${projName})
246280 endforeach()
247281
248 if(runtimes)
282 # runtime_register_target(target)
283 # Utility function to register external runtime target.
284 function(runtime_register_target target)
285 if(target STREQUAL LLVM_DEFAULT_TARGET_TRIPLE)
286 include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
287 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
288 else()
289 include(${LLVM_BINARY_DIR}/runtimes/${target}/Components.cmake OPTIONAL)
290 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${target}/Components.cmake)
291 endif()
249292
250293 foreach(runtime_name ${runtime_names})
251 list(APPEND extra_targets
252 ${runtime_name}
253 install-${runtime_name})
294 list(APPEND ${target}_extra_targets
295 ${runtime_name}-${target}
296 install-${runtime_name}-${target})
254297 if(LLVM_INCLUDE_TESTS)
255 list(APPEND test_targets check-${runtime_name})
298 list(APPEND ${target}_test_targets check-${runtime_name}-${target})
256299 endif()
257300 endforeach()
258301
302 foreach(name IN LISTS SUB_COMPONENTS SUB_INSTALL_TARGETS)
303 list(APPEND ${target}_extra_targets "${name}:${name}-${target}")
304 endforeach()
305
259306 if(LLVM_INCLUDE_TESTS)
260 list(APPEND test_targets runtimes-test-depends check-runtimes)
261 foreach(component ${SUB_COMPONENTS})
262 list(APPEND SUB_COMPONENT_CHECK_TARGETS check-${component})
307 list(APPEND ${target}_test_targets runtimes-test-depends-${target} check-runtimes-${target})
308 foreach(name IN LISTS SUB_CHECK_TARGETS)
309 list(APPEND ${target}_test_targets "${name}:${name}-${target}")
310 list(APPEND test_targets ${name}-${target})
263311 endforeach()
264 endif()
265
266 # Create a runtimes target that uses this file as its top-level CMake file.
267 # The runtimes target is a configuration of all the runtime libraries
268 # together in a single CMake invocaiton.
269 llvm_ExternalProject_Add(runtimes
312 set(test_targets "${test_targets}" PARENT_SCOPE)
313 endif()
314
315 get_cmake_property(variableNames VARIABLES)
316 foreach(variableName ${variableNames})
317 if(variableName MATCHES "^RUNTIMES_${target}")
318 string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName})
319 list(APPEND ${target}_extra_args "-D${new_name}=${${variableName}}")
320 endif()
321 endforeach()
322
323 if(NOT target STREQUAL LLVM_DEFAULT_TARGET_TRIPLE)
324 list(APPEND ${target}_extra_args "-DLLVM_RUNTIMES_TARGET=${target}")
325 endif()
326
327 llvm_ExternalProject_Add(runtimes-${target}
270328 ${CMAKE_CURRENT_SOURCE_DIR}
271329 DEPENDS ${deps}
272330 # Builtins were built separately above
273331 CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
274332 -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
333 -DCMAKE_C_COMPILER_TARGET=${target}
334 -DCMAKE_CXX_COMPILER_TARGET=${target}
335 -DCMAKE_ASM_COMPILER_TARGET=${target}
336 -DCMAKE_C_COMPILER_WORKS=ON
337 -DCMAKE_CXX_COMPILER_WORKS=ON
338 -DCMAKE_ASM_COMPILER_WORKS=ON
339 -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
340 ${${target}_extra_args}
275341 PASSTHROUGH_PREFIXES ${prefixes}
276 EXTRA_TARGETS ${extra_targets}
277 ${test_targets}
278 ${SUB_COMPONENTS}
279 ${SUB_COMPONENT_CHECK_TARGETS}
280 ${SUB_INSTALL_TARGETS}
342 EXTRA_TARGETS ${${target}_extra_targets}
343 ${${target}_test_targets}
281344 USE_TOOLCHAIN
282345 ${EXTRA_ARGS})
283
346 endfunction()
347
348 if(runtimes)
349 # Create a runtimes target that uses this file as its top-level CMake file.
350 # The runtimes target is a configuration of all the runtime libraries
351 # together in a single CMake invocaiton.
352 if(NOT LLVM_RUNTIME_TARGETS)
353 include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
354 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
355
356 foreach(runtime_name ${runtime_names})
357 list(APPEND extra_targets
358 ${runtime_name}
359 install-${runtime_name})
360 if(LLVM_INCLUDE_TESTS)
361 list(APPEND test_targets check-${runtime_name})
362 endif()
363 endforeach()
364
365 if(LLVM_INCLUDE_TESTS)
366 list(APPEND test_targets runtimes-test-depends check-runtimes)
367 foreach(component ${SUB_COMPONENTS})
368 list(APPEND SUB_CHECK_TARGETS check-${component})
369 endforeach()
370 endif()
371
372 llvm_ExternalProject_Add(runtimes
373 ${CMAKE_CURRENT_SOURCE_DIR}
374 DEPENDS ${deps}
375 # Builtins were built separately above
376 CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
377 -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
378 PASSTHROUGH_PREFIXES ${prefixes}
379 EXTRA_TARGETS ${extra_targets}
380 ${test_targets}
381 ${SUB_COMPONENTS}
382 ${SUB_CHECK_TARGETS}
383 ${SUB_INSTALL_TARGETS}
384 USE_TOOLCHAIN
385 ${EXTRA_ARGS})
386 else()
387 add_custom_target(runtimes)
388 add_custom_target(runtimes-configure)
389 add_custom_target(install-runtimes)
390 if(LLVM_INCLUDE_TESTS)
391 add_custom_target(check-runtimes)
392 add_custom_target(runtimes-test-depends)
393 set(test_targets "")
394 endif()
395
396 foreach(target ${LLVM_RUNTIME_TARGETS})
397 if(target STREQUAL "default")
398 set(target ${LLVM_DEFAULT_TARGET_TRIPLE})
399 endif()
400
401 runtime_register_target(${target})
402
403 add_dependencies(runtimes runtimes-${target})
404 add_dependencies(runtimes-configure runtimes-${target}-configure)
405 add_dependencies(install-runtimes install-runtimes-${target})
406 if(LLVM_INCLUDE_TESTS)
407 add_dependencies(check-runtimes check-runtimes-${target})
408 add_dependencies(runtimes-test-depends runtimes-test-depends-${target})
409 endif()
410 endforeach()
411 endif()
412
284413 # TODO: This is a hack needed because the libcxx headers are copied into the
285414 # build directory during configuration. Without that step the clang in the
286415 # build directory cannot find the C++ headers in certain configurations.
305434 sancov
306435 sanstats
307436 )
308 foreach(target ${test_targets} ${SUB_COMPONENT_CHECK_TARGETS})
437 foreach(target ${test_targets} ${SUB_CHECK_TARGETS})
309438 add_dependencies(${target} ${RUNTIMES_TEST_DEPENDS})
310439 endforeach()
311440 endif()
0 set(SUB_COMPONENTS @SUB_COMPONENTS@)
1 set(SUB_CHECK_TARGETS @SUB_CHECK_TARGETS@)
12 set(SUB_INSTALL_TARGETS @SUB_INSTALL_TARGETS@)