pro2cmake.py: generate examples with properties in qt_add_executable()

This patch will slightly change the output of CMakeLists.txt files that
are generated for examples.

* set_target_properties() will no longer be added to the top-level
  scope. If the WIN32 and MACOSX_BUNDLE properties should be added,
  they will instead be added to qt_add_executable().

* The version in cmake_minimum_required() will now be 3.16, rather than
  3.14.

Pick-to: 6.2
Change-Id: I79e1865dace5538d2b7ff264da02f9e28a655ae9
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Oliver Eftevaag 2021-09-06 17:03:41 +02:00
parent 28e194d3b2
commit 8337493301

View File

@ -3686,13 +3686,19 @@ 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
):
def get_win32_and_mac_bundle_properties(scope: Scope) -> tuple:
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"])
return win32, mac_bundle
def write_win32_and_mac_bundle_properties(
cm_fh: IO[str], scope: Scope, target: str, *, handling_first_scope=False, indent: int = 0
):
win32, mac_bundle = get_win32_and_mac_bundle_properties(scope)
true_value = "TRUE"
false_value = "FALSE"
@ -3710,7 +3716,7 @@ def write_win32_and_mac_bundle_properties(
# 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):
if not handling_first_scope and value != true_value:
properties.extend([name, value])
if properties:
@ -3731,7 +3737,7 @@ def write_example(
)
cm_fh.write(
"cmake_minimum_required(VERSION 3.14)\n"
f"cmake_minimum_required(VERSION {cmake_version_string})\n"
f"project({binary_name} LANGUAGES CXX)\n\n"
"set(CMAKE_INCLUDE_CURRENT_DIR ON)\n\n"
"set(CMAKE_AUTOMOC ON)\n"
@ -3856,6 +3862,13 @@ def write_example(
else:
add_target = f"qt_add_executable({binary_name}"
property_win32, property_mac_bundle = get_win32_and_mac_bundle_properties(scope)
if property_win32:
add_target += ' ' + "WIN32"
if property_mac_bundle:
add_target += ' ' + "MACOSX_BUNDLE"
write_all_source_file_lists(cm_fh, scope, add_target, indent=0)
cm_fh.write(")\n")