ExternalProject as script
My company has a set of cmake-based builds, where depending on the platform we build for we need to use specific generators (including the Green Hills generator). While it's possible to detect the generator and change settings based on that, the only way to set the generator is from the command line itself, or an ExternalProject call. Unfortunately, ExternalProject can't be used from a script being called with cmake -P
:
#!cmake -P
include(ExternalProject)
ExternalProject_add(MyBuild
SOURCE_DIR "."
SOURCE_SUBDIR "Src"
BINARY_DIR mybuild
CMAKE_GENERATOR "Visual Studio 10 2010"
CMAKE_CACHE_ARGS
-DGTEST_ENABLE=1
-DCONFIG=RED
INSTALL_COMMAND ""
TEST_COMMAND ""
)
Compare this to the naive but working version using execute_process
:
#!cmake -P
file(MAKE_DIRECTORY mybuild)
execute_process(
COMMAND cmake ../Src
-G"Visual Studio 10 2010"
-DGTEST_ENABLE=1
-DCONFIG=RED
WORKING_DIRECTORY mybuild
)
While ExternalProject
may be more verbose, it's also far clearer.