Update the CMake cache to reflect current settings

During configuration some of the values for CMake properties (compiler
flags etc.) may be changed either by the user (through command line
parameters or option files), or by the configuration script itself
(setting more aggressive options or detailed debugging for instance).

This change writes many of the relevant values back into the cache so
they are available for introspection (using e.g. ccmake) or when the
rerunning the configuration without specifying all options.
This commit is contained in:
Roland Kaufmann 2013-09-17 21:46:07 +02:00 committed by Bård Skaflestad
parent 93bfbecb3b
commit b6c5d3572d
2 changed files with 40 additions and 0 deletions

View File

@ -60,3 +60,40 @@ macro (opm_defaults opm)
set (Boost_NO_BOOST_CMAKE ON)
endif (NOT BOOST_ROOT)
endmacro (opm_defaults opm)
# overwrite a cache entry's value, but keep docstring and type
# if not already in cache, then does nothing
function (update_cache name)
get_property (_help CACHE "${name}" PROPERTY HELPSTRING)
get_property (_type CACHE "${name}" PROPERTY TYPE)
if (NOT "${_type}" STREQUAL "")
#message ("Setting ${name} to \"${${name}}\" in cache.")
set ("${name}" "${${name}}" CACHE ${_type} "${_help}" FORCE)
endif ()
endfunction (update_cache name)
# put all compiler options currently set back into the cache, so that
# they can be queried from there (using ccmake for instance)
function (write_back_options)
# build type
update_cache (CMAKE_BUILD_TYPE)
# compilers
set (languages C CXX Fortran)
foreach (language IN LISTS _languages)
if (CMAKE_${language}_COMPILER)
update_cache (CMAKE_${language}_COMPILER)
endif ()
endforeach (language)
# flags (notice use of IN LISTS to get the empty variant)
set (buildtypes "" "_DEBUG" "_RELEASE" "_MINSIZEREL" "_RELWITHDEBINFO")
set (processors "C" "CXX" "Fortran" "EXE_LINKER" "MODULE_LINKER" "SHARED_LINKER")
foreach (processor IN LISTS processors)
foreach (buildtype IN LISTS buildtypes)
if (CMAKE_${processor}_FLAGS${buildtype})
update_cache (CMAKE_${processor}_FLAGS${buildtype})
endif ()
endforeach (buildtype)
endforeach (processor)
endfunction (write_back_options)

View File

@ -269,3 +269,6 @@ configure_file (
# make sure updated version information is available in the source code
include (UseVersion)
# update the cache for next run
write_back_options ()