summaryrefslogtreecommitdiffstats
path: root/tests/auto/cmake/test_global_promotion
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/cmake/test_global_promotion')
-rw-r--r--tests/auto/cmake/test_global_promotion/CMakeLists.txt16
-rw-r--r--tests/auto/cmake/test_global_promotion/subdir_with_global_qt/CMakeLists.txt17
-rw-r--r--tests/auto/cmake/test_global_promotion/subdir_with_local_qt/CMakeLists.txt15
3 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/cmake/test_global_promotion/CMakeLists.txt b/tests/auto/cmake/test_global_promotion/CMakeLists.txt
new file mode 100644
index 0000000000..24b2eacaf1
--- /dev/null
+++ b/tests/auto/cmake/test_global_promotion/CMakeLists.txt
@@ -0,0 +1,16 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+
+project(global_promotion)
+
+add_subdirectory(subdir_with_local_qt)
+add_subdirectory(subdir_with_global_qt)
+
+set(file_path "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+file(GENERATE OUTPUT "${file_path}" CONTENT "int main() { return 0; }")
+add_executable(exe main.cpp)
+
+# The Qt targets found in the 2nd child directory scope should be available in this scope.
+target_link_libraries(exe PRIVATE lib_global_qt)
diff --git a/tests/auto/cmake/test_global_promotion/subdir_with_global_qt/CMakeLists.txt b/tests/auto/cmake/test_global_promotion/subdir_with_global_qt/CMakeLists.txt
new file mode 100644
index 0000000000..26e3d6e025
--- /dev/null
+++ b/tests/auto/cmake/test_global_promotion/subdir_with_global_qt/CMakeLists.txt
@@ -0,0 +1,17 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+message(STATUS "Entered subdir_with_global_qt subdirectory")
+
+set(file_path "${CMAKE_CURRENT_BINARY_DIR}/lib.cpp")
+file(GENERATE OUTPUT "${file_path}" CONTENT "int foo() { return 42; }")
+add_library(lib_global_qt STATIC "${file_path}")
+
+# These Qt targets will be available in all scopes of the project.
+# The previous local targets are simply shadowed.
+set(QT_PROMOTE_TO_GLOBAL_TARGETS ON)
+find_package(Qt6 REQUIRED COMPONENTS Gui)
+
+target_link_libraries(lib_global_qt PRIVATE Qt6::Gui)
+
+message(STATUS "Exiting subdir_with_global_qt subdirectory")
diff --git a/tests/auto/cmake/test_global_promotion/subdir_with_local_qt/CMakeLists.txt b/tests/auto/cmake/test_global_promotion/subdir_with_local_qt/CMakeLists.txt
new file mode 100644
index 0000000000..820282b7c1
--- /dev/null
+++ b/tests/auto/cmake/test_global_promotion/subdir_with_local_qt/CMakeLists.txt
@@ -0,0 +1,15 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+message(STATUS "Entered subdir_with_local_qt subdirectory")
+
+set(file_path "${CMAKE_CURRENT_BINARY_DIR}/lib.cpp")
+file(GENERATE OUTPUT "${file_path}" CONTENT "int foo() { return 42; }")
+add_library(lib_local_qt STATIC "${file_path}")
+
+# These Qt targets will be local to this directory scope.
+find_package(Qt6 REQUIRED COMPONENTS Gui)
+
+target_link_libraries(lib_local_qt PRIVATE Qt6::Gui)
+
+message(STATUS "Exiting subdir_with_local_qt subdirectory")