summaryrefslogtreecommitdiffstats
path: root/tests/auto/cmake
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 /tests/auto/cmake
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 'tests/auto/cmake')
-rw-r--r--tests/auto/cmake/CMakeLists.txt2
-rw-r--r--tests/auto/cmake/test_plugin_shared_static_flavor.cmake24
-rw-r--r--tests/auto/cmake/test_plugin_shared_static_flavor/CMakeLists.txt31
3 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt
index 317541f984..b43aa8f0a6 100644
--- a/tests/auto/cmake/CMakeLists.txt
+++ b/tests/auto/cmake/CMakeLists.txt
@@ -226,3 +226,5 @@ _qt_internal_test_expect_pass(test_versionless_targets)
_qt_internal_test_expect_pass(test_add_resources_binary_generated
BINARY test_add_resources_binary_generated)
+
+include(test_plugin_shared_static_flavor.cmake)
diff --git a/tests/auto/cmake/test_plugin_shared_static_flavor.cmake b/tests/auto/cmake/test_plugin_shared_static_flavor.cmake
new file mode 100644
index 0000000000..a906bfebbc
--- /dev/null
+++ b/tests/auto/cmake/test_plugin_shared_static_flavor.cmake
@@ -0,0 +1,24 @@
+_qt_internal_test_expect_pass(test_plugin_shared_static_flavor
+ TESTNAME test_plugin_flavor_static
+ BUILD_OPTIONS
+ "-DPLUGIN_OPTIONS=STATIC"
+ "-DEXPECTED_PLUGIN_TARGET_TYPE=STATIC_LIBRARY")
+
+_qt_internal_test_expect_pass(test_plugin_shared_static_flavor
+ TESTNAME test_plugin_flavor_shared
+ BUILD_OPTIONS
+ "-DPLUGIN_OPTIONS=SHARED"
+ "-DEXPECTED_PLUGIN_TARGET_TYPE=MODULE_LIBRARY")
+
+if(QT6_IS_SHARED_LIBS_BUILD)
+ set(expected_plugin_target_type "MODULE_LIBRARY")
+else()
+ set(expected_plugin_target_type "STATIC_LIBRARY")
+endif()
+
+# Check default computed value when no explicit option is set.
+_qt_internal_test_expect_pass(test_plugin_shared_static_flavor
+ TESTNAME test_plugin_flavor_derived_from_qt_type
+ BUILD_OPTIONS
+ "-DPLUGIN_OPTIONS="
+ "-DEXPECTED_PLUGIN_TARGET_TYPE=${expected_plugin_target_type}")
diff --git a/tests/auto/cmake/test_plugin_shared_static_flavor/CMakeLists.txt b/tests/auto/cmake/test_plugin_shared_static_flavor/CMakeLists.txt
new file mode 100644
index 0000000000..12d7affc51
--- /dev/null
+++ b/tests/auto/cmake/test_plugin_shared_static_flavor/CMakeLists.txt
@@ -0,0 +1,31 @@
+cmake_minimum_required(VERSION 3.14)
+
+project(test_plugin_flavor)
+
+if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
+ include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
+endif()
+
+find_package(Qt6Core REQUIRED HINTS ${Qt6Tests_PREFIX_PATH})
+
+qt6_add_plugin(test_plugin ${PLUGIN_OPTIONS})
+
+set(plugin_source_path "${CMAKE_CURRENT_BINARY_DIR}/plugin.cpp")
+file(GENERATE OUTPUT "${plugin_source_path}" CONTENT "int foo() {return 0;}")
+target_sources(test_plugin PRIVATE "${plugin_source_path}")
+
+get_target_property(plugin_target_type test_plugin TYPE)
+
+if(NOT EXPECTED_PLUGIN_TARGET_TYPE)
+ message(FATAL_ERROR "No value given for EXPECTED_PLUGIN_TARGET_TYPE variable")
+endif()
+
+if(NOT plugin_target_type STREQUAL "${EXPECTED_PLUGIN_TARGET_TYPE}")
+ set(info "")
+ list(APPEND info "PLUGIN_OPTIONS: ${PLUGIN_OPTIONS}")
+ list(APPEND info "QT6_IS_SHARED_LIBS_BUILD: ${QT6_IS_SHARED_LIBS_BUILD}")
+ list(APPEND info "EXPECTED_PLUGIN_TARGET_TYPE: ${EXPECTED_PLUGIN_TARGET_TYPE}")
+ list(JOIN info "\n" info)
+ message(FATAL_ERROR
+ "Computed plugin target type '${plugin_target_type}' did not match expected type '${EXPECTED_PLUGIN_TARGET_TYPE}'\n${info}")
+endif()