问题
I was trying to use ExternalProject module:
ExternalProject_Add( googlebenchmark
GIT_REPOSITORY "https://github.com/google/benchmark.git"
TLS_VERIFY ON
CMAKE_CACHE_DEFAULT_ARGS -DBENCHMARK_ENABLE_TESTING:BOOL=OFF
SOURCE_DIR "${CMAKE_BINARY_DIR}/third_party/gbenchmark"
INSTALL_DIR "${CMAKE_BINARY_DIR}/third_party" )`
And there is an issue I've come up with: this module for some reason doesn't forward compiler, used in (parent) cmake, as well as CMAKE_BUILD_TYPE.
I've tried to use CMAKE_CACHE_DEFAULT_ARGS to set CMAKE_CXX_COMPILER directly, but it didn't quiet worked out.
Is there a decent explanation for this behaviour? Is there a proper (cmake-ish) way to forward currently used compiler/build configuration to ExternalProject?
回答1:
To forward the compiler use the ExternalProject
argument CMAKE_CACHE_ARGS
, i.e.:
ExternalProject_Add( googlebenchmark
...
CMAKE_CACHE_ARGS
"-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}"
"-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}"
)
来源:https://stackoverflow.com/questions/32744788/forwarding-current-compiler-to-externalproject