Add find_package overrides that also work in CONFIG mode (#498) (#604)

This commit is contained in:
Patrick Stewart
2024-12-21 00:38:22 +09:00
committed by GitHub
parent 0bc73f41ce
commit 9ddfe1b6a8
5 changed files with 60 additions and 23 deletions

View File

@@ -3,7 +3,8 @@ include(${CPM_PATH}/testing.cmake)
set(TEST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/modules)
function(init_project_with_dependency TEST_DEPENDENCY_NAME)
function(init_project_with_dependency TEST_DEPENDENCY_NAME TEST_CANT_FIND_PACKAGE_NAME)
set(TEST_FIND_PACKAGE ON)
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/local_dependency/ModuleCMakeLists.txt.in"
"${CMAKE_CURRENT_LIST_DIR}/local_dependency/CMakeLists.txt"
@@ -18,11 +19,17 @@ function(init_project_with_dependency TEST_DEPENDENCY_NAME)
assert_equal(${ret} "0")
endfunction()
init_project_with_dependency(A)
assert_exists(${TEST_BUILD_DIR}/CPM_modules)
assert_exists(${TEST_BUILD_DIR}/CPM_modules/FindA.cmake)
assert_not_exists(${TEST_BUILD_DIR}/CPM_modules/FindB.cmake)
init_project_with_dependency(A B)
init_project_with_dependency(B A)
init_project_with_dependency(B)
assert_not_exists(${TEST_BUILD_DIR}/CPM_modules/FindA.cmake)
assert_exists(${TEST_BUILD_DIR}/CPM_modules/FindB.cmake)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0")
set(TEST_FIND_PACKAGE_CONFIG CONFIG)
init_project_with_dependency(A B)
init_project_with_dependency(B A)
# Test the fallback path for CMake <3.24 works
set(TEST_FIND_PACKAGE_CONFIG)
set(TEST_FORCE_MODULE_MODE ON)
init_project_with_dependency(A B)
init_project_with_dependency(B A)
endif()