Feature Request: add_custom_command(TARGET) for IMPORTED targets
I have a collection of IMPORTED targets which are shared libraries.
I have a wrapper function that is used to initialize a handful of properties for those IMPORTED targets, as well as call add_library(${PROJECT_NAME} SHARED IMPORTED)
Note that at this point in my cmake code, the target does not yet have its IMPORTED_LOCATION or IMPORTED_IMPLIB target properties set.
I want to add an add_custom_command(TARGET)
similar to this:
add_custom_command(TARGET ${TARGETNAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_GENEX_EVAL:${TARGETNAME},$<TARGET_PROPERTY:${TARGETNAME},IMPORTED_LOCATION>>
"${CMAKE_BINARY_DIR}/artifacts/$<CONFIG>/")
With POST_BUILD
replaced with some new keyword that means "do this action is this imported shared library is used by another target, otherwise don't".
I tried to use
add_custom_command(OUTPUT output1 [output2 ...]
COMMAND command1 [ARGS] [args1...])
But this cannot be done because in this wrapper function, I do not know the filename of the IMPORTED_LOCATION, so I cant specify what the generated output file would be, and even if I did, the add_custom_command forbids the use of target specific properties generator expressions in the OUTPUT parameter anyway.
For my codebase, I will not be able to provide the IMPORTED_LOCATION parameter to my wrapper function. The logic for calculating it is very complicated, and there are hundreds of places where I would have to change the code.