summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-07-15 13:04:15 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-07-16 09:52:24 +0200
commit3595613a0a285120b1c475e7c350a0de871e89aa (patch)
tree7ba00ca3aa8793c7b499b1d9fb712a41cf7802d3
parent616c32be04b8cee16354283d22dfe5cef890d435 (diff)
CMake: Don't propagate -fapplication-extension to user projects
Both the compiler and linker -fapplication-extension flag should only be applied when building Qt's libraries (not executables). It's up to the user project whether their code will be restricted with application-extension-only APIs. In qmake that can be achieved by adding to the qmake project CONFIG += app_extension_api_only In CMake it can be achieved by either adding the compiler and link flags in the project directly (using target_X_options) or by setting the appropriate setting in the Xcode project when using the Xcode generator. Amends e189126f1ae1d2fa2ad0f95ee2c4aa72c770a97b Pick-to: 6.2 Task-number: QTBUG-95199 Change-Id: Ie7a764d460a89c7650391abff0fcc5abfcabef64 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
-rw-r--r--cmake/Qt3rdPartyLibraryHelpers.cmake1
-rw-r--r--cmake/QtInternalTargets.cmake18
-rw-r--r--cmake/QtModuleHelpers.cmake1
-rw-r--r--cmake/QtPluginHelpers.cmake1
-rw-r--r--cmake/QtTargetHelpers.cmake9
5 files changed, 28 insertions, 2 deletions
diff --git a/cmake/Qt3rdPartyLibraryHelpers.cmake b/cmake/Qt3rdPartyLibraryHelpers.cmake
index 059213f5f2..f2b3882fc7 100644
--- a/cmake/Qt3rdPartyLibraryHelpers.cmake
+++ b/cmake/Qt3rdPartyLibraryHelpers.cmake
@@ -50,6 +50,7 @@ function(qt_internal_add_common_qt_library_helper target)
endif()
_qt_internal_add_library(${target} ${arg_STATIC} ${arg_SHARED} ${arg_MODULE} ${arg_INTERFACE})
+ qt_internal_mark_as_internal_library(${target})
endfunction()
# Wrapper function to create a regular cmake target and forward all the
diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake
index db7be3d21e..22080b4d53 100644
--- a/cmake/QtInternalTargets.cmake
+++ b/cmake/QtInternalTargets.cmake
@@ -325,8 +325,22 @@ function(qt_handle_apple_app_extension_api_only)
# Build Qt libraries with -fapplication-extension. Needed to avoid linker warnings
# transformed into errors on darwin platforms.
set(flags "-fapplication-extension")
- set(genex_condition "$<NOT:$<BOOL:$<TARGET_PROPERTY:QT_NO_APP_EXTENSION_ONLY_API>>>")
- set(flags "$<${genex_condition}:${flags}>")
+
+ # The flags should only be applied to internal Qt libraries like modules and plugins.
+ # The reason why we use a custom property to apply the flags is because there's no other
+ # way to prevent the link options spilling out into user projects if the target that links
+ # against PlatformXInternal is a static library.
+ # The exported static library's INTERFACE_LINK_LIBRARIES property would contain
+ # $<LINK_ONLY:PlatformXInternal> and PlatformXInternal's INTERFACE_LINK_OPTIONS would be
+ # applied to a user project target.
+ # So to contain the spilling out of the flags, we ensure the link options are only added
+ # to internal Qt libraries that are marked with the property.
+ set(not_disabled "$<NOT:$<BOOL:$<TARGET_PROPERTY:QT_NO_APP_EXTENSION_ONLY_API>>>")
+ set(is_qt_internal_library "$<BOOL:$<TARGET_PROPERTY:_qt_is_internal_library>>")
+
+ set(condition "$<AND:${not_disabled},${is_qt_internal_library}>")
+
+ set(flags "$<${condition}:${flags}>")
target_compile_options(PlatformModuleInternal INTERFACE ${flags})
target_link_options(PlatformModuleInternal INTERFACE ${flags})
target_compile_options(PlatformPluginInternal INTERFACE ${flags})
diff --git a/cmake/QtModuleHelpers.cmake b/cmake/QtModuleHelpers.cmake
index dc011a717e..ec09984522 100644
--- a/cmake/QtModuleHelpers.cmake
+++ b/cmake/QtModuleHelpers.cmake
@@ -105,6 +105,7 @@ function(qt_internal_add_module target)
endif()
_qt_internal_add_library("${target}" ${type_to_create})
+ qt_internal_mark_as_internal_library("${target}")
get_target_property(target_type ${target} TYPE)
diff --git a/cmake/QtPluginHelpers.cmake b/cmake/QtPluginHelpers.cmake
index 23e3de8f88..1b92a638a0 100644
--- a/cmake/QtPluginHelpers.cmake
+++ b/cmake/QtPluginHelpers.cmake
@@ -76,6 +76,7 @@ function(qt_internal_add_plugin target)
${ARGN}
)
qt6_add_plugin(${target} ${plugin_args})
+ qt_internal_mark_as_internal_library(${target})
qt_get_sanitized_plugin_type("${arg_TYPE}" plugin_type_escaped)
diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake
index af775ca514..9c1d0c5157 100644
--- a/cmake/QtTargetHelpers.cmake
+++ b/cmake/QtTargetHelpers.cmake
@@ -753,3 +753,12 @@ function(qt_internal_adjust_main_config_runtime_output_dir target output_dir)
RUNTIME_OUTPUT_DIRECTORY_${main_cmake_configuration} "${output_dir}"
)
endfunction()
+
+# Marks a target with a property that it is a library (shared or static) which was built using the
+# internal Qt API (qt_internal_add_module, qt_internal_add_plugin, etc) as opposed to it being
+# a user project library (qt_add_library, qt_add_plugin, etc).
+#
+# Needed to allow selectively applying certain flags via PlatformXInternal targets.
+function(qt_internal_mark_as_internal_library target)
+ set_target_properties(${target} PROPERTIES _qt_is_internal_library TRUE)
+endfunction()