Tests: Cover TARGET_PROPERTY genex evaluation of transitive link properties

Demonstrate that TARGET_PROPERTY does not honor CMP0099 from CMake 3.17.
This commit is contained in:
Brad King
2024-04-22 14:48:08 -04:00
parent abf607c2ec
commit 8d1d6a1437
4 changed files with 65 additions and 1 deletions
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.17)
if(RunCMake_TEST STREQUAL "LOCATION")
cmake_minimum_required(VERSION 2.8.12) # Leave CMP0026 unset.
endif()
@@ -14,6 +14,7 @@ run_cmake(LinkImplementationCycle6)
run_cmake(LOCATION)
run_cmake(SOURCES)
run_cmake(TransitiveBuild)
run_cmake(TransitiveLink)
block()
run_cmake(Scope)
@@ -0,0 +1,21 @@
# FIXME: TARGET_PROPERTY evaluation does not pierce LINK_ONLY
set(expect [[
# file\(GENERATE\) produced:
main LINK_LIBRARIES: 'foo1' # not transitive
main LINK_DIRECTORIES: '[^';]*/Tests/RunCMake/GenEx-TARGET_PROPERTY/dirM;[^';]*/Tests/RunCMake/GenEx-TARGET_PROPERTY/dir1'
main LINK_OPTIONS: '-optM;-opt1'
main LINK_DEPENDS: '[^';]*/Tests/RunCMake/GenEx-TARGET_PROPERTY/TransitiveLink-build/depM;[^';]*/Tests/RunCMake/GenEx-TARGET_PROPERTY/TransitiveLink-build/dep1'
]])
string(REGEX REPLACE "\r\n" "\n" expect "${expect}")
string(REGEX REPLACE "\n+$" "" expect "${expect}")
file(READ "${RunCMake_TEST_BINARY_DIR}/out.txt" actual)
string(REGEX REPLACE "\r\n" "\n" actual "${actual}")
string(REGEX REPLACE "\n+$" "" actual "${actual}")
if(NOT actual MATCHES "^${expect}$")
string(REPLACE "\n" "\n expect> " expect " expect> ${expect}")
string(REPLACE "\n" "\n actual> " actual " actual> ${actual}")
message(FATAL_ERROR "Expected file(GENERATE) output:\n${expect}\ndoes not match actual output:\n${actual}")
endif()
@@ -0,0 +1,42 @@
enable_language(C)
add_library(foo1 STATIC empty.c)
target_link_libraries(foo1 PRIVATE foo2 foo3)
target_link_directories(foo1 INTERFACE dir1)
target_link_options(foo1 INTERFACE -opt1)
set_target_properties(foo1 PROPERTIES
INTERFACE_LINK_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/dep1"
)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dep1" "")
add_library(foo2 STATIC empty.c)
target_link_directories(foo2 INTERFACE dir2)
target_link_options(foo2 INTERFACE -opt2)
set_target_properties(foo2 PROPERTIES
INTERFACE_LINK_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/dep2"
)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dep2" "")
add_library(foo3 STATIC empty.c)
target_link_directories(foo3 PRIVATE dir3)
target_link_options(foo3 PRIVATE -opt3)
set_target_properties(foo3 PROPERTIES
LINK_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/dep3"
)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dep3" "")
add_executable(main main.c)
target_link_libraries(main PRIVATE foo1)
target_link_directories(main PRIVATE dirM)
target_link_options(main PRIVATE -optM)
set_target_properties(main PROPERTIES
LINK_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/depM"
)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/depM" "")
file(GENERATE OUTPUT out.txt CONTENT "# file(GENERATE) produced:
main LINK_LIBRARIES: '$<TARGET_PROPERTY:main,LINK_LIBRARIES>' # not transitive
main LINK_DIRECTORIES: '$<TARGET_PROPERTY:main,LINK_DIRECTORIES>'
main LINK_OPTIONS: '$<TARGET_PROPERTY:main,LINK_OPTIONS>'
main LINK_DEPENDS: '$<TARGET_PROPERTY:main,LINK_DEPENDS>'
")