For a number of reasons I have to manually generate a static library through a custom command.
However, it seems that the custom command is only executed when a target specifically requests its output files.
If I try to link the generated static library with target_link_libraries
, CMake complains that it cannot find a rule to generate it.
# Building library on the fly
add_custom_command(OUTPUT mylib.a
COMMAND ...
)
add_executable(myexe main.cpp)
target_link_libraries(myexe mylib.a) # Fails miserably
I imagine I have to insert a target or dependency somehow between the add_custom_command
call and the target_link_libraries
one, but I cannot understand how to do so correctly.
add_custom_command
. Looks like you need to resort to IMPORTED library target, as described in this question. BTW that question looks like duplicate for yours. – Healion