[llvm] 0fc8f0b - [CMake] Correctly handle LLVM_ENABLE_RUNTIMES in targets (#69869)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 25 12:12:31 PDT 2023


Author: Petr Hosek
Date: 2023-10-25T12:12:27-07:00
New Revision: 0fc8f0be9b05bc4e123eaf6963f9b9a3f82b38b0

URL: https://github.com/llvm/llvm-project/commit/0fc8f0be9b05bc4e123eaf6963f9b9a3f82b38b0
DIFF: https://github.com/llvm/llvm-project/commit/0fc8f0be9b05bc4e123eaf6963f9b9a3f82b38b0.diff

LOG: [CMake] Correctly handle LLVM_ENABLE_RUNTIMES in targets (#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.

Added: 
    

Modified: 
    llvm/runtimes/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index 7ec6480773c8f05..4ae2bf2ef20e92d 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,25 @@ 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})
+    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()
 endfunction()
 
 if(runtimes)
@@ -424,7 +459,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 +488,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 +499,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