[llvm] [CMake] Correctly handle LLVM_ENABLE_RUNTIMES in targets (PR #69869)
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 22 19:22:21 PDT 2023
https://github.com/petrhosek updated https://github.com/llvm/llvm-project/pull/69869
>From 244b1ab1d46e880a654f9f8e399eb59c060944ee 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 | 93 +++++++++++++++++++-----------------
1 file changed, 50 insertions(+), 43 deletions(-)
diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index 7ec6480773c8f05..cc1e709ca3a9ca5 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})
@@ -365,6 +381,31 @@ function(runtime_register_target name)
${${name}_test_targets}
USE_TOOLCHAIN
${EXTRA_ARGS} ${ARG_EXTRA_ARGS})
+
+ add_dependencies(runtimes runtimes-${name})
+ add_dependencies(runtimes-configure runtimes-${name}-configure)
+ add_dependencies(install-runtimes install-runtimes-${name})
+ add_dependencies(install-runtimes-stripped install-runtimes-${name}-stripped)
+ if(LLVM_INCLUDE_TESTS)
+ add_dependencies(check-runtimes check-runtimes-${name})
+ add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
+ endif()
+ foreach(runtime_name ${runtime_names})
+ if(TARGET ${runtime_name})
+ add_dependencies(${runtime_name} ${runtime_name}-${name})
+ endif()
+ if(TARGET install-${runtime_name})
+ add_dependencies(install-${runtime_name} install-${runtime_name}-${name})
+ endif()
+ if(TARGET install-${runtime_name}-stripped)
+ add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}-stripped)
+ endif()
+ endforeach()
+ foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
+ add_dependencies(${component} ${component}-${name})
+ add_dependencies(install-${component} install-${component}-${name})
+ add_dependencies(install-${component}-stripped install-${component}-${name}-stripped)
+ endforeach()
endfunction()
if(runtimes)
@@ -424,7 +465,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)
@@ -453,25 +494,6 @@ if(runtimes)
DEPENDS ${builtins_dep_name} ${libc_tools}
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${libc_cmake_args}
EXTRA_ARGS TARGET_TRIPLE ${name})
-
- add_dependencies(runtimes runtimes-${name})
- add_dependencies(runtimes-configure runtimes-${name}-configure)
- add_dependencies(install-runtimes install-runtimes-${name})
- add_dependencies(install-runtimes-stripped install-runtimes-${name}-stripped)
- if(LLVM_INCLUDE_TESTS)
- add_dependencies(check-runtimes check-runtimes-${name})
- add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
- endif()
- 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)
- endforeach()
- foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
- add_dependencies(${component} ${component}-${name})
- add_dependencies(install-${component} install-${component}-${name})
- add_dependencies(install-${component}-stripped install-${component}-${name}-stripped)
- endforeach()
endforeach()
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
@@ -483,21 +505,6 @@ if(runtimes)
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
BASE_NAME ${name}
EXTRA_ARGS TARGET_TRIPLE ${name})
-
- add_dependencies(runtimes runtimes-${name}+${multilib})
- 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})
- 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)
- endforeach()
- foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
- add_dependencies(${component} ${component}-${name}+${multilib})
- add_dependencies(install-${component} install-${component}-${name}+${multilib})
- add_dependencies(install-${component}-stripped install-${component}-${name}+${multilib}-stripped)
- endforeach()
endforeach()
endforeach()
endif()
More information about the llvm-commits
mailing list