summaryrefslogtreecommitdiffstats
path: root/tests/auto/cmake
diff options
context:
space:
mode:
authorAlexey Edelev <alexey.edelev@qt.io>2024-01-31 11:07:10 +0100
committerAlexey Edelev <alexey.edelev@qt.io>2024-02-01 09:46:51 +0100
commit31b75303d7f9126dcc9bb0e94f0ea4ef1b9c0a71 (patch)
tree784cd366649e0e9f45aec95d45b6f660c7d53752 /tests/auto/cmake
parentd0da8d963d31f75b8648448f74819ee0854a86bb (diff)
Introduce QTP0003 which controls the BUILD_SHARED_LIBS impact on user projects
Since 6.7 we consider the BUILD_SHARED_LIBS when creating libraries using Qt CMake API. This change may affect the user projects that rely on the old strategy of selecting the default library type. To preserve the old behavior this change introduces the QTP0003 policy that allows user to control whether the BUILD_SHARED_LIBS should or shouldn't be considered in library creation process. The policy doesn't affect Qt repos, we assume that we want the NEW behavior by default. Fixes: QTBUG-121707 Pick-to: 6.7 Change-Id: I4bcfbd8966839731624e3f7ef9e0d6bb2782ac50 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Diffstat (limited to 'tests/auto/cmake')
-rw-r--r--tests/auto/cmake/CMakeLists.txt1
-rw-r--r--tests/auto/cmake/test_QTP0003/CMakeLists.txt66
-rw-r--r--tests/auto/cmake/test_QTP0003/source.cpp4
3 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt
index b8d8f50d6b..f71468cee8 100644
--- a/tests/auto/cmake/CMakeLists.txt
+++ b/tests/auto/cmake/CMakeLists.txt
@@ -392,3 +392,4 @@ else()
endif()
_qt_internal_test_expect_pass(test_config_expressions)
+_qt_internal_test_expect_pass(test_QTP0003)
diff --git a/tests/auto/cmake/test_QTP0003/CMakeLists.txt b/tests/auto/cmake/test_QTP0003/CMakeLists.txt
new file mode 100644
index 0000000000..8dda76fdb0
--- /dev/null
+++ b/tests/auto/cmake/test_QTP0003/CMakeLists.txt
@@ -0,0 +1,66 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+
+project(test_QTP0003)
+
+find_package(Qt6 COMPONENTS Core REQUIRED)
+
+if(QT6_IS_SHARED_LIBS_BUILD)
+ set(qt_build_type "SHARED_LIBRARY")
+else()
+ set(qt_build_type "STATIC_LIBRARY")
+endif()
+
+set(BUILD_SHARED_LIBS ON)
+qt6_add_library(MyLib source.cpp)
+get_target_property(type MyLib TYPE)
+if(NOT "${type}" STREQUAL "${qt_build_type}")
+ message(FATAL_ERROR "The library uses the default type different from Qt build type when"
+ "QTP0003 is not set")
+endif()
+
+set(BUILD_SHARED_LIBS OFF)
+qt6_add_library(MyLib2 source.cpp)
+get_target_property(type MyLib2 TYPE)
+if(NOT "${type}" STREQUAL "${qt_build_type}")
+ message(FATAL_ERROR "The library uses the default type different from Qt build type when"
+ "QTP0003 is not set")
+endif()
+
+set(BUILD_SHARED_LIBS ON)
+qt_policy(SET QTP0003 OLD)
+qt6_add_library(MyLib3 source.cpp)
+get_target_property(type MyLib3 TYPE)
+if(NOT "${type}" STREQUAL "${qt_build_type}")
+ message(FATAL_ERROR "The library uses the default type different from Qt build type when"
+ "QTP0003 is set to OLD")
+endif()
+
+set(BUILD_SHARED_LIBS OFF)
+qt_policy(SET QTP0003 OLD)
+qt6_add_library(MyLib4 source.cpp)
+get_target_property(type MyLib4 TYPE)
+if(NOT "${type}" STREQUAL "${qt_build_type}")
+ message(FATAL_ERROR "The library uses the default type different from Qt build type when"
+ "QTP0003 is set to OLD")
+endif()
+
+set(BUILD_SHARED_LIBS ON)
+qt_policy(SET QTP0003 NEW)
+qt6_add_library(MyLib5 source.cpp)
+get_target_property(type MyLib5 TYPE)
+if(NOT "${type}" STREQUAL "SHARED_LIBRARY")
+ message(FATAL_ERROR "The library doesn't consider the BUILD_SHARED_LIBS when"
+ "QTP0003 is set to NEW")
+endif()
+
+set(BUILD_SHARED_LIBS OFF)
+qt_policy(SET QTP0003 NEW)
+qt6_add_library(MyLib6 source.cpp)
+get_target_property(type MyLib6 TYPE)
+if(NOT "${type}" STREQUAL "STATIC_LIBRARY")
+ message(FATAL_ERROR "The library doesn't consider the BUILD_SHARED_LIBS when"
+ "QTP0003 is set to NEW")
+endif()
diff --git a/tests/auto/cmake/test_QTP0003/source.cpp b/tests/auto/cmake/test_QTP0003/source.cpp
new file mode 100644
index 0000000000..0df705acd8
--- /dev/null
+++ b/tests/auto/cmake/test_QTP0003/source.cpp
@@ -0,0 +1,4 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+class Noop {};