mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-09 07:11:05 -06:00
install(EXPORT): Use UNWIND_INCLUDE in exported find_dependency()
This commit is contained in:
@@ -451,16 +451,27 @@ void cmExportCMakeConfigGenerator::GenerateFindDependencyCalls(
|
||||
return lhs.second.FindPackageIndex < rhs.second.FindPackageIndex;
|
||||
});
|
||||
|
||||
// Unwinding is only valid in a find_package() context
|
||||
os << "if(DEFINED CMAKE_FIND_PACKAGE_NAME)\n"
|
||||
<< " set(_cmake_unwind_arg UNWIND_INCLUDE)\n"
|
||||
<< "endif()\n\n";
|
||||
|
||||
for (auto const& it : packageDependenciesSorted) {
|
||||
if (it.second.Enabled == cmExportSet::PackageDependencyExportEnabled::On) {
|
||||
os << "find_dependency(" << it.first;
|
||||
os << "__find_dependency_no_return(" << it.first;
|
||||
for (auto const& arg : it.second.ExtraArguments) {
|
||||
os << ' ' << cmOutputConverter::EscapeForCMake(arg);
|
||||
}
|
||||
os << ")\n";
|
||||
os << " ${_cmake_unwind_arg})\n";
|
||||
os << "if(NOT " << it.first << "_FOUND)\n"
|
||||
<< " unset(_cmake_unwind_arg)\n"
|
||||
<< " cmake_policy(POP)\n"
|
||||
<< " return()\n"
|
||||
<< "endif()\n\n";
|
||||
}
|
||||
}
|
||||
os << "\n\n";
|
||||
|
||||
os << "unset(_cmake_unwind_arg)\n\n\n";
|
||||
}
|
||||
|
||||
void cmExportCMakeConfigGenerator::GenerateMissingTargetsCheckCode(
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
file(READ "${RunCMake_TEST_BINARY_DIR}/mytargets.cmake" mytargets)
|
||||
if("${mytargets}" MATCHES "find_dependency\\(P1")
|
||||
if("${mytargets}" MATCHES "__find_dependency_no_return\\(P1")
|
||||
string(APPEND RunCMake_TEST_FAILED "P1 dependency should not be exported but it is\n")
|
||||
endif()
|
||||
if(NOT "${mytargets}" MATCHES "find_dependency\\(P2 \"VERSION\" \"1\\.0\"\\)")
|
||||
if(NOT "${mytargets}" MATCHES "__find_dependency_no_return\\(P2")
|
||||
string(APPEND RunCMake_TEST_FAILED "P2 dependency should be exported but it is not\n")
|
||||
endif()
|
||||
if(NOT "${mytargets}" MATCHES "find_dependency\\(P3\\)")
|
||||
if(NOT "${mytargets}" MATCHES "__find_dependency_no_return\\(P3")
|
||||
string(APPEND RunCMake_TEST_FAILED "P3 dependency should be exported but it is not\n")
|
||||
endif()
|
||||
if(NOT "${mytargets}" MATCHES "find_dependency\\(P4\\)")
|
||||
if(NOT "${mytargets}" MATCHES "__find_dependency_no_return\\(P4")
|
||||
string(APPEND RunCMake_TEST_FAILED "P4 dependency should be exported but it is not\n")
|
||||
endif()
|
||||
if("${mytargets}" MATCHES "find_dependency\\(P5")
|
||||
if("${mytargets}" MATCHES "__find_dependency_no_return\\(P5")
|
||||
string(APPEND RunCMake_TEST_FAILED "P5 dependency should not be exported but it is\n")
|
||||
endif()
|
||||
if(NOT "${mytargets}" MATCHES "find_dependency\\(P6\\)")
|
||||
if(NOT "${mytargets}" MATCHES "__find_dependency_no_return\\(P6")
|
||||
string(APPEND RunCMake_TEST_FAILED "P6 dependency should be exported but it is not\n")
|
||||
endif()
|
||||
if("${mytargets}" MATCHES "find_dependency\\(P7")
|
||||
if("${mytargets}" MATCHES "__find_dependency_no_return\\(P7")
|
||||
string(APPEND RunCMake_TEST_FAILED "P7 dependency should not be exported but it is\n")
|
||||
endif()
|
||||
if(NOT "${mytargets}" MATCHES "find_dependency\\(P3[^
|
||||
]*\\)
|
||||
find_dependency\\(P2[^
|
||||
]*\\)
|
||||
find_dependency\\(P8[^
|
||||
]*\\)
|
||||
find_dependency\\(P6[^
|
||||
]*\\)
|
||||
find_dependency\\(P9[^
|
||||
]*\\)
|
||||
find_dependency\\(P4")
|
||||
if(NOT "${mytargets}" MATCHES "__find_dependency_no_return\\(P3[^
|
||||
]*\\)(.*)
|
||||
__find_dependency_no_return\\(P2[^
|
||||
]*\\)(.*)
|
||||
__find_dependency_no_return\\(P8[^
|
||||
]*\\)(.*)
|
||||
__find_dependency_no_return\\(P6[^
|
||||
]*\\)(.*)
|
||||
__find_dependency_no_return\\(P9[^
|
||||
]*\\)(.*)
|
||||
__find_dependency_no_return\\(P4")
|
||||
string(APPEND RunCMake_TEST_FAILED "Dependencies are not in the correct order\n")
|
||||
endif()
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
file(READ "${RunCMake_TEST_BINARY_DIR}/mytargets.cmake" mytargets)
|
||||
if(NOT "${mytargets}" MATCHES "find_dependency\\(P1")
|
||||
if(NOT "${mytargets}" MATCHES "__find_dependency_no_return\\(P1")
|
||||
string(APPEND RunCMake_TEST_FAILED "P1 dependency should be exported but it is not\n")
|
||||
endif()
|
||||
if(NOT "${mytargets}" MATCHES "find_dependency\\(P2")
|
||||
if(NOT "${mytargets}" MATCHES "__find_dependency_no_return\\(P2")
|
||||
string(APPEND RunCMake_TEST_FAILED "P2 dependency should be exported but it is not\n")
|
||||
endif()
|
||||
if(NOT "${mytargets}" MATCHES "find_dependency\\(P3")
|
||||
if(NOT "${mytargets}" MATCHES "__find_dependency_no_return\\(P3")
|
||||
string(APPEND RunCMake_TEST_FAILED "P3 dependency should be exported but it is not\n")
|
||||
endif()
|
||||
if(NOT "${mytargets}" MATCHES "find_dependency\\(P4")
|
||||
if(NOT "${mytargets}" MATCHES "__find_dependency_no_return\\(P4")
|
||||
string(APPEND RunCMake_TEST_FAILED "P4 dependency should be exported but it is not\n")
|
||||
endif()
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
file(READ "${RunCMake_TEST_BINARY_DIR}/root-all/lib/cmake/mylib/mylib-targets.cmake" contents)
|
||||
if(NOT contents MATCHES "include\\(CMakeFindDependencyMacro\\)\nfind_dependency\\(P2\\)\nfind_dependency\\(P1\\)\n")
|
||||
set(RunCMake_TEST_FAILED "Dependencies were not properly exported")
|
||||
|
||||
if(NOT contents MATCHES "__find_dependency_no_return\\(P2")
|
||||
string(APPEND RunCMake_TEST_FAILED "P2 dependency should be exported but it is not\n")
|
||||
endif()
|
||||
|
||||
if(NOT contents MATCHES "__find_dependency_no_return\\(P1")
|
||||
string(APPEND RunCMake_TEST_FAILED "P1 dependency should be exported but it is not\n")
|
||||
endif()
|
||||
|
||||
if(NOT contents MATCHES "__find_dependency_no_return\\(P2[^
|
||||
]*\\)(.*)
|
||||
__find_dependency_no_return\\(P1")
|
||||
string(APPEND RunCMake_TEST_FAILED "Dependencies are not in the correct order\n")
|
||||
endif()
|
||||
|
||||
8
Tests/RunCMake/install/EXPORT-Unwind-all-check.cmake
Normal file
8
Tests/RunCMake/install/EXPORT-Unwind-all-check.cmake
Normal file
@@ -0,0 +1,8 @@
|
||||
cmake_policy(SET CMP0074 NEW)
|
||||
set(Unwind_ROOT "${RunCMake_TEST_BINARY_DIR}/root-all")
|
||||
|
||||
find_package(Unwind CONFIG QUIET)
|
||||
|
||||
if(Unwind_FOUND)
|
||||
set(RunCMake_TEST_FAILED "Unwinding failed, package was reported as found")
|
||||
endif()
|
||||
6
Tests/RunCMake/install/EXPORT-Unwind-stderr.txt
Normal file
6
Tests/RunCMake/install/EXPORT-Unwind-stderr.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
^CMake Warning \(dev\) at EXPORT-Unwind\.cmake:[0-9]+ \(install\):
|
||||
CMake's EXPORT_PACKAGE_DEPENDENCIES support is experimental\. It is meant
|
||||
only for experimentation and feedback to CMake developers\.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists\.txt:[0-9]+ \(include\)
|
||||
This warning is for project developers\. Use -Wno-dev to suppress it\.$
|
||||
12
Tests/RunCMake/install/EXPORT-Unwind.cmake
Normal file
12
Tests/RunCMake/install/EXPORT-Unwind.cmake
Normal file
@@ -0,0 +1,12 @@
|
||||
set(CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_DEPENDENCIES "1942b4fa-b2c5-4546-9385-83f254070067")
|
||||
enable_language(C)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
find_package(P1 REQUIRED)
|
||||
|
||||
add_library(Unwind INTERFACE)
|
||||
target_link_libraries(Unwind INTERFACE lib1)
|
||||
install(TARGETS Unwind EXPORT UnwindTargets)
|
||||
install(EXPORT UnwindTargets EXPORT_PACKAGE_DEPENDENCIES DESTINATION lib/cmake/Unwind)
|
||||
install(FILES cmake/UnwindConfig.cmake DESTINATION lib/cmake/Unwind)
|
||||
@@ -189,6 +189,7 @@ run_install_test(FILES-PERMISSIONS)
|
||||
run_install_test(TARGETS-RPATH)
|
||||
run_install_test(InstallRequiredSystemLibraries)
|
||||
run_install_test(EXPORT-FindDependencyExport)
|
||||
run_install_test(EXPORT-Unwind)
|
||||
|
||||
set(RunCMake_TEST_OPTIONS "-DCMAKE_POLICY_DEFAULT_CMP0087:STRING=NEW")
|
||||
run_install_test(SCRIPT)
|
||||
|
||||
2
Tests/RunCMake/install/cmake/UnwindConfig.cmake
Normal file
2
Tests/RunCMake/install/cmake/UnwindConfig.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/UnwindTargets.cmake)
|
||||
set(Unwind_FOUND true)
|
||||
Reference in New Issue
Block a user