Reputation: 20304
Is it possible to export all variables values that were set in CMake-GUI to single command line string so it can be used from external tools quickly?
So the output would be something like:
cmake -DVar1=ON -DVar2="foo" ...
Upvotes: 3
Views: 878
Reputation: 43030
There is no cmake-gui
integrated way to export or document the changed variables over several configure/generate runs.
But each change to a cached variable runs the configure step again and so I came up with the following code you can add to your main CMakeLists.txt
to persist the original variables and diff against any future list of variables:
if (EXISTS "${CMAKE_BINARY_DIR}/CMakeCache.txt")
file(
STRINGS
"${CMAKE_BINARY_DIR}/CMakeCache.txt"
_vars
REGEX "^[^#/]"
)
if (NOT EXISTS "${CMAKE_BINARY_DIR}/CMakeCacheVars.txt")
file(
WRITE "${CMAKE_BINARY_DIR}/CMakeCacheVars.txt"
"${_vars}"
)
else()
file(
READ "${CMAKE_BINARY_DIR}/CMakeCacheVars.txt"
_vars_ori
)
list(REMOVE_ITEM _vars ${_vars_ori})
message("Changed values: ${_vars}")
endif()
endif()
Upvotes: 0