Skip to content

Commit 87b62dd

Browse files
committed
[CMake] Correctly handle LLVM_ENABLE_RUNTIMES in targets
When a target sets LLVM_ENABLE_RUNTIMES, we should only generate proxy targets for those runtimes rather than using the global list which may contain runtimes that are not supported by that particular target.
1 parent c7be4e6 commit 87b62dd

File tree

1 file changed

+44
-43
lines changed

1 file changed

+44
-43
lines changed

llvm/runtimes/CMakeLists.txt

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,20 @@ if(compiler_rt_path)
171171
endif()
172172
endif()
173173

174+
function(_get_runtime_name name out_var)
175+
string(FIND ${name} "lib" idx)
176+
if(idx EQUAL 0 AND NOT ${name} STREQUAL "libc")
177+
string(SUBSTRING ${name} 3 -1 entry)
178+
endif()
179+
set(${out_var} ${name} PARENT_SCOPE)
180+
endfunction()
181+
174182
# Create a list with the names of all the runtime projects in all uppercase and
175183
# with dashes turned to underscores. This gives us the CMake variable `prefixes`
176184
# for all variables that will apply to runtimes.
177185
foreach(entry ${runtimes})
178-
get_filename_component(projName ${entry} NAME)
179-
string(REPLACE "-" "_" canon_name ${projName})
186+
get_filename_component(name ${entry} NAME)
187+
string(REPLACE "-" "_" canon_name ${name})
180188
string(TOUPPER ${canon_name} canon_name)
181189
list(APPEND prefixes ${canon_name})
182190
if (${canon_name} STREQUAL "OPENMP")
@@ -196,11 +204,8 @@ foreach(entry ${runtimes})
196204
endif()
197205
endif()
198206

199-
string(FIND ${projName} "lib" LIB_IDX)
200-
if(LIB_IDX EQUAL 0 AND NOT projName STREQUAL "libc")
201-
string(SUBSTRING ${projName} 3 -1 projName)
202-
endif()
203-
list(APPEND runtime_names ${projName})
207+
_get_runtime_name(${name} name)
208+
list(APPEND RUNTIME_NAMES ${name})
204209
endforeach()
205210

206211
function(runtime_default_target)
@@ -210,7 +215,7 @@ function(runtime_default_target)
210215
set(SUB_CHECK_TARGETS ${SUB_CHECK_TARGETS} PARENT_SCOPE)
211216
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
212217

213-
foreach(runtime_name ${runtime_names})
218+
foreach(runtime_name ${RUNTIME_NAMES})
214219
list(APPEND extra_targets
215220
${runtime_name}
216221
install-${runtime_name}
@@ -268,6 +273,17 @@ function(runtime_register_target name)
268273
include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
269274
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
270275

276+
set(runtime_names ${RUNTIME_NAMES})
277+
foreach(_name IN ITEMS ${ARG_BASE_NAME} ${name})
278+
if(RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)
279+
set(runtime_names)
280+
foreach(entry ${RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES})
281+
_get_runtime_name(${entry} runtime_name)
282+
list(APPEND runtime_names ${runtime_name})
283+
endforeach()
284+
endif()
285+
endforeach()
286+
271287
foreach(runtime_name ${runtime_names})
272288
set(${runtime_name}-${name} ${runtime_name})
273289
set(install-${runtime_name}-${name} install-${runtime_name})
@@ -365,6 +381,25 @@ function(runtime_register_target name)
365381
${${name}_test_targets}
366382
USE_TOOLCHAIN
367383
${EXTRA_ARGS} ${ARG_EXTRA_ARGS})
384+
385+
add_dependencies(runtimes runtimes-${name})
386+
add_dependencies(runtimes-configure runtimes-${name}-configure)
387+
add_dependencies(install-runtimes install-runtimes-${name})
388+
add_dependencies(install-runtimes-stripped install-runtimes-${name}-stripped)
389+
if(LLVM_INCLUDE_TESTS)
390+
add_dependencies(check-runtimes check-runtimes-${name})
391+
add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
392+
endif()
393+
foreach(runtime_name ${runtime_names})
394+
add_dependencies(${runtime_name} ${runtime_name}-${name})
395+
add_dependencies(install-${runtime_name} install-${runtime_name}-${name})
396+
add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}-stripped)
397+
endforeach()
398+
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
399+
add_dependencies(${component} ${component}-${name})
400+
add_dependencies(install-${component} install-${component}-${name})
401+
add_dependencies(install-${component}-stripped install-${component}-${name}-stripped)
402+
endforeach()
368403
endfunction()
369404

370405
if(runtimes)
@@ -424,7 +459,7 @@ if(runtimes)
424459
add_custom_target(runtimes-test-depends)
425460
set(test_targets "")
426461
endif()
427-
foreach(runtime_name ${runtime_names})
462+
foreach(runtime_name ${RUNTIME_NAMES})
428463
add_custom_target(${runtime_name})
429464
add_custom_target(install-${runtime_name})
430465
add_custom_target(install-${runtime_name}-stripped)
@@ -453,25 +488,6 @@ if(runtimes)
453488
DEPENDS ${builtins_dep_name} ${libc_tools}
454489
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${libc_cmake_args}
455490
EXTRA_ARGS TARGET_TRIPLE ${name})
456-
457-
add_dependencies(runtimes runtimes-${name})
458-
add_dependencies(runtimes-configure runtimes-${name}-configure)
459-
add_dependencies(install-runtimes install-runtimes-${name})
460-
add_dependencies(install-runtimes-stripped install-runtimes-${name}-stripped)
461-
if(LLVM_INCLUDE_TESTS)
462-
add_dependencies(check-runtimes check-runtimes-${name})
463-
add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
464-
endif()
465-
foreach(runtime_name ${runtime_names})
466-
add_dependencies(${runtime_name} ${runtime_name}-${name})
467-
add_dependencies(install-${runtime_name} install-${runtime_name}-${name})
468-
add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}-stripped)
469-
endforeach()
470-
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
471-
add_dependencies(${component} ${component}-${name})
472-
add_dependencies(install-${component} install-${component}-${name})
473-
add_dependencies(install-${component}-stripped install-${component}-${name}-stripped)
474-
endforeach()
475491
endforeach()
476492

477493
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
@@ -483,21 +499,6 @@ if(runtimes)
483499
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
484500
BASE_NAME ${name}
485501
EXTRA_ARGS TARGET_TRIPLE ${name})
486-
487-
add_dependencies(runtimes runtimes-${name}+${multilib})
488-
add_dependencies(runtimes-configure runtimes-${name}+${multilib}-configure)
489-
add_dependencies(install-runtimes install-runtimes-${name}+${multilib})
490-
add_dependencies(install-runtimes-stripped install-runtimes-${name}+${multilib}-stripped)
491-
foreach(runtime_name ${runtime_names})
492-
add_dependencies(${runtime_name} ${runtime_name}-${name}+${multilib})
493-
add_dependencies(install-${runtime_name} install-${runtime_name}-${name}+${multilib})
494-
add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}+${multilib}-stripped)
495-
endforeach()
496-
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
497-
add_dependencies(${component} ${component}-${name}+${multilib})
498-
add_dependencies(install-${component} install-${component}-${name}+${multilib})
499-
add_dependencies(install-${component}-stripped install-${component}-${name}+${multilib}-stripped)
500-
endforeach()
501502
endforeach()
502503
endforeach()
503504
endif()

0 commit comments

Comments
 (0)