diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a889ee6fd590de4e3e8bc892b8f5e5449be66fe..16dda92348caf45faa2d8855d8b6cf3ed48ed990 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ endif() project( OGS-6 ) include(scripts/cmake/CMakeSetup.cmake) +include(ParseCMakeArgs) ########################### ### Preliminary Options ### diff --git a/scripts/cmake/ParseCMakeArgs.cmake b/scripts/cmake/ParseCMakeArgs.cmake new file mode 100644 index 0000000000000000000000000000000000000000..ed56906582e60b0ecd4d99fe28d64fb8e91108d8 --- /dev/null +++ b/scripts/cmake/ParseCMakeArgs.cmake @@ -0,0 +1,40 @@ +# Implementation from https://stackoverflow.com/questions/10205986 +# +# Captures not-yet cached CMake variables. +# On first CMake run via cmake-cli this works as expected. +# Once the variables are cached this will not work anymore (and is +# therefore skipped). +# +# When running CMake -D.. passed args can be retrieved with by the +# CACHE_VARIABLES CMake property. On sub-sequent CMake runs it is +# no longer possible to differentiate between variables already cached +# by option()-calls and variables passed to the CMake call with -D.. +# +# A (cached) map data structure would solve this. +# Tried the following map implementations without luck: +# - https://github.com/toeb/cmakepp (not cached) +# - https://github.com/j3lamp/mcl (did not work at all) + +if(EXISTS ${PROJECT_BINARY_DIR}/CMakeCache.txt) + set(CMAKE_ARGS "Information not available.") + set(CMAKE_ARGS_ESCAPED ${CMAKE_ARGS}) + file(REMOVE ${PROJECT_BINARY_DIR}/cmake-args) + return() +endif() + +get_cmake_property(CACHE_VARS CACHE_VARIABLES) +foreach(CACHE_VAR ${CACHE_VARS}) + get_property(CACHE_VAR_HELPSTRING CACHE ${CACHE_VAR} PROPERTY HELPSTRING) + if(CACHE_VAR_HELPSTRING STREQUAL "No help, variable specified on the command line.") + get_property(CACHE_VAR_TYPE CACHE ${CACHE_VAR} PROPERTY TYPE) + if(CACHE_VAR_TYPE STREQUAL "UNINITIALIZED") + set(CACHE_VAR_TYPE) + else() + set(CACHE_VAR_TYPE :${CACHE_VAR_TYPE}) + endif() + set(CMAKE_ARGS "${CMAKE_ARGS} -D${CACHE_VAR}${CACHE_VAR_TYPE}=\"${${CACHE_VAR}}\"") + endif() +endforeach() + +string(REPLACE "\"" "\\\"" CMAKE_ARGS_ESCAPED ${CMAKE_ARGS}) +file(WRITE ${PROJECT_BINARY_DIR}/cmake-args "${CMAKE_ARGS}\n") diff --git a/scripts/cmake/packaging/Pack.cmake b/scripts/cmake/packaging/Pack.cmake index 3ef648bf2d41e0433cb2ce141fef26f944b95977..0ef317ec54a36b5f75b8be24d0dce1bae2142c42 100644 --- a/scripts/cmake/packaging/Pack.cmake +++ b/scripts/cmake/packaging/Pack.cmake @@ -126,3 +126,6 @@ endif() configure_file(Documentation/README.txt.in ${PROJECT_BINARY_DIR}/README.txt) install(FILES ${PROJECT_BINARY_DIR}/README.txt DESTINATION .) + +install(FILES ${PROJECT_BINARY_DIR}/CMakeCache.txt DESTINATION ${CMAKE_INSTALL_INFODIR}) +install(FILES ${PROJECT_BINARY_DIR}/cmake-args DESTINATION ${CMAKE_INSTALL_INFODIR})