[CMake] avoid rebuilding targets depending on generated source files

Ajay Panyala ajay at csc.lsu.edu
Sat Mar 3 17:59:13 EST 2012


No, it wouldn't;

Thanks. It works now. I might have done something wrong earlier.

- Ajay

On Sat, Mar 3, 2012 at 2:47 PM, Michael Hertling <mhertling at online.de>wrote:

> On 03/03/2012 10:36 PM, Ajay Panyala wrote:
> > Try "cmake -E copy_if_different ..."
> >
> > cmake -E copy_if_different build/test1.c build/tests/test1.c
> >
> > That would work when make is run atleast once.
> > When running make for the 1st time test1.c was never
> > copied to build/tests before. So I would be comparing a file with
> > another non-existant file and that would result in an error halting
> > the make process.
>
> No, it wouldn't; check it out:
>
> % touch a
> % rm -f b
> % ls b
> ls: cannot access b: No such file or directory
> % cmake -E copy_if_different a b
> % ls b
> b
> % cksum a b
> 4294967295 0 a
> 4294967295 0 b
>
> Regards,
>
> Michael
>
> > On Sat, Mar 3, 2012 at 1:20 PM, Hendrik Sattler <post at hendrik-sattler.de
> >wrote:
> >
> >> Am Samstag, 3. März 2012, 21:41:49 schrieb Ajay Panyala:
> >>> 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
> >>
> >> Try "cmake -E copy_if_different ..."
> >>
> >> HS
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120303/13eaa8a0/attachment-0001.htm>


More information about the CMake mailing list