[CMake] Generating multiple targets in parallel generates common prerequisites twice

Martin Apel martin.apel at simpack.de
Wed Jan 8 03:42:01 EST 2014


Hi all,

I hope this question hasn't been asked before, I haven't found anything 
useful in the archive.

Assume I have the following small CMakeLists.txt file:

CMAKE_MINIMUM_REQUIRED (VERSION 2.8)
PROJECT(testCMakeDeps)

ADD_LIBRARY(foo SHARED foo.cpp)
ADD_LIBRARY(bar SHARED bar.cpp)

ADD_EXECUTABLE(test test.cpp)
TARGET_LINK_LIBRARIES(test foo bar)

ADD_EXECUTABLE(test2 test2.cpp)
TARGET_LINK_LIBRARIES(test2 foo bar)

This creates two executables, which both depend on the same two shared 
libraries. When generating a Makefile for this on Linux,
one can start the compilation process via 'make -j2 test test2', i.e. 
name two separate targets on the command line.
However CMake seems to generate a Makefile, which does not work 
correctly in this case. The shared libraries are generated twice.
This seems to be a CMake issue, not a Make issue, I can write a Makefile 
by hand, which works correctly in this case.
Is there any way around the duplicate generation (which sometimes fails, 
because the same libraries may be generated simultaneously)?

Martin


More information about the CMake mailing list