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.