From 87aa94008ba0f61f515827f302b718dc2ef3a6f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 10 Jan 2024 11:29:13 +0100 Subject: [PATCH] cmake: Explicitly generate Xcode schemes for executables and libs Otherwise, Xcode will auto-generate schemes for all targets, including internal targets such as foo_autogen and build-only targets such as ZERO_CHECK and ALL_BUILD, choosing one of them at random when opening the project for the first time. If multiple targets get a scheme they will be sorted alphabetically. We could prioritize them by generating a xcschememanagement.plist file, but that would require teaching CMake about that feature. This aligns the CMake behavior with qmake, where we also generate schemes explicitly. Pick-to: 6.6 6.5 Change-Id: I3756fced37a4ff7792370da10fc49169cc271ae8 Reviewed-by: Alexandru Croitor (cherry picked from commit 822dc75f1a0be988b25741a8f16ddc2fbeb48e77) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/Qt6CoreMacros.cmake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 9f978d5f9db..93f19e0d8be 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -757,6 +757,20 @@ function(qt6_finalize_target target) _qt_internal_finalize_executable(${ARGV}) endif() + if(APPLE) + # Tell CMake to generate run-scheme for the executable when generating + # Xcode projects. This avoids Xcode auto-generating default schemes for + # all targets, which includes internal and build-only targets. + get_target_property(generate_scheme "${target}" XCODE_GENERATE_SCHEME) + if(generate_scheme MATCHES "-NOTFOUND" AND ( + target_type STREQUAL "EXECUTABLE" OR + target_type STREQUAL "SHARED_LIBRARY" OR + target_type STREQUAL "STATIC_LIBRARY" OR + target_type STREQUAL "MODULE_LIBRARY")) + set_property(TARGET "${target}" PROPERTY XCODE_GENERATE_SCHEME TRUE) + endif() + endif() + set_target_properties(${target} PROPERTIES _qt_is_finalized TRUE) endfunction()