[CMake] Problems with auto-generated sources

Jakub Schmidtke sjakub at gmail.com
Mon Sep 30 13:19:10 EDT 2013


The workaround I found so far is to add a custom target that depends on the
targets I want to build.
So if I add this:
add_custom_target(test12 DEPENDS test1 test2)

to my CMake file, and instead of running 'make -j test1 test2' I run 'make
-j test12' everything seems to be fine...





On Mon, Sep 30, 2013 at 1:07 PM, Rolf Eike Beer <eike at sf-mail.de> wrote:

> Am Montag, 30. September 2013, 12:58:40 schrieb Jakub Schmidtke:
> > Hi,
> >
> > I am trying to get dependencies right in a project that uses
> auto-generated
> > sources.
> > I have a library, that uses auto-generated files, and other executables
> > that use that library.
> > I created a set of CMakeLists.txt files that show the problem.
> >
> > To run it you need test.c and org.c in the source directory, and one of
> > them should contain int main(void) { return 0; } in it,
> > the other can be empty. First try - the simplest approach:
> >
> > project(Test)
> >
> > add_custom_command(OUTPUT file.c
> >     COMMAND echo "GENERATING FILE"
> >     COMMAND rm -f file.c
> >     COMMAND cp -i ${CMAKE_CURRENT_SOURCE_DIR}/org.c file.c
> >     DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/org.c
> >   )
> > add_library(LibFile file.c)
> >
> > add_executable(test1 test.c)
> > target_link_libraries(test1 LibFile)
> >
> > add_executable(test2 test.c)
> > target_link_libraries(test2 LibFile)
> >
> > When I build it with 'make' it builds just fine.
> > However, if (from the build/) directory I run: touch ../org.c; make -j
> > test1 test2 it sometimes gives me this:
> >
> > [ 25%] [ 25%] Generating file.c
> > Generating file.c
> > GENERATING FILE
> > GENERATING FILE
> > cp: overwrite ‘file.c’? [ 25%] [ 25%] Built target gen_file
> > Built target gen_file
>
> What a coincidence ;) I recently updated my CMake sources. I decided to do
> a
> partial rebuild as the executables themselves were in use and I wanted to
> avoid any hassle. So I typed
>
> make -j 10 CMakeLib CPackLib CTestLib
>
> And that resulted in basically the same problem: make tried to link
> CMakeLib
> three times in parallel, obviously failing. So the problem here is not
> limited
> to generated files I think.
>
> Eike
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> 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/20130930/b672d271/attachment.htm>


More information about the CMake mailing list