[ACCEPTED]-Get CMake to execute a target in project before building a library-cmake

Accepted answer
Score: 18

In CMakeLists.txt:

First, define your executable:

add_executable(marks-code-generator gen.cpp)

Then, define 6 a custom command to generate the source:

add_custom_command(OUTPUT generated.cpp generated.hpp
                   COMMAND marks-code-generator ARGS args here maybe
                   MAIN_DEPENDENCY input-file.in
                   DEPENDS marks-code-generator
                   COMMENT here we go!

The 5 option VERBATIM makes sure platform-specific escaping 4 is done correctly. The COMMENT will be printed 3 out as make executes, giving something like 2 [ 66%] here we go!.

Finally, name your generated source in 1 the source list for your real program:

add_executable(some-program generated.cpp generated.hpp non-generated.cpp foo.cpp)

More Related questions