mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-24 19:59:47 +08:00
Tests: Add tests for CPS find_package
Add several tests for the new CPS support in find_package. While not exhaustive, there is some coverage for both search and import functions.
This commit is contained in:
committed by
Brad King
parent
65429611b9
commit
d00201afd6
@@ -20,6 +20,7 @@ add_executable(FindPackageCpsTest FindPackageTest.cxx)
|
||||
|
||||
###############################################################################
|
||||
# Test a basic package search.
|
||||
# It should NOT find the package's CMake package file.
|
||||
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
find_package(Sample CONFIG)
|
||||
@@ -38,3 +39,87 @@ elseif(NOT Sample_VERSION_TWEAK EQUAL 0)
|
||||
endif()
|
||||
|
||||
set(CMAKE_PREFIX_PATH)
|
||||
|
||||
###############################################################################
|
||||
# Test glob sorting.
|
||||
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
set(SortLib_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
|
||||
set(CMAKE_FIND_PACKAGE_SORT_ORDER NAME)
|
||||
set(CMAKE_FIND_PACKAGE_SORT_DIRECTION ASC)
|
||||
find_package(SortLib CONFIG)
|
||||
if(NOT "${SortLib_VERSION}" STREQUAL "3.1.1")
|
||||
message(SEND_ERROR "FIND_PACKAGE_SORT_ORDER Name Asc! ${SortLib_VERSION}")
|
||||
endif()
|
||||
unset(SortLib_VERSION)
|
||||
|
||||
set(SortLib_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
|
||||
set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
|
||||
set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
|
||||
find_package(SortLib CONFIG)
|
||||
if(NOT "${SortLib_VERSION}" STREQUAL "3.10.1")
|
||||
message(SEND_ERROR "FIND_PACKAGE_SORT_ORDER Natural! Dec ${SortLib_VERSION}")
|
||||
endif()
|
||||
set(SortLib_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
|
||||
unset(SortLib_VERSION)
|
||||
|
||||
# TODO Add this test once CPS version checking is implemented.
|
||||
# set(SortLib_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
|
||||
# FIND_PACKAGE(SortLib 4.0 CONFIG)
|
||||
# IF (NOT "${SortLib_VERSION}" STREQUAL "4.0.0")
|
||||
# message(SEND_ERROR "FIND_PACKAGE_SORT_ORDER gave up too soon! ${SortLib_VERSION}")
|
||||
# endif()
|
||||
# unset(SortLib_VERSION)
|
||||
|
||||
set(SortFramework_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
|
||||
set(CMAKE_FIND_PACKAGE_SORT_ORDER NAME)
|
||||
set(CMAKE_FIND_PACKAGE_SORT_DIRECTION ASC)
|
||||
find_package(SortFramework CONFIG)
|
||||
if(NOT "${SortFramework_VERSION}" STREQUAL "3.1.1")
|
||||
message(SEND_ERROR "FIND_PACKAGE_SORT_ORDER Framework Name Asc! ${SortFramework_VERSION}")
|
||||
endif()
|
||||
set(SortLib_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
|
||||
unset(SortFramework_VERSION)
|
||||
|
||||
set(SortFramework_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
|
||||
set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
|
||||
set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
|
||||
find_package(SortFramework CONFIG)
|
||||
if(NOT "${SortFramework_VERSION}" STREQUAL "3.10.1")
|
||||
message(SEND_ERROR "FIND_PACKAGE_SORT_ORDER Framework Natural! Dec ${SortFramework_VERSION}")
|
||||
endif()
|
||||
set(SortLib_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
|
||||
unset(SortFramework_VERSION)
|
||||
|
||||
unset(CMAKE_FIND_PACKAGE_SORT_ORDER)
|
||||
unset(CMAKE_FIND_PACKAGE_SORT_DIRECTION)
|
||||
set(CMAKE_PREFIX_PATH)
|
||||
|
||||
###############################################################################
|
||||
# Find a package that actually has some content.
|
||||
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
find_package(Foo CONFIG)
|
||||
if(NOT Foo_FOUND)
|
||||
message(SEND_ERROR "Foo not found !")
|
||||
elseif(NOT TARGET Foo::PrefixTest)
|
||||
message(SEND_ERROR "Foo::PrefixTest missing !")
|
||||
elseif(NOT TARGET Foo::RelativeTest)
|
||||
message(SEND_ERROR "Foo::RelativeTest missing !")
|
||||
elseif(NOT TARGET Foo::Empty)
|
||||
message(SEND_ERROR "Foo::Empty missing !")
|
||||
else()
|
||||
get_property(pt_includes
|
||||
TARGET Foo::PrefixTest PROPERTY INTERFACE_INCLUDE_DIRECTORIES_DEFAULT)
|
||||
if(NOT "${CMAKE_CURRENT_SOURCE_DIR}/include" PATH_EQUAL "${pt_includes}")
|
||||
message(SEND_ERROR "Foo::PrefixTest has wrong includes '${pt_includes}' !")
|
||||
endif()
|
||||
set(pt_includes)
|
||||
|
||||
get_property(rt_includes
|
||||
TARGET Foo::RelativeTest PROPERTY INTERFACE_INCLUDE_DIRECTORIES_DEFAULT)
|
||||
if(NOT "${CMAKE_CURRENT_SOURCE_DIR}/cps/../include" PATH_EQUAL "${rt_includes}")
|
||||
message(SEND_ERROR "Foo::RelativeTest has wrong includes '${rt_includes}' !")
|
||||
endif()
|
||||
set(rt_includes)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"cps_version": "0.13",
|
||||
"name": "SortFramework",
|
||||
"version": "3.1.1",
|
||||
"cps_path": "@prefix@/Resources/CPS",
|
||||
"components": {}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"cps_version": "0.13",
|
||||
"name": "SortFramework",
|
||||
"version": "3.10.1",
|
||||
"cps_path": "@prefix@/Resources/CPS",
|
||||
"components": {}
|
||||
}
|
||||
2
Tests/FindPackageCpsTest/cmake/SampleConfig.cmake
Normal file
2
Tests/FindPackageCpsTest/cmake/SampleConfig.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
set(Sample_FOUND TRUE)
|
||||
set(Sample_VERSION 1.0)
|
||||
7
Tests/FindPackageCpsTest/cps/SortLib/3.1.1/SortLib.cps
Normal file
7
Tests/FindPackageCpsTest/cps/SortLib/3.1.1/SortLib.cps
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"cps_version": "0.13",
|
||||
"name": "SortLib",
|
||||
"version": "3.1.1",
|
||||
"cps_path": "@prefix@/cps/SortLib/3.1.1",
|
||||
"components": {}
|
||||
}
|
||||
7
Tests/FindPackageCpsTest/cps/SortLib/3.10.1/SortLib.cps
Normal file
7
Tests/FindPackageCpsTest/cps/SortLib/3.10.1/SortLib.cps
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"cps_version": "0.13",
|
||||
"name": "SortLib",
|
||||
"version": "3.10.1",
|
||||
"cps_path": "@prefix@/cps/SortLib/3.10.1",
|
||||
"components": {}
|
||||
}
|
||||
9
Tests/FindPackageCpsTest/cps/foo-relative.cps
Normal file
9
Tests/FindPackageCpsTest/cps/foo-relative.cps
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"cps_version": "0.13",
|
||||
"name": "Foo",
|
||||
"components": {
|
||||
"RelativeTest": {
|
||||
"type": "interface"
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Tests/FindPackageCpsTest/cps/foo-relative@default.cps
Normal file
10
Tests/FindPackageCpsTest/cps/foo-relative@default.cps
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"cps_version": "0.13",
|
||||
"name": "Foo",
|
||||
"configuration": "default",
|
||||
"components": {
|
||||
"RelativeTest": {
|
||||
"includes": ["../include"]
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Tests/FindPackageCpsTest/cps/foo.cps
Normal file
14
Tests/FindPackageCpsTest/cps/foo.cps
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"cps_version": "0.13",
|
||||
"name": "Foo",
|
||||
"cps_path": "@prefix@/cps",
|
||||
"default_configurations": ["default"],
|
||||
"components": {
|
||||
"PrefixTest": {
|
||||
"type": "interface"
|
||||
},
|
||||
"Empty": {
|
||||
"type": "interface"
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Tests/FindPackageCpsTest/cps/foo@default.cps
Normal file
10
Tests/FindPackageCpsTest/cps/foo@default.cps
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"cps_version": "0.13",
|
||||
"name": "Foo",
|
||||
"configuration": "default",
|
||||
"components": {
|
||||
"PrefixTest": {
|
||||
"includes": ["@prefix@/include"]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user