summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-06-11 10:13:51 +0000
committerKitware Robot <kwrobot@kitware.com>2022-06-11 06:13:57 -0400
commit012eb492635cded21f8cb2bd6c37a856e5558cde (patch)
tree45d7cdf1a8375795bc50a2c1bce532c8d27658b1 /Tests
parentf0ebdce4e8f3400e9ecec698506ddf03ca4e053e (diff)
parentf19b48e0b89d5854e4a7a8fbbccadb38c02dcd76 (diff)
downloadcmake-012eb492635cded21f8cb2bd6c37a856e5558cde.tar.gz
Merge topic 'fetchcontent-global-targets' into release-3.24
f19b48e0b8 FetchContent: Honor CMAKE_FIND_PACKAGE_TARGETS_GLOBAL 1305bade56 Help: Add missing version directive for find_package() GLOBAL keyword Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !7347
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/FetchContent_find_package/ChildScope/CMakeLists.txt11
-rw-r--r--Tests/RunCMake/FetchContent_find_package/GLOBAL.cmake50
-rw-r--r--Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindEventuallyGlobal.cmake6
-rw-r--r--Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindGlobalWithArgsKeyword.cmake6
-rw-r--r--Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindGlobalWithoutArgsKeyword.cmake6
-rw-r--r--Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindLocalWithArgsKeyword.cmake6
-rw-r--r--Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindLocalWithoutArgsKeyword.cmake6
-rw-r--r--Tests/RunCMake/FetchContent_find_package/RunCMakeTest.cmake1
8 files changed, 92 insertions, 0 deletions
diff --git a/Tests/RunCMake/FetchContent_find_package/ChildScope/CMakeLists.txt b/Tests/RunCMake/FetchContent_find_package/ChildScope/CMakeLists.txt
new file mode 100644
index 0000000000..7e994d6ecf
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/ChildScope/CMakeLists.txt
@@ -0,0 +1,11 @@
+FetchContent_MakeAvailable(
+ GlobalWithArgsKeyword
+ GlobalWithoutArgsKeyword
+ LocalWithArgsKeyword
+ LocalWithoutArgsKeyword
+)
+
+# This one was declared without GLOBAL, but should still become global when
+# this variable is true at the time FetchContent_MakeAvailable() is called
+set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL TRUE)
+FetchContent_MakeAvailable(EventuallyGlobal)
diff --git a/Tests/RunCMake/FetchContent_find_package/GLOBAL.cmake b/Tests/RunCMake/FetchContent_find_package/GLOBAL.cmake
new file mode 100644
index 0000000000..0de65d59be
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/GLOBAL.cmake
@@ -0,0 +1,50 @@
+include(FetchContent)
+
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/PackageFindModules)
+set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE ALWAYS)
+
+set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL TRUE)
+FetchContent_Declare(
+ GlobalWithArgsKeyword
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
+ FIND_PACKAGE_ARGS
+)
+FetchContent_Declare(
+ GlobalWithoutArgsKeyword
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
+)
+
+set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL FALSE)
+FetchContent_Declare(
+ LocalWithArgsKeyword
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
+ FIND_PACKAGE_ARGS
+)
+FetchContent_Declare(
+ LocalWithoutArgsKeyword
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
+)
+FetchContent_Declare(
+ EventuallyGlobal
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
+)
+
+add_subdirectory(ChildScope)
+
+if(NOT TARGET GlobalWithArgsKeywordExe)
+ message(SEND_ERROR "GlobalWithArgsKeywordExe is not a global target")
+endif()
+if(NOT TARGET GlobalWithoutArgsKeywordExe)
+ message(SEND_ERROR "GlobalWithoutArgsKeywordExe is not a global target")
+endif()
+
+if(TARGET LocalWithArgsKeywordExe)
+ message(SEND_ERROR "LocalWithArgsKeywordExe is unexpectedly a global target")
+endif()
+if(TARGET LocalWithoutArgsKeywordExe)
+ message(SEND_ERROR "LocalWithoutArgsKeywordExe is unexpectedly a global target")
+endif()
+
+if(NOT TARGET EventuallyGlobalExe)
+ message(SEND_ERROR "EventuallyGlobalExe is not a global target")
+endif()
diff --git a/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindEventuallyGlobal.cmake b/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindEventuallyGlobal.cmake
new file mode 100644
index 0000000000..2389cb1029
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindEventuallyGlobal.cmake
@@ -0,0 +1,6 @@
+add_executable(EventuallyGlobalExe IMPORTED)
+set_target_properties(EventuallyGlobalExe PROPERTIES
+ IMPORTED_LOCATION "${CMAKE_COMMAND}"
+)
+
+set(EventuallyGlobal_FOUND TRUE)
diff --git a/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindGlobalWithArgsKeyword.cmake b/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindGlobalWithArgsKeyword.cmake
new file mode 100644
index 0000000000..55588b81dc
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindGlobalWithArgsKeyword.cmake
@@ -0,0 +1,6 @@
+add_executable(GlobalWithArgsKeywordExe IMPORTED)
+set_target_properties(GlobalWithArgsKeywordExe PROPERTIES
+ IMPORTED_LOCATION "${CMAKE_COMMAND}"
+)
+
+set(GlobalWithArgsKeyword_FOUND TRUE)
diff --git a/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindGlobalWithoutArgsKeyword.cmake b/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindGlobalWithoutArgsKeyword.cmake
new file mode 100644
index 0000000000..c3e6a6b7b3
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindGlobalWithoutArgsKeyword.cmake
@@ -0,0 +1,6 @@
+add_executable(GlobalWithoutArgsKeywordExe IMPORTED)
+set_target_properties(GlobalWithoutArgsKeywordExe PROPERTIES
+ IMPORTED_LOCATION "${CMAKE_COMMAND}"
+)
+
+set(GlobalWithoutArgsKeyword_FOUND TRUE)
diff --git a/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindLocalWithArgsKeyword.cmake b/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindLocalWithArgsKeyword.cmake
new file mode 100644
index 0000000000..381daa3c32
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindLocalWithArgsKeyword.cmake
@@ -0,0 +1,6 @@
+add_executable(LocalWithArgsKeywordExe IMPORTED)
+set_target_properties(LocalWithArgsKeywordExe PROPERTIES
+ IMPORTED_LOCATION "${CMAKE_COMMAND}"
+)
+
+set(LocalWithArgsKeyword_FOUND TRUE)
diff --git a/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindLocalWithoutArgsKeyword.cmake b/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindLocalWithoutArgsKeyword.cmake
new file mode 100644
index 0000000000..523fecdf48
--- /dev/null
+++ b/Tests/RunCMake/FetchContent_find_package/PackageFindModules/FindLocalWithoutArgsKeyword.cmake
@@ -0,0 +1,6 @@
+add_executable(LocalWithoutArgsKeywordExe IMPORTED)
+set_target_properties(LocalWithoutArgsKeywordExe PROPERTIES
+ IMPORTED_LOCATION "${CMAKE_COMMAND}"
+)
+
+set(LocalWithoutArgsKeyword_FOUND TRUE)
diff --git a/Tests/RunCMake/FetchContent_find_package/RunCMakeTest.cmake b/Tests/RunCMake/FetchContent_find_package/RunCMakeTest.cmake
index c139f5780b..83c0a9a5ff 100644
--- a/Tests/RunCMake/FetchContent_find_package/RunCMakeTest.cmake
+++ b/Tests/RunCMake/FetchContent_find_package/RunCMakeTest.cmake
@@ -20,3 +20,4 @@ run_cmake(Try_find_package-NEVER)
run_cmake(Try_find_package-OPT_IN)
run_cmake(Try_find_package-BOGUS)
run_cmake(Redirect_find_package_MODULE)
+run_cmake(GLOBAL)