Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Jul 31, 2024

Conversation

jroelofs
Copy link
Contributor

@jroelofs jroelofs commented Jul 30, 2024

CMake -GXcode would otherwise offer to create one scheme for each target, which ends up being a lot. For now, limit the default to the check-* LIT targets, plus ALL_BUILD and install.

For targets that aren't in the default list, we now have a configuration variable to promote an extra list of targets into schemes, for example -DLLVM_XCODE_EXTRA_TARGET_SCHEMES="TargetParserTests;SupportTests" to add schemes for TargetParserTests and SupportTests respectively.

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`.
@llvmbot llvmbot added the cmake Build system in general and CMake in particular label Jul 30, 2024
@JDevlieghere
Copy link
Member

+1 on reducing the number of schemes. Thanks for doing this!

I wonder if we could achieve the same result, without iterating over all the targets, by setting CMAKE_XCODE_GENERATE_SCHEME to OFF and then explicitly turning it on in llvm_add_tool and add_lit_target (like you did here).

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jul 30, 2024
@JDevlieghere
Copy link
Member

JDevlieghere commented Jul 30, 2024

Nice. An added benefit of doing it this way is that you can always set the property for a particular target if you really need the scheme and you can do it in the same CMake file that creates the target (e.g. in a subproject).

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 30, 2024

@llvm/pr-subscribers-lldb

@llvm/pr-subscribers-clang

Author: Jon Roelofs (jroelofs)

Changes

CMake -GXcode would otherwise offer to create one scheme for each target, which ends up being a lot. For now, limit the default to the check-* LIT targets, plus ALL_BUILD and install.


Full diff: https://github.com/llvm/llvm-project/pull/101243.diff

2 Files Affected:

  • (modified) clang/cmake/modules/AddClang.cmake (+2)
  • (modified) llvm/cmake/modules/AddLLVM.cmake (+2)
diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake
index 9d09be1936847..5327b5d2f0892 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -147,6 +147,7 @@ endmacro(add_clang_library)
 macro(add_clang_executable name)
   add_llvm_executable( ${name} ${ARGN} )
   set_clang_windows_version_resource_properties(${name})
+  set_target_properties(${name} PROPERTIES XCODE_GENERATE_SCHEME ON)
 endmacro(add_clang_executable)
 
 macro(add_clang_tool name)
@@ -181,6 +182,7 @@ macro(add_clang_tool name)
       set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
     endif()
   endif()
+  set_target_properties(${name} PROPERTIES XCODE_GENERATE_SCHEME ON)
 endmacro()
 
 macro(add_clang_symlink name dest)
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 03f4e1f190fd9..ac47e884ac229 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1452,6 +1452,7 @@ macro(llvm_add_tool project name)
   endif()
   get_subproject_title(subproject_title)
   set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Tools")
+  set_target_properties(${name} PROPERTIES XCODE_GENERATE_SCHEME ON)
 endmacro(llvm_add_tool project name)
 
 macro(add_llvm_tool name)
@@ -2043,6 +2044,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.

@jroelofs
Copy link
Contributor Author

And you can always manually override them through the scheme editor thing, if that is a one-off local need.

@llvmbot llvmbot added the lldb label Jul 30, 2024
@clayborg
Copy link
Collaborator

Can we add a cmake settings that allows users to add custom target names that will be added? I would love to use this for my common projects like:

-DCMAKE_LLVM_XCODE_TARGETS=lldb;llvm-dwarfdump;llvm-gsymutil;lld

And it would add those top level targets?

@jroelofs
Copy link
Contributor Author

neat idea. that's doable.

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@clayborg
Copy link
Collaborator

Great! That will be very useful.

@@ -1423,3 +1423,11 @@ endif()
if (LLVM_INCLUDE_UTILS AND LLVM_INCLUDE_TOOLS)
add_subdirectory(utils/llvm-locstats)
endif()

if (XCODE)
set(LLVM_XCODE_EXTRA_TARGET_SCHEMES "" CACHE STRING "Specifies an extra list of targets to turn into schemes")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to say "an extra list of semi colon separated target names"? Do you specify this multiple times, or just once with semi colon separated target names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists in CMake are semicolon-separated. I'll add an example in a comment.

@jroelofs jroelofs merged commit a982cab into llvm:main Jul 31, 2024
4 of 6 checks passed
@jroelofs jroelofs deleted the jroelofs/xcode-schemes branch July 31, 2024 00:17
clementval pushed a commit to clementval/llvm-project that referenced this pull request Jul 31, 2024
…lvm#101243)

CMake -GXcode would otherwise offer to create one scheme for each
target, which ends up being a lot. For now, limit the default to the
`check-*` LIT targets, plus `ALL_BUILD` and `install`.

For targets that aren't in the default list, we now have a configuration
variable to promote an extra list of targets into schemes, for example
`-DLLVM_XCODE_EXTRA_TARGET_SCHEMES="TargetParserTests;SupportTests"` to
add schemes for `TargetParserTests` and `SupportTests` respectively.
banach-space pushed a commit to banach-space/llvm-project that referenced this pull request Aug 7, 2024
…lvm#101243)

CMake -GXcode would otherwise offer to create one scheme for each
target, which ends up being a lot. For now, limit the default to the
`check-*` LIT targets, plus `ALL_BUILD` and `install`.

For targets that aren't in the default list, we now have a configuration
variable to promote an extra list of targets into schemes, for example
`-DLLVM_XCODE_EXTRA_TARGET_SCHEMES="TargetParserTests;SupportTests"` to
add schemes for `TargetParserTests` and `SupportTests` respectively.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category cmake Build system in general and CMake in particular lldb
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants