[CMake] Problems with auto-generated sources

Rolf Eike Beer eike at sf-mail.de
Mon Sep 30 13:07:31 EDT 2013


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


More information about the CMake mailing list