Policy CMP0112: generatorexpressions seem to care about the state when the target was defined
# define version requirements
cmake_minimum_required(VERSION 3.19)
project(Test)
file(TOUCH dummy.c)
add_library(somelib SHARED
dummy.c)
cmake_minimum_required(VERSION 3.14)
add_library(somelib2 SHARED
dummy.c)
cmake_minimum_required(VERSION 3.19)
set(invar "$<TARGET_FILE_DIR:somelib>")
set(output)
get_property(stargets DIRECTORY . PROPERTY BUILDSYSTEM_TARGETS)
foreach(tar IN LISTS stargets)
get_target_property(stype ${tar} TYPE)
if(stype STREQUAL "SHARED_LIBRARY")
list(APPEND output "${tar}=$<TARGET_FILE_DIR:${tar}>/$<TARGET_FILE_NAME:${tar}>")
endif()
endforeach()
list(SORT output)
# OLD/NEW doesnt make a difference here ?
cmake_policy(SET CMP0112 NEW)
add_custom_command(
OUTPUT variable.txt
COMMAND ${CMAKE_COMMAND} -E echo "\"${output}\"" > variable.txt
)
add_custom_target(
writestuff
DEPENDS variable.txt direct.txt
)
This is compacted from a larger project where libraries (plugins) are contained in subdirectories with their own CMakeLists.txt
.
There seem to be some weird inconsistencies with the behavior of dependencies. What I was able to narrow down was that it apparently matters where the target is defined.
ninja variable.txt
will usually depend and build libsomelib2.so
So is that the way it is intended? If so please update the docs, because I would expect that the point where I use add_custom_command
should matter.