summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-10-26 16:07:44 +0100
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-10-27 12:49:39 +0100
commit65fe5b2ce22797389aa074ef2c30e873a3c38d48 (patch)
tree2b8a9ef9035ab6cb6cd5ab7a07da0e9851c3ef9d /util
parent1e904ab342c1aaabbef67cbcc25cf3de9e35e755 (diff)
CMake: pro2cmake: Handle CONFIG+=console app_bundle in examples
Now that qt_add_executable doesn't set the WIN32_EXECUTABLE and MACOSX_BUNDLE properties anymore, pro2cmake needs to look at the qmake example projects and generate appropriate set_target_properties calls. The relevant CONFIG entries to look at are windows, console, app_bundle and cmdline. CONFIG += windows implies 'subsystem windows' on Windows, which maps to WIN32_EXECUTABLE == TRUE. CONFIG += console implies 'subsystem console' on Windows, which maps to WIN32_EXECUTABLE == FALSE. Aka the opposite of CONFIG += windows. Whichever is the last one set, cancels out the other one. CONFIG += app_bundle implies a macOS bundle executable, which maps to MACOSX_BUNDLE == TRUE. CONFIG += cmdline is the same as CONFIG += console and CONFIG -= app_bundle, aka WIN32_EXECUTABLE and MACOSX_BUNDLE set to false. In qmake, if no CONFIG is specified in an example project, the default is CONFIG += windows app_bundle, aka WIN32_EXECUTABLE and MACOSX_BUNDLE set to true. The script uses a heuristic to try and not write the properties for every single subscope, except for values different from the default. This is not strictly correct, but it covers most use cases, and keeps the generated projects a bit cleaner. Task-number: QTBUG-87664 Task-number: QTBUG-86827 Change-Id: If05606ec3205e0fe7c1803c07e114d9fd9c3e4f7 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'util')
-rwxr-xr-xutil/cmake/pro2cmake.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py
index b2b7215975..9ba0e95765 100755
--- a/util/cmake/pro2cmake.py
+++ b/util/cmake/pro2cmake.py
@@ -3582,6 +3582,34 @@ def write_jar(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> str:
return target
+def write_win32_and_mac_bundle_properties(cm_fh: IO[str], scope: Scope, target: str, *,
+ handling_first_scope=False, indent: int = 0):
+ config = scope.get("CONFIG")
+ win32 = all(val not in config for val in ["cmdline", "console"])
+ mac_bundle = all(val not in config for val in ["cmdline", "-app_bundle"])
+
+ true_value = "TRUE"
+ false_value = "FALSE"
+
+ properties_mapping = {"WIN32_EXECUTABLE": true_value if win32 else false_value,
+ "MACOSX_BUNDLE": true_value if mac_bundle else false_value}
+
+ properties = []
+
+ # Always write the properties for the first scope.
+ # For conditional scopes, only write them if the value is different
+ # from the default value (aka different from TRUE).
+ # This is a heurestic that should cover 90% of the example projects
+ # without creating excess noise of setting the properties in every
+ # single scope.
+ for name, value in properties_mapping.items():
+ if handling_first_scope or (not handling_first_scope and value != true_value):
+ properties.extend([name, value])
+
+ if properties:
+ write_set_target_properties(cm_fh, [target], properties, indent=indent)
+
+
def write_example(
cm_fh: IO[str], scope: Scope, gui: bool = False, *, indent: int = 0, is_plugin: bool = False
) -> str:
@@ -3747,6 +3775,12 @@ def write_example(
io_string, scope, target_sources, indent=indent, footer=")\n"
)
+ write_win32_and_mac_bundle_properties(io_string,
+ scope,
+ binary_name,
+ handling_first_scope=handling_first_scope,
+ indent=indent)
+
write_include_paths(
io_string,
scope,