I have (mostly) successfully set up ExternalProject_Add for googletest. However, I noticed that things like my choice of C++ compiler, build type, etc. are not automatically
I don't know of a robust way to achieve this, and I'm pretty sure there's no standard "CMake way", but my answer to a similar question about capturing CMake command line arguments might help you?
After long hours of trying to figure this out, it was finally answered (by Don Hinton) in the CMake mailing list. Fraser's solution is very close, but can still pass some project specific arguments that can cause some unpredictable behavior.
The following works properly. Hopefully this will save people some time trying to figure this out:
cmake_minimum_required(VERSION 3.1)
# MUST be done before call to 'project'
get_cmake_property(vars CACHE_VARIABLES)
foreach(var ${vars})
get_property(currentHelpString CACHE "${var}" PROPERTY HELPSTRING)
if("${currentHelpString}" MATCHES "No help, variable specified on the command line." OR "${currentHelpString}" STREQUAL "")
# message("${var} = [${${var}}] -- ${currentHelpString}") # uncomment to see the variables being processed
list(APPEND CL_ARGS "-D${var}=${${var}}")
endif()
endforeach()
project(SuperBuild)
include(ExternalProject)
ExternalProject_Add(ext_proj
...
CMAKE_ARGS ${CL_ARGS}
)
Link to mailing list thread: https://cmake.org/pipermail/cmake/2018-January/067002.html