I'm writing a C++ project which use a code generator (perl xsubpp). It generates C/C++ source code from XS file. As xsubpp sometimes produce incomplete output file, I want to have it run before the actual binary target is built, regardless there exists generated source file.
I can find out two ways to achieve it:
# the target is always out-of-date, so the command is always run add_custom_target(...) add_library(lib_name ...) add_dependencies(lib_name ...) and
add_library(lib_name ...) # the command is always run before lib_name is build add_custom_command(TARGET lib_name PRE_BUILD ...) However, none of them works, because add_library() checks source file at configure time. The source file must either exist, or as an output target of add_custom_command().
For the first way, the add_custom_target() don't have the concept of output target; and for the second way, the add_custom_command() is used as an auxiliary of lib_name, which also don't have the concept of output target.