c++cmakemakefileparallel-builds

CMake ExternalProject_Add and parallel builds


With the following CMakeLists.txt build script:

include( ExternalProject )
ExternalProject_Add( framework SOURCE_DIR ${framework_SOURCE}
                     PREFIX framework_build
                     INSTALL_DIR ${framework_DISTRIBUTION} )

    ...

add_library( ${PROJECT_NAME} SHARED ${BUILD_MANIFEST} )
add_dependencies( ${PROJECT_NAME} framework )

When I attempt to perform a parallel build (make -j5) it will occasionally fail due to a build artefact from the framework not being present. The order of the build, fixed by add_dependencies, is not being adhered to.

Have I misunderstood the documentation around add_dependencies?

Output from cmake --graphviz=graph.dot

enter image description here


Solution

  • Ok, so an updated version of CMake has warned me that the framework dependency is not present. ExternalProject_Add and add_dependencies can not be used with each other, as ExternalProject_Add has not actually built and therefore registered the framework as a high-level target.

    Note: Anyone encountering this problem in future. I've found another SO post by @matiu that resolved my issue.