Files
cmake/Tests/RunCMake/ExportCpsDefaultComponents/NormalExport-check.cmake
T
Matthew Woehlke 4c6b437265 Export: Expand CPS default targets
CPS provides "default targets" as a user convenience which can be linked
by specifying only the package name. CMake implements this via a utility
`INTERFACE` target. However, because it is not namespaced, this is not a
valid requirement, which prevents exporting anything linking to this
target to CPS.

Work around this by introducing a new (internal) target property which
replaces a target with its link interface targets at export time.
2026-07-30 15:01:47 -04:00

28 lines
1.1 KiB
CMake

include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake)
set(out_dir "${RunCMake_BINARY_DIR}/NormalExport-build")
file(READ "${out_dir}/cps/bar/bar.cps" content)
expect_value("${content}" "bar" "name")
expect_value("${content}" "interface" "components" "bar" "type")
expect_value("${content}" "bar" "name")
expect_array("${content}" 2 "requires" "foo" "components")
expect_value("${content}" "foo1" "requires" "foo" "components" 0)
expect_value("${content}" "foo2" "requires" "foo" "components" 1)
string(JSON component GET "${content}" "components" "bar")
expect_array("${component}" 2 "requires")
expect_value("${component}" "foo:foo1" "requires" 0)
expect_value("${component}" "foo:foo2" "requires" 1)
file(READ "${out_dir}/bar.cmake" bar_cmake)
if(NOT "${bar_cmake}" MATCHES "add_library\\(bar INTERFACE IMPORTED\\)")
string(APPEND RunCMake_TEST_FAILED
"Interface library 'bar' was not exported\n")
endif()
if(NOT "${bar_cmake}" MATCHES "set_target_properties\\(bar PROPERTIES[ \n]+INTERFACE_LINK_LIBRARIES \"foo::foo1;foo::foo2\"[ \n]*\\)")
string(APPEND RunCMake_TEST_FAILED
"Interface library 'bar' has wrong link libraries\n")
endif()