I need to run a few commands after I build my project with cmake. The commands will do some transformations to the source files in order to produce a new binary. The whole process would be like this:
- compile the target (executable or library) and link it (as it is now)
- run tool A on the compiled binary and produce an intermediary output
- run tool B on the source files using the intermediary output
- compile the target (executable or library) and link it (as it is now)
So, I need to compile twice with the same command, but between the compilations I need to run tool A and B.
All parameters that were passed to the cxx compiler should be passed to the tools A and B. Namely, those commands would look pretty much the same as if we were invoking the compiler, just instead of running the g++/clang++/etc, we would run another tool.
Ex, if the compilation step looks like this (simplified):
g++ source1.cpp source2.cpp -I/some/include -I/some/other/include -fPIC -o target then, we should just invoke this:
aaa source1.cpp source2.cpp -I/some/include -I/some/other/include -fPIC -o target bbb source1.cpp source2.cpp -I/some/include -I/some/other/include -fPIC -o target
add_library(target1 ...)thenadd_custom_command(OUTPUTS semething_from_target1 DEPENDS target1 COMMAND aaa $<TARGET_POPERTY ... (get command line options )> $<TARGET_FILE:target1> )and thenadd_library(the_real_target1 ....) add_dependencies(the_real_target1 something_from_target1). It would get easier if you would create an minimal reproducible example or at least explain what is that "intermediary output" you are generating and with what purpose. You could also generate compile_commands.json and parse it for options.