I am trying to combine several static libraries with CMake and I found an answer that suggests doing the following:
SET_TARGET_PROPERTIES(merged PROPERTIES STATIC_LIBRARY_FLAGS "full\path\to\lib1.lib full\path\to\lib2.lib")
The libraries I want to combine are the output of other targets and when I want to refer to the output of a target I usually use generator expression such as $< TARGET_FILE:MyLib>. However in this context it does not work because the generator expression does not get expanded before being passed to the linker and it complains that $< TARGET_FILE:MyLib> cannot be found.
This does not work:
set_target_properties(merged PROPERTIES STATIC_LIBRARY_FLAGS $<TARGET_FILE:MyLib>)
I guess I am meant to set the property to the path of the library:
set_target_properties(merged PROPERTIES STATIC_LIBRARY_FLAGS ${CURRENT_BIN_DIR}/MyLib.lib})
Generating this path manually can be tedious (I have many targets) and I was wondering if, given a target, there was a better way to get that path automatically.
For example (I am making up the syntax here):
set_target_properties(merged PROPERTIES STATIC_LIBRARY_FLAGS EXPAND_PATH($<TARGET_FILE:MyLib>))