[CMake] Generate *.cpp/*.hpp with add_custom_command, reference these in add_library in another subdirectory/CMakeLists?
Martin Zenzes
martin.zenzes at dfki.de
Fri Jan 10 05:21:43 EST 2014
Hi,
I'm generating a *.cpp/*.hpp pair of files using add_custom_command() +
add_custom_target(). These are then referenced in add_library() to be
compiled and linked into a library, together with some "static"
source-files. This works well as long as both parts (generating and
creating the library) are in the same CMakeLists. This is also stated in
the documentation [1]:
{{{
A target created in the same directory (CMakeLists.txt file) that
specifies any output of the custom command as a source file is given a
rule to generate the file using the command at build time.
}}}
My question: Is there a way to split the generating and compiling into
different subdirectories/CMakeLists, and specify the "rule to generate
the file" manually for the add_library() target?
The problem: At the time the add_library() is processed by cmake, the
referenced *.cpp/*.hpp files are not yet created, hence they are not
found ("Cannot find source file"). Adding the generate-target to ALL
does not help, as at the target is executed to create the file _after_
the add_library() call is processed.
Any hints?
Greetings and thanks for your efforts.
[1] http://cmake.org/cmake/help/v2.8.7/cmake.html#command:add_custom_command
More information about the CMake
mailing list