[llvm] [llvm][CMake] Introduce LLVM_RUNTIME_<project>_BUILD in CMake (PR #88934)

Michael Klemm via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 22 13:12:10 PDT 2024


https://github.com/mjklemm updated https://github.com/llvm/llvm-project/pull/88934

>From 4f53ec79994aa25db12ad4bc7f1becbc32f6e047 Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Tue, 16 Apr 2024 11:45:59 -0500
Subject: [PATCH 1/3] Add CMake code to set LLVM_RUNTIME_xxxx_ENABLED

---
 llvm/CMakeLists.txt | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index d511376e18ba5e..e33514c4cd0d7f 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -253,6 +253,35 @@ if (LLVM_ENABLE_PROJECTS_USED OR NOT LLVM_ENABLE_PROJECTS STREQUAL "")
 endif()
 unset(SHOULD_ENABLE_PROJECT)
 
+# Set LLVM_RUNTIME_<project>_BUILD variables if a sub-project is enabled to be built as
+# a runtime.
+foreach(proj ${LLVM_SUPPORTED_RUNTIMES})
+  set(SHOULD_ENABLE_PROJECT FALSE)
+  string(TOUPPER "${proj}" upper_proj)
+  string(REGEX REPLACE "-" "_" upper_proj ${upper_proj})
+  if ("${proj}" IN_LIST LLVM_ENABLE_RUNTIMES)
+    message(STATUS "${proj} runtime is enabled")
+    set(SHOULD_ENABLE_PROJECT TRUE)
+    set(PROJ_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}")
+    if(NOT EXISTS "${PROJ_DIR}" OR NOT IS_DIRECTORY "${PROJ_DIR}")
+      message(FATAL_ERROR "LLVM_ENABLE_RUNTIMES requests ${proj} but directory not found: ${PROJ_DIR}")
+    endif()
+    if(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR STREQUAL "" )
+      set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}" CACHE PATH "" FORCE)
+    else()
+      set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}" CACHE PATH "")
+    endif()
+  else()
+    message(STATUS "${proj} runtime is disabled")
+    set(SHOULD_ENABLE_PROJECT FALSE)
+  endif()
+  set(LLVM_RUNTIME_${upper_proj}_BUILD
+      ${SHOULD_ENABLE_PROJECT}
+      CACHE
+      BOOL "Whether to build runtime ${upper_proj} as part of LLVM" FORCE)
+endforeach()
+unset(SHOULD_ENABLE_PROJECT)
+
 # Build llvm with ccache if the package is present
 set(LLVM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")
 if(LLVM_CCACHE_BUILD)

>From 175d6e1b882a21db1d2189e761b57c50c141cbea Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Wed, 17 Apr 2024 07:27:37 -0500
Subject: [PATCH 2/3] Be a bit clearer that LLVM_RUNTIME_<project>_BUILD
 shouldn't be directly used

---
 llvm/CMakeLists.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index e33514c4cd0d7f..0876bbf11bd516 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -254,7 +254,8 @@ endif()
 unset(SHOULD_ENABLE_PROJECT)
 
 # Set LLVM_RUNTIME_<project>_BUILD variables if a sub-project is enabled to be built as
-# a runtime.
+# a runtime.  As with LLVM_TOOL_<project>_BUILD, the LLVM_RUNTIME_<project>_BUILD variables
+# should be not directly used from the CMake configuration command line.
 foreach(proj ${LLVM_SUPPORTED_RUNTIMES})
   set(SHOULD_ENABLE_PROJECT FALSE)
   string(TOUPPER "${proj}" upper_proj)

>From c415ad502591befc6c68da6389f7b269e2bc70cc Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Mon, 22 Apr 2024 22:11:56 +0200
Subject: [PATCH 3/3] Move CMake code to the right place

Thanks to @petrhosek for the suggestion!
---
 llvm/CMakeLists.txt          | 30 ------------------------------
 llvm/runtimes/CMakeLists.txt | 30 ++++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 0876bbf11bd516..d511376e18ba5e 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -253,36 +253,6 @@ if (LLVM_ENABLE_PROJECTS_USED OR NOT LLVM_ENABLE_PROJECTS STREQUAL "")
 endif()
 unset(SHOULD_ENABLE_PROJECT)
 
-# Set LLVM_RUNTIME_<project>_BUILD variables if a sub-project is enabled to be built as
-# a runtime.  As with LLVM_TOOL_<project>_BUILD, the LLVM_RUNTIME_<project>_BUILD variables
-# should be not directly used from the CMake configuration command line.
-foreach(proj ${LLVM_SUPPORTED_RUNTIMES})
-  set(SHOULD_ENABLE_PROJECT FALSE)
-  string(TOUPPER "${proj}" upper_proj)
-  string(REGEX REPLACE "-" "_" upper_proj ${upper_proj})
-  if ("${proj}" IN_LIST LLVM_ENABLE_RUNTIMES)
-    message(STATUS "${proj} runtime is enabled")
-    set(SHOULD_ENABLE_PROJECT TRUE)
-    set(PROJ_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}")
-    if(NOT EXISTS "${PROJ_DIR}" OR NOT IS_DIRECTORY "${PROJ_DIR}")
-      message(FATAL_ERROR "LLVM_ENABLE_RUNTIMES requests ${proj} but directory not found: ${PROJ_DIR}")
-    endif()
-    if(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR STREQUAL "" )
-      set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}" CACHE PATH "" FORCE)
-    else()
-      set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}" CACHE PATH "")
-    endif()
-  else()
-    message(STATUS "${proj} runtime is disabled")
-    set(SHOULD_ENABLE_PROJECT FALSE)
-  endif()
-  set(LLVM_RUNTIME_${upper_proj}_BUILD
-      ${SHOULD_ENABLE_PROJECT}
-      CACHE
-      BOOL "Whether to build runtime ${upper_proj} as part of LLVM" FORCE)
-endforeach()
-unset(SHOULD_ENABLE_PROJECT)
-
 # Build llvm with ccache if the package is present
 set(LLVM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")
 if(LLVM_CCACHE_BUILD)
diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index 8159d7f8a0a104..b95f9a2ff9e478 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -208,6 +208,36 @@ foreach(entry ${runtimes})
   list(APPEND RUNTIME_NAMES ${name})
 endforeach()
 
+# Set LLVM_RUNTIME_<project>_BUILD variables if a sub-project is enabled to be built as
+# a runtime.  As with LLVM_TOOL_<project>_BUILD, the LLVM_RUNTIME_<project>_BUILD variables
+# should be not directly used from the CMake configuration command line.
+foreach(proj ${LLVM_SUPPORTED_RUNTIMES})
+  set(SHOULD_ENABLE_RUNTIME FALSE)
+  string(TOUPPER "${proj}" upper_proj)
+  string(REGEX REPLACE "-" "_" upper_proj ${upper_proj})
+  if ("${proj}" IN_LIST LLVM_ENABLE_RUNTIMES)
+    message(STATUS "${proj} runtime is enabled")
+    set(SHOULD_ENABLE_RUNTIME TRUE)
+    set(PROJ_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
+    if(NOT EXISTS "${PROJ_DIR}" OR NOT IS_DIRECTORY "${PROJ_DIR}")
+      message(FATAL_ERROR "LLVM_ENABLE_RUNTIMES requests ${proj} but directory not found: ${PROJ_DIR}")
+    endif()
+    if(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR STREQUAL "" )
+      set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}" CACHE PATH "" FORCE)
+    else()
+      set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}" CACHE PATH "")
+    endif()
+  else()
+    message(STATUS "${proj} runtime is disabled")
+    set(SHOULD_ENABLE_RUNTIME FALSE)
+  endif()
+  set(LLVM_RUNTIME_${upper_proj}_BUILD
+      ${SHOULD_ENABLE_RUNTIME}
+      CACHE
+      BOOL "Whether to build runtime ${upper_proj} as part of LLVM" FORCE)
+endforeach()
+unset(SHOULD_ENABLE_RUNTIME)
+
 function(runtime_default_target)
   cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;PREFIXES" ${ARGN})
 



More information about the llvm-commits mailing list