[llvm] [cmake][llvm] Limit the number of Xcode schemes created by default (PR #101243)

Jon Roelofs via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 30 14:41:41 PDT 2024


https://github.com/jroelofs updated https://github.com/llvm/llvm-project/pull/101243

>From 61371af08b82e1229c34b43f56772813c2f74b1c Mon Sep 17 00:00:00 2001
From: Jon Roelofs <jonathan_roelofs at apple.com>
Date: Tue, 30 Jul 2024 13:56:21 -0700
Subject: [PATCH 1/2] [cmake][llvm] Limit the number of Xcode schemes created
 by default

CMake -GXcode would otherwise offer to create one scheme for each target, which
ends up being a lot. For t push --forcenow, limit the default to the `check-*` LIT targets,
plus `ALL_BUILD` and `install`.
---
 cmake/Modules/Xcode.cmake        | 24 ++++++++++++++++++++++++
 llvm/CMakeLists.txt              |  4 ++++
 llvm/cmake/modules/AddLLVM.cmake |  1 +
 3 files changed, 29 insertions(+)
 create mode 100644 cmake/Modules/Xcode.cmake

diff --git a/cmake/Modules/Xcode.cmake b/cmake/Modules/Xcode.cmake
new file mode 100644
index 0000000000000..466cf79eb8b00
--- /dev/null
+++ b/cmake/Modules/Xcode.cmake
@@ -0,0 +1,24 @@
+# When this is enabled, CMake will generate schemes for every target, but not
+# all of them make sense to surface in the Xcode UI by default.
+set(CMAKE_XCODE_GENERATE_SCHEME YES)
+
+# Enumerate all the targets in a directory.
+macro(get_all_targets targets dir)
+  get_property(sub_dirs DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
+  foreach(subdir ${sub_dirs})
+    get_all_targets(${targets} ${subdir})
+  endforeach()
+  get_property(local_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
+  list(APPEND ${targets} ${local_targets})
+endmacro()
+
+get_all_targets(all_targets ${PROJECT_SOURCE_DIR})
+
+# Turn off scheme generation by default for targets that do not have
+# XCODE_GENERATE_SCHEME set.
+foreach(target ${all_targets})
+  get_target_property(value ${target} XCODE_GENERATE_SCHEME)
+  if("${value}" STREQUAL "value-NOTFOUND")
+    set_target_properties(${target} PROPERTIES XCODE_GENERATE_SCHEME NO)
+  endif()
+endforeach()
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 12618966c4adf..501b9ea288053 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -1423,3 +1423,7 @@ endif()
 if (LLVM_INCLUDE_UTILS AND LLVM_INCLUDE_TOOLS)
   add_subdirectory(utils/llvm-locstats)
 endif()
+
+if (XCODE)
+  include(Xcode)
+endif()
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 03f4e1f190fd9..f4f71b35ffa70 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -2043,6 +2043,7 @@ function(add_lit_target target comment)
 
   # Tests should be excluded from "Build Solution".
   set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON)
+  set_target_properties(${target} PROPERTIES XCODE_GENERATE_SCHEME ON)
 endfunction()
 
 # Convert a target name like check-clang to a variable name like CLANG.

>From 9b294dcb88c5aeb377454338773fabbaf58e41d6 Mon Sep 17 00:00:00 2001
From: Jon Roelofs <jonathan_roelofs at apple.com>
Date: Tue, 30 Jul 2024 14:36:56 -0700
Subject: [PATCH 2/2] take Jonas' suggestion

---
 cmake/Modules/Xcode.cmake | 24 ------------------------
 llvm/CMakeLists.txt       |  4 ----
 2 files changed, 28 deletions(-)
 delete mode 100644 cmake/Modules/Xcode.cmake

diff --git a/cmake/Modules/Xcode.cmake b/cmake/Modules/Xcode.cmake
deleted file mode 100644
index 466cf79eb8b00..0000000000000
--- a/cmake/Modules/Xcode.cmake
+++ /dev/null
@@ -1,24 +0,0 @@
-# When this is enabled, CMake will generate schemes for every target, but not
-# all of them make sense to surface in the Xcode UI by default.
-set(CMAKE_XCODE_GENERATE_SCHEME YES)
-
-# Enumerate all the targets in a directory.
-macro(get_all_targets targets dir)
-  get_property(sub_dirs DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
-  foreach(subdir ${sub_dirs})
-    get_all_targets(${targets} ${subdir})
-  endforeach()
-  get_property(local_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
-  list(APPEND ${targets} ${local_targets})
-endmacro()
-
-get_all_targets(all_targets ${PROJECT_SOURCE_DIR})
-
-# Turn off scheme generation by default for targets that do not have
-# XCODE_GENERATE_SCHEME set.
-foreach(target ${all_targets})
-  get_target_property(value ${target} XCODE_GENERATE_SCHEME)
-  if("${value}" STREQUAL "value-NOTFOUND")
-    set_target_properties(${target} PROPERTIES XCODE_GENERATE_SCHEME NO)
-  endif()
-endforeach()
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 501b9ea288053..12618966c4adf 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -1423,7 +1423,3 @@ endif()
 if (LLVM_INCLUDE_UTILS AND LLVM_INCLUDE_TOOLS)
   add_subdirectory(utils/llvm-locstats)
 endif()
-
-if (XCODE)
-  include(Xcode)
-endif()



More information about the llvm-commits mailing list