[CMake] ExternalProject_Add not re-building when source changes

Rob McDonald rob.a.mcdonald at gmail.com
Thu Apr 23 19:54:00 EDT 2015


I've used ExternalProject_Add to trick CMake into supporting two
compilers to build my project.

Part of my project needs OpenMP, but other parts do not.  So, on
MacOS, I would prefer to build most of the project with CLang, but the
OpenMP requiring part with gcc.

I have CMake set up to detect whether the compiler supports OpenMP.
If it does not, it checks for a user-supplied alternate compiler.

If the user has supplied an alternate compiler, CMake treats the
current directory as an ExternalProject , but passes the alternate
OpenMP capable compiler.

In general, this works well.  However, this arrangement does not
notice when the source files have changed and cause the External
Project to rebuild.

I'm using ExternalProject_ForceBuild to try to make the EP build every
time -- that works, but once inside the EP, make doesn't recognize
that the source files have been updated.

The meat of the situation is something like this....

ExternalProject_Add( MYPROJECT
URL ${CMAKE_CURRENT_SOURCE_DIR}
CMAKE_ARGS -DCMAKE_C_COMPILER=${C_ALTERNATE_COMPILER}
    -DCMAKE_CXX_COMPILER=${CXX_ALTERNATE_COMPILER}
    -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
    -DEP_BUILD=TRUE
INSTALL_COMMAND ""
)
EP_ForceBuild( MYPROJECT )

I use the -DEP_BUILD=TRUE as an extra safety to prevent infinite
recursion -- if the user supplied a non OpenMP capable compiler as the
ALTERNATE_COMPILER.

So, I think the problem is with my use of 'URL
${CMAKE_CURRENT_SOURCE_DIR}'.  Is there a better way to achieve the
same thing?

Thanks in advance,

Rob


More information about the CMake mailing list