2

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?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
MPogoda
  • 138
  • 1
  • 7

1 Answers1

5

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}"
)
sakra
  • 62,199
  • 16
  • 168
  • 151
  • 1
    Oh, thanks a lot! Actually, ExternalProject uses Regexps to parse parameters to options, so you need to append type for those variables (FILENAME). – MPogoda Sep 23 '15 at 18:31
  • 1
    Thanks for the hint with the types. The correct type is actually `FILEPATH`. – sakra Sep 23 '15 at 18:50
  • `CMAKE_ARGS` can be used without the type (it's passed to the inner `cmake` as regular cmdline parameters). `CMAKE_CACHE_ARGS` is only needed if the cmdline becomes too long, which is probably relatively rare. – Sebastian Ullrich Nov 11 '19 at 17:38