[llvm] [CMake] Correctly handle LLVM_ENABLE_RUNTIMES in targets (PR #69869)
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 21 22:52:58 PDT 2023
https://github.com/petrhosek created https://github.com/llvm/llvm-project/pull/69869
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.
>From 431934b7c65718dfd1a24cb7b8263a9a1c86c191 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Sun, 22 Oct 2023 05:49:37 +0000
Subject: [PATCH] [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.
---
llvm/runtimes/CMakeLists.txt | 38 +++++++++++++++++++++++++-----------
1 file changed, 27 insertions(+), 11 deletions(-)
diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index 7ec6480773c8f05..742272a2918b4ce 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -171,12 +171,20 @@ if(compiler_rt_path)
endif()
endif()
+function(_get_runtime_name name out_var)
+ string(FIND ${name} "lib" idx)
+ if(idx EQUAL 0 AND NOT ${name} STREQUAL "libc")
+ string(SUBSTRING ${name} 3 -1 entry)
+ endif()
+ set(${out_var} ${name} PARENT_SCOPE)
+endfunction()
+
# Create a list with the names of all the runtime projects in all uppercase and
# with dashes turned to underscores. This gives us the CMake variable `prefixes`
# for all variables that will apply to runtimes.
foreach(entry ${runtimes})
- get_filename_component(projName ${entry} NAME)
- string(REPLACE "-" "_" canon_name ${projName})
+ get_filename_component(name ${entry} NAME)
+ string(REPLACE "-" "_" canon_name ${name})
string(TOUPPER ${canon_name} canon_name)
list(APPEND prefixes ${canon_name})
if (${canon_name} STREQUAL "OPENMP")
@@ -196,11 +204,8 @@ foreach(entry ${runtimes})
endif()
endif()
- string(FIND ${projName} "lib" LIB_IDX)
- if(LIB_IDX EQUAL 0 AND NOT projName STREQUAL "libc")
- string(SUBSTRING ${projName} 3 -1 projName)
- endif()
- list(APPEND runtime_names ${projName})
+ _get_runtime_name(${name} name)
+ list(APPEND RUNTIME_NAMES ${name})
endforeach()
function(runtime_default_target)
@@ -210,7 +215,7 @@ function(runtime_default_target)
set(SUB_CHECK_TARGETS ${SUB_CHECK_TARGETS} PARENT_SCOPE)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
- foreach(runtime_name ${runtime_names})
+ foreach(runtime_name ${RUNTIME_NAMES})
list(APPEND extra_targets
${runtime_name}
install-${runtime_name}
@@ -268,6 +273,17 @@ function(runtime_register_target name)
include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
+ set(runtime_names ${RUNTIME_NAMES})
+ foreach(_name IN ITEMS ${ARG_BASE_NAME} ${name})
+ if(RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)
+ set(runtime_names)
+ foreach(entry ${RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES})
+ _get_runtime_name(${entry} runtime_name)
+ list(APPEND runtime_names ${runtime_name})
+ endforeach()
+ endif()
+ endforeach()
+
foreach(runtime_name ${runtime_names})
set(${runtime_name}-${name} ${runtime_name})
set(install-${runtime_name}-${name} install-${runtime_name})
@@ -424,7 +440,7 @@ if(runtimes)
add_custom_target(runtimes-test-depends)
set(test_targets "")
endif()
- foreach(runtime_name ${runtime_names})
+ foreach(runtime_name ${RUNTIME_NAMES})
add_custom_target(${runtime_name})
add_custom_target(install-${runtime_name})
add_custom_target(install-${runtime_name}-stripped)
@@ -462,7 +478,7 @@ if(runtimes)
add_dependencies(check-runtimes check-runtimes-${name})
add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
endif()
- foreach(runtime_name ${runtime_names})
+ foreach(runtime_name ${RUNTIME_NAMES})
add_dependencies(${runtime_name} ${runtime_name}-${name})
add_dependencies(install-${runtime_name} install-${runtime_name}-${name})
add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}-stripped)
@@ -488,7 +504,7 @@ if(runtimes)
add_dependencies(runtimes-configure runtimes-${name}+${multilib}-configure)
add_dependencies(install-runtimes install-runtimes-${name}+${multilib})
add_dependencies(install-runtimes-stripped install-runtimes-${name}+${multilib}-stripped)
- foreach(runtime_name ${runtime_names})
+ foreach(runtime_name ${RUNTIME_NAMES})
add_dependencies(${runtime_name} ${runtime_name}-${name}+${multilib})
add_dependencies(install-${runtime_name} install-${runtime_name}-${name}+${multilib})
add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}+${multilib}-stripped)
More information about the llvm-commits
mailing list