[CMake] avoid rebuilding targets depending on generated source files

Ajay Panyala ajay at csc.lsu.edu
Sat Mar 3 15:41:49 EST 2012


Hello,

I have a custom target which runs a command to generate
a C source file say test1.c

ADD_CUSTOM_TARGET(TestGen ALL
COMMAND genExec ${PROJECT_SOURCE_DIR}/Main.java
DEPENDS ${PROJECT_SOURCE_DIR}/Main.java
)

And I have a custom command that moves the generated *test1.c *
to a new directory inside the build directory.

ADD_CUSTOM_COMMAND(
TARGET TestGen
POST_BUILD
COMMAND mv
ARGS ${PROJECT_BINARY_DIR}/test1.c ${PROJECT_BINARY_DIR}/tests/
)

Each time I run make, the custom target is run (since custom targets are
always
out-of-date). But I want to avoid moving the new test1.c generated each time
if build/test1.c is the same as build/tests/test1.c since there are other
targets
like add_executable and add_library later in the CMakelists file that are
 re-built
each time since they depend on test1.c

I tried cmake -E compare_files inside execute_process, but it would not be
executed before the custom command.

I tried cmake -E compare_files inside a custom command as well, but that
would give an
error and halt the make process if the files differ.

I want to avoid re-building later targets that depend on test1.c.

Thanks
Ajay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120303/c68572fc/attachment.htm>


More information about the CMake mailing list