diff options
author | Matthew Woehlke <matthew.woehlke@kitware.com> | 2024-08-01 18:59:47 (GMT) |
---|---|---|
committer | Matthew Woehlke <matthew.woehlke@kitware.com> | 2024-08-14 19:25:27 (GMT) |
commit | 1a846c8849c47f5871afaed68468de26d49af29e (patch) | |
tree | 8e77bb7635e4189bf892c76958f031eb80dbc37e /Tests/RunCMake/PackageInfo | |
parent | 3d52d70b84b114adf36a176c6f05aa0f42b1326f (diff) | |
download | CMake-1a846c8849c47f5871afaed68468de26d49af29e.zip CMake-1a846c8849c47f5871afaed68468de26d49af29e.tar.gz CMake-1a846c8849c47f5871afaed68468de26d49af29e.tar.bz2 |
Tests: Add tests for install(PACKAGE_INFO)
Add several test cases to verify that install(PACKAGE_INFO) is working
as expected. These cover validating the output for several scenarios,
improper use of the command, effects of command arguments, and a handful
of improper uses.
Tests that should still be added include one covering DESTINATION (both
the default and user-specified) and the CPS location and link_location
attributes. These have been skipped for now because the former requires
actually installing a test project, and the latter involves validating
attributes whose values are platform-dependent. (In particular, I don't
think link_location will appear on not-Windows.) Additionally, there is
no coverage of (other) common install-command arguments such as
PERMISSIONS, COMPONENT, etc.; however, because the logic implementing
these is shared, the tests covering them for other sub-commands is
probably sufficient.
Note that, because the files are generated in a location that includes a
hash of the install destination, and because the default destination is
platform dependent, the tests need to specify a fixed DESTINATION so
that the location of generated files (which we need to inspect and
validate) is predictable.
Diffstat (limited to 'Tests/RunCMake/PackageInfo')
56 files changed, 393 insertions, 0 deletions
diff --git a/Tests/RunCMake/PackageInfo/Appendix-check.cmake b/Tests/RunCMake/PackageInfo/Appendix-check.cmake new file mode 100644 index 0000000..864e731 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/Appendix-check.cmake @@ -0,0 +1,16 @@ +include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake) + +set(out_dir "${RunCMake_BINARY_DIR}/Appendix-build/CMakeFiles/Export/510c5684a4a8a792eadfb55bc9744983") + +file(READ "${out_dir}/foo.cps" content) +expect_value("${content}" "foo" "name") +expect_value("${content}" "interface" "components" "mammal" "type") +expect_value("${content}" "1.0" "version") + +file(READ "${out_dir}/foo-dog.cps" content) +expect_value("${content}" "foo" "name") +expect_value("${content}" "interface" "components" "canine" "type") +expect_missing("${content}" "version") + +expect_array("${content}" 1 "components" "canine" "requires") +expect_value("${content}" ":mammal" "components" "canine" "requires" 0) diff --git a/Tests/RunCMake/PackageInfo/Appendix.cmake b/Tests/RunCMake/PackageInfo/Appendix.cmake new file mode 100644 index 0000000..fe67778 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/Appendix.cmake @@ -0,0 +1,9 @@ +add_library(mammal INTERFACE) +add_library(canine INTERFACE) +target_link_libraries(canine INTERFACE mammal) + +install(TARGETS mammal EXPORT mammal DESTINATION .) +install(TARGETS canine EXPORT canine DESTINATION .) + +install(PACKAGE_INFO foo DESTINATION cps EXPORT mammal VERSION 1.0) +install(PACKAGE_INFO foo DESTINATION cps EXPORT canine APPENDIX dog) diff --git a/Tests/RunCMake/PackageInfo/Assertions.cmake b/Tests/RunCMake/PackageInfo/Assertions.cmake new file mode 100644 index 0000000..8157618 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/Assertions.cmake @@ -0,0 +1,34 @@ +macro(_expect entity op actual expected) + if(NOT "${actual}" ${op} "${expected}") + list(JOIN ARGN "." name) + set(RunCMake_TEST_FAILED + "Attribute '${name}' ${entity} '${actual}' does not match expected ${entity} '${expected}'" PARENT_SCOPE) + return() + endif() +endmacro() + +function(expect_value content expected_value) + string(JSON actual_value GET "${content}" ${ARGN}) + _expect("value" STREQUAL "${actual_value}" "${expected_value}" ${ARGN}) +endfunction() + +function(expect_array content expected_length) + string(JSON actual_type TYPE "${content}" ${ARGN}) + _expect("type" STREQUAL "${actual_type}" "ARRAY" ${ARGN}) + + string(JSON actual_length LENGTH "${content}" ${ARGN}) + _expect("length" EQUAL "${actual_length}" "${expected_length}" ${ARGN}) +endfunction() + +function(expect_null content) + string(JSON actual_type TYPE "${content}" ${ARGN}) + _expect("type" STREQUAL "${actual_type}" "NULL" ${ARGN}) +endfunction() + +function(expect_missing content) + string(JSON value ERROR_VARIABLE error GET "${content}" ${ARGN}) + if(NOT value MATCHES "^(.*-)?NOTFOUND$") + set(RunCMake_TEST_FAILED + "Attribute '${ARGN}' is unexpectedly present" PARENT_SCOPE) + endif() +endfunction() diff --git a/Tests/RunCMake/PackageInfo/BadArgs1-result.txt b/Tests/RunCMake/PackageInfo/BadArgs1-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/PackageInfo/BadArgs1-stderr.txt b/Tests/RunCMake/PackageInfo/BadArgs1-stderr.txt new file mode 100644 index 0000000..92ba6fb --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs1-stderr.txt @@ -0,0 +1,2 @@ +CMake Error at BadArgs1.cmake:3 \(install\): + install COMPAT_VERSION requires VERSION. diff --git a/Tests/RunCMake/PackageInfo/BadArgs1.cmake b/Tests/RunCMake/PackageInfo/BadArgs1.cmake new file mode 100644 index 0000000..b99997c --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs1.cmake @@ -0,0 +1,3 @@ +add_library(foo INTERFACE) +install(TARGETS foo EXPORT foo DESTINATION .) +install(PACKAGE_INFO test EXPORT foo COMPAT_VERSION 1.0) diff --git a/Tests/RunCMake/PackageInfo/BadArgs2-result.txt b/Tests/RunCMake/PackageInfo/BadArgs2-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/PackageInfo/BadArgs2-stderr.txt b/Tests/RunCMake/PackageInfo/BadArgs2-stderr.txt new file mode 100644 index 0000000..636335c --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs2-stderr.txt @@ -0,0 +1,2 @@ +CMake Error at BadArgs2.cmake:3 \(install\): + install VERSION_SCHEMA requires VERSION. diff --git a/Tests/RunCMake/PackageInfo/BadArgs2.cmake b/Tests/RunCMake/PackageInfo/BadArgs2.cmake new file mode 100644 index 0000000..265d93c --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs2.cmake @@ -0,0 +1,3 @@ +add_library(foo INTERFACE) +install(TARGETS foo EXPORT foo DESTINATION .) +install(PACKAGE_INFO test EXPORT foo VERSION_SCHEMA simple) diff --git a/Tests/RunCMake/PackageInfo/BadArgs3-result.txt b/Tests/RunCMake/PackageInfo/BadArgs3-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs3-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/PackageInfo/BadArgs3-stderr.txt b/Tests/RunCMake/PackageInfo/BadArgs3-stderr.txt new file mode 100644 index 0000000..11e1a8c --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs3-stderr.txt @@ -0,0 +1,2 @@ +CMake Error at BadArgs3.cmake:3 \(install\): + install APPENDIX and VERSION are mutually exclusive. diff --git a/Tests/RunCMake/PackageInfo/BadArgs3.cmake b/Tests/RunCMake/PackageInfo/BadArgs3.cmake new file mode 100644 index 0000000..5f57f6a --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs3.cmake @@ -0,0 +1,3 @@ +add_library(foo INTERFACE) +install(TARGETS foo EXPORT foo DESTINATION .) +install(PACKAGE_INFO test EXPORT foo APPENDIX test VERSION 1.0) diff --git a/Tests/RunCMake/PackageInfo/BadArgs4-result.txt b/Tests/RunCMake/PackageInfo/BadArgs4-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs4-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/PackageInfo/BadArgs4-stderr.txt b/Tests/RunCMake/PackageInfo/BadArgs4-stderr.txt new file mode 100644 index 0000000..067a07b --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs4-stderr.txt @@ -0,0 +1,2 @@ +CMake Error at BadArgs4.cmake:3 \(install\): + install APPENDIX and DEFAULT_TARGETS are mutually exclusive. diff --git a/Tests/RunCMake/PackageInfo/BadArgs4.cmake b/Tests/RunCMake/PackageInfo/BadArgs4.cmake new file mode 100644 index 0000000..426d10b --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs4.cmake @@ -0,0 +1,3 @@ +add_library(foo INTERFACE) +install(TARGETS foo EXPORT foo DESTINATION .) +install(PACKAGE_INFO test EXPORT foo APPENDIX test DEFAULT_TARGETS foo) diff --git a/Tests/RunCMake/PackageInfo/BadArgs5-result.txt b/Tests/RunCMake/PackageInfo/BadArgs5-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs5-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/PackageInfo/BadArgs5-stderr.txt b/Tests/RunCMake/PackageInfo/BadArgs5-stderr.txt new file mode 100644 index 0000000..4f7d285 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs5-stderr.txt @@ -0,0 +1,2 @@ +CMake Error at BadArgs5.cmake:3 \(install\): + install APPENDIX and DEFAULT_CONFIGURATIONS are mutually exclusive. diff --git a/Tests/RunCMake/PackageInfo/BadArgs5.cmake b/Tests/RunCMake/PackageInfo/BadArgs5.cmake new file mode 100644 index 0000000..356c856 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadArgs5.cmake @@ -0,0 +1,3 @@ +add_library(foo INTERFACE) +install(TARGETS foo EXPORT foo DESTINATION .) +install(PACKAGE_INFO test EXPORT foo APPENDIX test DEFAULT_CONFIGURATIONS test) diff --git a/Tests/RunCMake/PackageInfo/BadDefaultTarget-result.txt b/Tests/RunCMake/PackageInfo/BadDefaultTarget-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadDefaultTarget-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/PackageInfo/BadDefaultTarget-stderr.txt b/Tests/RunCMake/PackageInfo/BadDefaultTarget-stderr.txt new file mode 100644 index 0000000..6467a14 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadDefaultTarget-stderr.txt @@ -0,0 +1,2 @@ +CMake Error: Package "test" specifies DEFAULT_TARGETS "dog", which is not a target in the export set "foo". +CMake Error: Package "test" specifies DEFAULT_TARGETS "cat", which is not a target in the export set "foo". diff --git a/Tests/RunCMake/PackageInfo/BadDefaultTarget.cmake b/Tests/RunCMake/PackageInfo/BadDefaultTarget.cmake new file mode 100644 index 0000000..d3d993a --- /dev/null +++ b/Tests/RunCMake/PackageInfo/BadDefaultTarget.cmake @@ -0,0 +1,5 @@ +add_library(foo INTERFACE) +add_library(dog INTERFACE) +install(TARGETS foo EXPORT foo DESTINATION .) +install(TARGETS dog EXPORT dog DESTINATION .) +install(PACKAGE_INFO test EXPORT foo DEFAULT_TARGETS dog cat) diff --git a/Tests/RunCMake/PackageInfo/CMakeLists.txt b/Tests/RunCMake/PackageInfo/CMakeLists.txt new file mode 100644 index 0000000..dda37d8 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.30) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/PackageInfo/ExperimentalGate-result.txt b/Tests/RunCMake/PackageInfo/ExperimentalGate-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ExperimentalGate-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/PackageInfo/ExperimentalGate-stderr.txt b/Tests/RunCMake/PackageInfo/ExperimentalGate-stderr.txt new file mode 100644 index 0000000..40799b7 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ExperimentalGate-stderr.txt @@ -0,0 +1,2 @@ +CMake Error at ExperimentalGate.cmake:5 \(install\): + install does not recognize sub-command PACKAGE_INFO diff --git a/Tests/RunCMake/PackageInfo/ExperimentalGate.cmake b/Tests/RunCMake/PackageInfo/ExperimentalGate.cmake new file mode 100644 index 0000000..327d3bb --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ExperimentalGate.cmake @@ -0,0 +1,5 @@ +unset(CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO) + +add_library(foo INTERFACE) +install(TARGETS foo EXPORT foo DESTINATION .) +install(PACKAGE_INFO foo DESTINATION cps EXPORT foo) diff --git a/Tests/RunCMake/PackageInfo/ExperimentalWarning-stderr.txt b/Tests/RunCMake/PackageInfo/ExperimentalWarning-stderr.txt new file mode 100644 index 0000000..960d541 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ExperimentalWarning-stderr.txt @@ -0,0 +1,7 @@ +CMake Warning \(dev\) at ExperimentalWarning.cmake:8 \(install\): + CMake's support for exporting package information in the Common Package + Specification format. It is meant only for experimentation and feedback to + CMake developers. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/PackageInfo/ExperimentalWarning.cmake b/Tests/RunCMake/PackageInfo/ExperimentalWarning.cmake new file mode 100644 index 0000000..df6604c --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ExperimentalWarning.cmake @@ -0,0 +1,8 @@ +set( + CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO + "b80be207-778e-46ba-8080-b23bba22639e" + ) + +add_library(foo INTERFACE) +install(TARGETS foo EXPORT foo DESTINATION .) +install(PACKAGE_INFO foo DESTINATION cps EXPORT foo) diff --git a/Tests/RunCMake/PackageInfo/InterfaceProperties-check.cmake b/Tests/RunCMake/PackageInfo/InterfaceProperties-check.cmake new file mode 100644 index 0000000..2c3272e --- /dev/null +++ b/Tests/RunCMake/PackageInfo/InterfaceProperties-check.cmake @@ -0,0 +1,24 @@ +include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake) + +set(out_dir "${RunCMake_BINARY_DIR}/InterfaceProperties-build/CMakeFiles/Export/510c5684a4a8a792eadfb55bc9744983") + +file(READ "${out_dir}/foo.cps" content) +expect_value("${content}" "foo" "name") + +string(JSON component GET "${content}" "components" "foo") + +expect_value("${component}" "interface" "type") +expect_array("${component}" 1 "includes") +expect_value("${component}" "@prefix@/include/foo" "includes" 0) +expect_array("${component}" 1 "compile_features") +expect_value("${component}" "c++23" "compile_features" 0) +expect_array("${component}" 1 "compile_flags") +expect_value("${component}" "-ffast-math" "compile_flags" 0) +expect_null("${component}" "compile_definitions" "*" "FOO") +expect_value("${component}" "BAR" "compile_definitions" "*" "BAR") +expect_array("${component}" 1 "link_directories") +expect_value("${component}" "/opt/foo/lib" "link_directories" 0) +expect_array("${component}" 1 "link_flags") +expect_value("${component}" "--needed" "link_flags" 0) +expect_array("${component}" 1 "link_libraries") +expect_value("${component}" "/usr/lib/libm.so" "link_libraries" 0) diff --git a/Tests/RunCMake/PackageInfo/InterfaceProperties.cmake b/Tests/RunCMake/PackageInfo/InterfaceProperties.cmake new file mode 100644 index 0000000..42edc21 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/InterfaceProperties.cmake @@ -0,0 +1,15 @@ +add_library(foo INTERFACE) + +target_compile_features(foo INTERFACE cxx_std_23) +target_compile_options(foo INTERFACE -ffast-math) +target_compile_definitions(foo INTERFACE -DFOO -DBAR=BAR) +target_include_directories( + foo INTERFACE + $<INSTALL_INTERFACE:include/foo> + ) +target_link_directories(foo INTERFACE /opt/foo/lib) +target_link_options(foo INTERFACE --needed) +target_link_libraries(foo INTERFACE /usr/lib/libm.so) + +install(TARGETS foo EXPORT foo DESTINATION .) +install(PACKAGE_INFO foo DESTINATION cps EXPORT foo) diff --git a/Tests/RunCMake/PackageInfo/LowerCaseFile-check.cmake b/Tests/RunCMake/PackageInfo/LowerCaseFile-check.cmake new file mode 100644 index 0000000..d8de372 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/LowerCaseFile-check.cmake @@ -0,0 +1,9 @@ +include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake) + +set(out_dir "${RunCMake_BINARY_DIR}/LowerCaseFile-build/CMakeFiles/Export/510c5684a4a8a792eadfb55bc9744983") + +file(READ "${out_dir}/lowercase.cps" content) +expect_value("${content}" "LowerCase" "name") + +file(READ "${out_dir}/PreserveCase.cps" content) +expect_value("${content}" "PreserveCase" "name") diff --git a/Tests/RunCMake/PackageInfo/LowerCaseFile.cmake b/Tests/RunCMake/PackageInfo/LowerCaseFile.cmake new file mode 100644 index 0000000..dc6827f --- /dev/null +++ b/Tests/RunCMake/PackageInfo/LowerCaseFile.cmake @@ -0,0 +1,4 @@ +add_library(foo INTERFACE) +install(TARGETS foo EXPORT foo DESTINATION .) +install(PACKAGE_INFO LowerCase DESTINATION cps EXPORT foo LOWER_CASE_FILE) +install(PACKAGE_INFO PreserveCase DESTINATION cps EXPORT foo) diff --git a/Tests/RunCMake/PackageInfo/Metadata-check.cmake b/Tests/RunCMake/PackageInfo/Metadata-check.cmake new file mode 100644 index 0000000..8db8c29 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/Metadata-check.cmake @@ -0,0 +1,16 @@ +include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake) + +set(out_dir "${RunCMake_BINARY_DIR}/Metadata-build/CMakeFiles/Export/510c5684a4a8a792eadfb55bc9744983") + +file(READ "${out_dir}/foo.cps" content) +expect_value("${content}" "foo" "name") +expect_value("${content}" "1.2.3" "version") +expect_value("${content}" "1.2.0" "compat_version") +expect_value("${content}" "simple" "version_schema") + +expect_array("${content}" 1 "default_components") +expect_value("${content}" "foo" "default_components" 0) + +expect_array("${content}" 2 "configurations") +expect_value("${content}" "release" "configurations" 0) +expect_value("${content}" "debug" "configurations" 1) diff --git a/Tests/RunCMake/PackageInfo/Metadata.cmake b/Tests/RunCMake/PackageInfo/Metadata.cmake new file mode 100644 index 0000000..f8fc9b8 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/Metadata.cmake @@ -0,0 +1,12 @@ +add_library(foo INTERFACE) +install(TARGETS foo EXPORT foo DESTINATION .) +install( + PACKAGE_INFO foo + DESTINATION cps + EXPORT foo + VERSION 1.2.3 + VERSION_SCHEMA simple + COMPAT_VERSION 1.2.0 + DEFAULT_TARGETS foo + DEFAULT_CONFIGURATIONS release debug + ) diff --git a/Tests/RunCMake/PackageInfo/Minimal-check.cmake b/Tests/RunCMake/PackageInfo/Minimal-check.cmake new file mode 100644 index 0000000..9608ed8 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/Minimal-check.cmake @@ -0,0 +1,18 @@ +include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake) + +set(out_dir "${RunCMake_BINARY_DIR}/Minimal-build/CMakeFiles/Export/510c5684a4a8a792eadfb55bc9744983") + +file(READ "${out_dir}/foo.cps" content) +expect_value("${content}" "foo" "name") +expect_value("${content}" "interface" "components" "foo" "type") +expect_missing("${content}" "version") +expect_missing("${content}" "configurations") +expect_missing("${content}" "default_targets") +expect_missing("${content}" "components" "foo" "compile_definitions") +expect_missing("${content}" "components" "foo" "compile_features") +expect_missing("${content}" "components" "foo" "compile_flags") +expect_missing("${content}" "components" "foo" "link_directories") +expect_missing("${content}" "components" "foo" "link_features") +expect_missing("${content}" "components" "foo" "link_flags") +expect_missing("${content}" "components" "foo" "link_libraries") +expect_missing("${content}" "components" "foo" "requires") diff --git a/Tests/RunCMake/PackageInfo/Minimal.cmake b/Tests/RunCMake/PackageInfo/Minimal.cmake new file mode 100644 index 0000000..6c060b9 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/Minimal.cmake @@ -0,0 +1,3 @@ +add_library(foo INTERFACE) +install(TARGETS foo EXPORT foo DESTINATION .) +install(PACKAGE_INFO foo DESTINATION cps EXPORT foo) diff --git a/Tests/RunCMake/PackageInfo/ReferencesNonExportedTarget-result.txt b/Tests/RunCMake/PackageInfo/ReferencesNonExportedTarget-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ReferencesNonExportedTarget-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/PackageInfo/ReferencesNonExportedTarget-stderr.txt b/Tests/RunCMake/PackageInfo/ReferencesNonExportedTarget-stderr.txt new file mode 100644 index 0000000..c68d518 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ReferencesNonExportedTarget-stderr.txt @@ -0,0 +1 @@ +CMake Error: install\(PACKAGE_INFO "dog" \.\.\.\) includes target "canine" which requires target "mammal" that is not in any export set. diff --git a/Tests/RunCMake/PackageInfo/ReferencesNonExportedTarget.cmake b/Tests/RunCMake/PackageInfo/ReferencesNonExportedTarget.cmake new file mode 100644 index 0000000..a835582 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ReferencesNonExportedTarget.cmake @@ -0,0 +1,6 @@ +add_library(mammal INTERFACE) +add_library(canine INTERFACE) +target_link_libraries(canine INTERFACE mammal) + +install(TARGETS canine EXPORT dog DESTINATION .) +install(PACKAGE_INFO dog EXPORT dog) diff --git a/Tests/RunCMake/PackageInfo/ReferencesWronglyExportedTarget-result.txt b/Tests/RunCMake/PackageInfo/ReferencesWronglyExportedTarget-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ReferencesWronglyExportedTarget-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/PackageInfo/ReferencesWronglyExportedTarget-stderr.txt b/Tests/RunCMake/PackageInfo/ReferencesWronglyExportedTarget-stderr.txt new file mode 100644 index 0000000..0a74e18 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ReferencesWronglyExportedTarget-stderr.txt @@ -0,0 +1,7 @@ +CMake Error in CMakeLists.txt: + Target "test" references target "foo", which does not use the standard + namespace separator. This is not allowed. +.* +CMake Error in CMakeLists.txt: + Target "test" references target "bar_bar", which does not use the standard + namespace separator. This is not allowed. diff --git a/Tests/RunCMake/PackageInfo/ReferencesWronglyExportedTarget.cmake b/Tests/RunCMake/PackageInfo/ReferencesWronglyExportedTarget.cmake new file mode 100644 index 0000000..3e3d21d --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ReferencesWronglyExportedTarget.cmake @@ -0,0 +1,14 @@ +add_library(foo INTERFACE) +add_library(bar INTERFACE) + +add_library(test INTERFACE) +target_link_libraries(test INTERFACE foo bar) + +install(TARGETS foo EXPORT foo DESTINATION .) +install(TARGETS bar EXPORT bar DESTINATION .) + +install(EXPORT foo DESTINATION .) +install(EXPORT bar DESTINATION . NAMESPACE bar_) + +install(TARGETS test EXPORT test DESTINATION .) +install(PACKAGE_INFO test EXPORT test) diff --git a/Tests/RunCMake/PackageInfo/ReferencesWronglyImportedTarget-result.txt b/Tests/RunCMake/PackageInfo/ReferencesWronglyImportedTarget-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ReferencesWronglyImportedTarget-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/PackageInfo/ReferencesWronglyImportedTarget-stderr.txt b/Tests/RunCMake/PackageInfo/ReferencesWronglyImportedTarget-stderr.txt new file mode 100644 index 0000000..cc4e824 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ReferencesWronglyImportedTarget-stderr.txt @@ -0,0 +1,3 @@ +CMake Error in CMakeLists.txt: + Target "foo" references imported target "bar" which does not come from any + known package. diff --git a/Tests/RunCMake/PackageInfo/ReferencesWronglyImportedTarget.cmake b/Tests/RunCMake/PackageInfo/ReferencesWronglyImportedTarget.cmake new file mode 100644 index 0000000..8addd64 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ReferencesWronglyImportedTarget.cmake @@ -0,0 +1,7 @@ +add_library(bar INTERFACE IMPORTED) + +add_library(foo INTERFACE) +target_link_libraries(foo INTERFACE bar) + +install(TARGETS foo EXPORT foo DESTINATION .) +install(PACKAGE_INFO foo EXPORT foo) diff --git a/Tests/RunCMake/PackageInfo/ReferencesWronglyNamespacedTarget-result.txt b/Tests/RunCMake/PackageInfo/ReferencesWronglyNamespacedTarget-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ReferencesWronglyNamespacedTarget-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/PackageInfo/ReferencesWronglyNamespacedTarget-stderr.txt b/Tests/RunCMake/PackageInfo/ReferencesWronglyNamespacedTarget-stderr.txt new file mode 100644 index 0000000..0a6872e --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ReferencesWronglyNamespacedTarget-stderr.txt @@ -0,0 +1,4 @@ +CMake Error in CMakeLists.txt: + Target "foo" references target "wrong::lib", which comes from the "broken" + package, but does not belong to the package's canonical namespace. This is + not allowed. diff --git a/Tests/RunCMake/PackageInfo/ReferencesWronglyNamespacedTarget.cmake b/Tests/RunCMake/PackageInfo/ReferencesWronglyNamespacedTarget.cmake new file mode 100644 index 0000000..7a4f9c0 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/ReferencesWronglyNamespacedTarget.cmake @@ -0,0 +1,11 @@ +find_package( + broken REQUIRED CONFIG + NO_DEFAULT_PATH + PATHS ${CMAKE_CURRENT_LIST_DIR} + ) + +add_library(foo INTERFACE) +target_link_libraries(foo INTERFACE wrong::lib) + +install(TARGETS foo EXPORT foo DESTINATION .) +install(PACKAGE_INFO foo EXPORT foo) diff --git a/Tests/RunCMake/PackageInfo/Requirements-check.cmake b/Tests/RunCMake/PackageInfo/Requirements-check.cmake new file mode 100644 index 0000000..59a212f --- /dev/null +++ b/Tests/RunCMake/PackageInfo/Requirements-check.cmake @@ -0,0 +1,20 @@ +include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake) + +set(out_dir "${RunCMake_BINARY_DIR}/Requirements-build/CMakeFiles/Export/510c5684a4a8a792eadfb55bc9744983") + +file(READ "${out_dir}/foo.cps" content) +expect_value("${content}" "foo" "name") +expect_value("${content}" "interface" "components" "libb" "type") + +file(READ "${out_dir}/bar.cps" content) +expect_value("${content}" "bar" "name") +expect_null("${content}" "requires" "foo") +expect_null("${content}" "requires" "test") +expect_value("${content}" "interface" "components" "libc" "type") +expect_value("${content}" "interface" "components" "libd" "type") + +string(JSON component GET "${content}" "components" "libd") +expect_array("${component}" 3 "requires") +expect_value("${component}" "test:liba" "requires" 0) +expect_value("${component}" "foo:libb" "requires" 1) +expect_value("${component}" ":libc" "requires" 2) diff --git a/Tests/RunCMake/PackageInfo/Requirements.cmake b/Tests/RunCMake/PackageInfo/Requirements.cmake new file mode 100644 index 0000000..a4e947c --- /dev/null +++ b/Tests/RunCMake/PackageInfo/Requirements.cmake @@ -0,0 +1,20 @@ +find_package( + test REQUIRED CONFIG + NO_DEFAULT_PATH + PATHS ${CMAKE_CURRENT_LIST_DIR} + ) + +add_library(libb INTERFACE) +add_library(libc INTERFACE) +add_library(libd INTERFACE) + +add_library(foo ALIAS libb) +add_library(bar ALIAS libc) + +target_link_libraries(libd INTERFACE test::liba foo bar) + +install(TARGETS libb EXPORT foo DESTINATION .) +install(PACKAGE_INFO foo DESTINATION cps EXPORT foo) + +install(TARGETS libc libd EXPORT bar DESTINATION .) +install(PACKAGE_INFO bar DESTINATION cps EXPORT bar) diff --git a/Tests/RunCMake/PackageInfo/RunCMakeTest.cmake b/Tests/RunCMake/PackageInfo/RunCMakeTest.cmake new file mode 100644 index 0000000..54a32d5 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/RunCMakeTest.cmake @@ -0,0 +1,32 @@ +include(RunCMake) + +# Test experimental gate +run_cmake(ExperimentalGate) +run_cmake(ExperimentalWarning) + +# Enable experimental feature and suppress warnings +set(RunCMake_TEST_OPTIONS + -Wno-dev + "-DCMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO:STRING=b80be207-778e-46ba-8080-b23bba22639e" + ) + +# Test incorrect usage +run_cmake(BadArgs1) +run_cmake(BadArgs2) +run_cmake(BadArgs3) +run_cmake(BadArgs4) +run_cmake(BadArgs5) +run_cmake(BadDefaultTarget) +run_cmake(ReferencesNonExportedTarget) +run_cmake(ReferencesWronglyExportedTarget) +run_cmake(ReferencesWronglyImportedTarget) +run_cmake(ReferencesWronglyNamespacedTarget) + +# Test functionality +run_cmake(Appendix) +run_cmake(InterfaceProperties) +run_cmake(Metadata) +run_cmake(Minimal) +run_cmake(LowerCaseFile) +run_cmake(Requirements) +run_cmake(TargetTypes) diff --git a/Tests/RunCMake/PackageInfo/TargetTypes-check.cmake b/Tests/RunCMake/PackageInfo/TargetTypes-check.cmake new file mode 100644 index 0000000..34ca5ab --- /dev/null +++ b/Tests/RunCMake/PackageInfo/TargetTypes-check.cmake @@ -0,0 +1,11 @@ +include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake) + +set(out_dir "${RunCMake_BINARY_DIR}/TargetTypes-build/CMakeFiles/Export/510c5684a4a8a792eadfb55bc9744983") + +file(READ "${out_dir}/foo.cps" content) +expect_value("${content}" "foo" "name") +expect_value("${content}" "archive" "components" "foo-static" "type") +expect_value("${content}" "dylib" "components" "foo-shared" "type") +expect_value("${content}" "module" "components" "foo-module" "type") +expect_value("${content}" "interface" "components" "bar" "type") +expect_value("${content}" "executable" "components" "test" "type") diff --git a/Tests/RunCMake/PackageInfo/TargetTypes.cmake b/Tests/RunCMake/PackageInfo/TargetTypes.cmake new file mode 100644 index 0000000..755c3a3 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/TargetTypes.cmake @@ -0,0 +1,20 @@ +project(TargetTypes CXX) + +add_library(foo-static STATIC foo.cxx) +add_library(foo-shared SHARED foo.cxx) +add_library(foo-module MODULE foo.cxx) +add_library(bar INTERFACE) +add_executable(test test.cxx) + +install( + TARGETS + foo-static + foo-shared + foo-module + bar + test + EXPORT foo + DESTINATION . + ) + +install(PACKAGE_INFO foo DESTINATION cps EXPORT foo) diff --git a/Tests/RunCMake/PackageInfo/broken-config.cmake b/Tests/RunCMake/PackageInfo/broken-config.cmake new file mode 100644 index 0000000..09e40df --- /dev/null +++ b/Tests/RunCMake/PackageInfo/broken-config.cmake @@ -0,0 +1 @@ +add_library(wrong::lib INTERFACE IMPORTED) diff --git a/Tests/RunCMake/PackageInfo/foo.cxx b/Tests/RunCMake/PackageInfo/foo.cxx new file mode 100644 index 0000000..3695dc9 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/foo.cxx @@ -0,0 +1,3 @@ +void foo() +{ +} diff --git a/Tests/RunCMake/PackageInfo/test-config.cmake b/Tests/RunCMake/PackageInfo/test-config.cmake new file mode 100644 index 0000000..3c46ea6 --- /dev/null +++ b/Tests/RunCMake/PackageInfo/test-config.cmake @@ -0,0 +1 @@ +add_library(test::liba INTERFACE IMPORTED) diff --git a/Tests/RunCMake/PackageInfo/test.cxx b/Tests/RunCMake/PackageInfo/test.cxx new file mode 100644 index 0000000..f8b643a --- /dev/null +++ b/Tests/RunCMake/PackageInfo/test.cxx @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} |