summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <[email protected]>2025-03-28 16:50:58 +0100
committerTor Arne Vestbø <[email protected]>2025-03-31 17:29:48 +0200
commit6a465729be812465ea97dda81e03c4d6d92f5d4c (patch)
treefe150e772ac5ff8f90977d96a9f3bcb0ed7ea99a
parent80d680e82f545d3a0ae23aa65d07befbab57b71a (diff)
cmake: Respect CMAKE_MACOSX_BUNDLE and CMAKE_WIN32_EXECUTABLE
The user may set different global defaults for CMAKE_MACOSX_BUNDLE and CMAKE_WIN32_EXECUTABLE, so we shouldn't unconditionally override them on a target level. This allows cmake ~/foo/ -DCMAKE_MACOSX_BUNDLE=ON to build a project as a GUI app without needing to modify the CMakeLists.txt with target specific overrides. Change-Id: Id49adb1c0aedfe82a2b1d919d086c5112ba92b93 Reviewed-by: Alexandru Croitor <[email protected]>
-rw-r--r--cmake/QtExecutableHelpers.cmake11
-rw-r--r--cmake/QtTestHelpers.cmake18
2 files changed, 20 insertions, 9 deletions
diff --git a/cmake/QtExecutableHelpers.cmake b/cmake/QtExecutableHelpers.cmake
index 49d341597d1..90bbfee4ac3 100644
--- a/cmake/QtExecutableHelpers.cmake
+++ b/cmake/QtExecutableHelpers.cmake
@@ -184,10 +184,17 @@ function(qt_internal_add_executable name)
set_target_properties("${name}" PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}"
LIBRARY_OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}"
- WIN32_EXECUTABLE "${arg_GUI}"
- MACOSX_BUNDLE "${arg_GUI}"
)
+ if(arg_GUI)
+ # Only override if GUI is set. Otherwise leave up to
+ # CMake defaults, which may be set by the user elsewhere.
+ set_target_properties("${name}" PROPERTIES
+ MACOSX_BUNDLE ON
+ WIN32_EXECUTABLE ON
+ )
+ endif()
+
if(NOT arg_EXCEPTIONS)
qt_internal_set_exceptions_flags("${name}" "DEFAULT")
else()
diff --git a/cmake/QtTestHelpers.cmake b/cmake/QtTestHelpers.cmake
index e84a9bfa6b0..84d93297ed4 100644
--- a/cmake/QtTestHelpers.cmake
+++ b/cmake/QtTestHelpers.cmake
@@ -576,13 +576,17 @@ function(qt_internal_add_test name)
# Manual tests can be bundle apps
if(NOT arg_MANUAL)
- # Tests should not be bundles on macOS even if arg_GUI is true, because some tests make
- # assumptions about the location of helper processes, and those paths would be different
- # if a test is built as a bundle.
- set_property(TARGET "${name}" PROPERTY MACOSX_BUNDLE FALSE)
- # The same goes for WIN32_EXECUTABLE, but because it will detach from the console window
- # and not print anything.
- set_property(TARGET "${name}" PROPERTY WIN32_EXECUTABLE FALSE)
+ if(NOT DEFINED CMAKE_MACOSX_BUNDLE)
+ # Tests should not be bundles on macOS even if arg_GUI is true, because some tests make
+ # assumptions about the location of helper processes, and those paths would be different
+ # if a test is built as a bundle.
+ set_property(TARGET "${name}" PROPERTY MACOSX_BUNDLE FALSE)
+ endif()
+ if(NOT DEFINED CMAKE_WIN32_EXECUTABLE)
+ # The same goes for WIN32_EXECUTABLE, but because it will detach from the console window
+ # and not print anything.
+ set_property(TARGET "${name}" PROPERTY WIN32_EXECUTABLE FALSE)
+ endif()
endif()
# Tests on iOS must be app bundles.