summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-04-06 13:06:11 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-04-07 14:02:36 +0000
commitbce41e0c41cf8e25c0d46fe90f7ea1b1b358454a (patch)
tree1bd8397d53fa821b0069eaa9d47104fb8603e4fb /src/corelib
parentf7605d562b83aef5b098ea18bf6c89f30ec4e920 (diff)
CMake: Choose better defaults for qt_add_plugin STATIC/SHARED
There was a recent behavior change where the public CMake API qt_add_plugin API took into account the value of BUILD_SHARED_LIBS to decide whether the plugin should be a static or shared library. Instead, use the following new behavior - If no explicit option STATIC / SHARED option is passed, default to whatever flavor Qt was built as. Aka if Qt was configured with -shared, qt_add_plugin defaults to creating shared plugins. If it's a -static Qt, create static plugins. - If an explicit STATIC / SHARED option is set, override the default computed value with the given value. As a result BUILD_SHARED_LIBS does not affect Qt plugins anymore. This is more in line with Qt expectations. Add SHARED as a new valid option to pass to qt_add_plugin (it wasn't before). Add tests to check for the above behavior. Amends aa4a1006cbccbc180c600f9b4dc9e882bb5ed5ca Fixes: QTBUG-92361 Task-number: QTBUG-88763 Change-Id: Iae806024ddd5cf10cfe58ddbcebd2818084b0bd7 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit d0c2425d791edd75e35cce65ddbcfaab9a7f16ed) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/Qt6CTestMacros.cmake16
-rw-r--r--src/corelib/Qt6CoreMacros.cmake23
2 files changed, 35 insertions, 4 deletions
diff --git a/src/corelib/Qt6CTestMacros.cmake b/src/corelib/Qt6CTestMacros.cmake
index 9062985ac0..5a96e15ea6 100644
--- a/src/corelib/Qt6CTestMacros.cmake
+++ b/src/corelib/Qt6CTestMacros.cmake
@@ -114,10 +114,19 @@ function(_qt_internal_set_up_test_run_environment testname)
endfunction()
# Checks if the test project can be built successfully.
+#
+# TESTNAME: a custom test name to use instead of the one derived from the source directory name
+# BUILD_OPTIONS: a list of -D style CMake definitions to pass to ctest's --build-options (which
+# are ultimately passed to the CMake invocation of the test project)
macro(_qt_internal_test_expect_pass _dir)
- cmake_parse_arguments(_ARGS "" "BINARY" "" ${ARGN})
- string(REPLACE "(" "_" testname "${_dir}")
- string(REPLACE ")" "_" testname "${testname}")
+ cmake_parse_arguments(_ARGS "" "BINARY;TESTNAME" "BUILD_OPTIONS" ${ARGN})
+
+ if(_ARGS_TESTNAME)
+ set(testname "${_ARGS_TESTNAME}")
+ else()
+ string(REPLACE "(" "_" testname "${_dir}")
+ string(REPLACE ")" "_" testname "${testname}")
+ endif()
set(__expect_pass__prefixes "${CMAKE_PREFIX_PATH}")
string(REPLACE ";" "\;" __expect_pass__prefixes "${__expect_pass__prefixes}")
@@ -131,6 +140,7 @@ macro(_qt_internal_test_expect_pass _dir)
--build-makeprogram "${CMAKE_MAKE_PROGRAM}"
--build-project "${_dir}"
--build-options "-DCMAKE_PREFIX_PATH=${__expect_pass__prefixes}" ${BUILD_OPTIONS_LIST}
+ ${_ARGS_BUILD_OPTIONS}
--test-command ${_ARGS_BINARY})
add_test(${testname} ${CMAKE_CTEST_COMMAND} ${ctest_command_args})
if(_ARGS_BINARY)
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake
index 9e9b0f1e56..3d1a10ff0a 100644
--- a/src/corelib/Qt6CoreMacros.cmake
+++ b/src/corelib/Qt6CoreMacros.cmake
@@ -1423,6 +1423,7 @@ endfunction()
macro(_qt_internal_get_add_plugin_keywords option_args single_args multi_args)
set(${option_args}
STATIC
+ SHARED
)
set(${single_args}
TYPE
@@ -1455,7 +1456,27 @@ function(qt6_add_plugin target)
unset(arg_CLASSNAME)
endif()
- if (arg_STATIC OR NOT BUILD_SHARED_LIBS)
+ if(arg_STATIC AND arg_SHARED)
+ message(FATAL_ERROR
+ "Both STATIC and SHARED options were given. Only one of the two should be used."
+ )
+ endif()
+
+ # If no explicit STATIC/SHARED option is set, default to the flavor of the Qt build.
+ if(QT6_IS_SHARED_LIBS_BUILD)
+ set(create_static_plugin FALSE)
+ else()
+ set(create_static_plugin TRUE)
+ endif()
+
+ # Explicit option takes priority over the computed default.
+ if(arg_STATIC)
+ set(create_static_plugin TRUE)
+ elseif(arg_SHARED)
+ set(create_static_plugin FALSE)
+ endif()
+
+ if (create_static_plugin)
add_library(${target} STATIC)
target_compile_definitions(${target} PRIVATE QT_STATICPLUGIN)
else()