From 6d261267547280380ea174c894aa07c21c31db7e Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Tue, 5 Mar 2013 14:45:37 +0100 Subject: [PATCH] Only regenerate config var file if actually changed --- CMakeLists.txt | 12 +++++++++++- cmake/Modules/ConfigVars.cmake | 5 ++--- cmake/Modules/OpmDistClean.cmake | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 26a4e57..c0a2d6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,7 +118,10 @@ opm_sources (${project}) # includes the necessary defines by the dependencies include (ConfigVars) list (APPEND ${project}_CONFIG_VARS ${${project}_CONFIG_VAR}) -set (CONFIG_H "${PROJECT_BINARY_DIR}/config.h") + +# write configuration variables to this file. note that it is a temporary. +message (STATUS "Writing config file \"${PROJECT_BINARY_DIR}/config.h\"...") +set (CONFIG_H "${PROJECT_BINARY_DIR}/config.h.tmp") configure_vars ( FILE CXX ${CONFIG_H} WRITE ${${project}_CONFIG_VARS} @@ -130,6 +133,13 @@ define_fc_func ( IF HAVE_LAPACK ) +# overwrite the config.h that is used by the code only if we have some +# real changes. thus, we don't have to recompile if a reconfigure is run +# due to some files being added, for instance +execute_process (COMMAND + ${CMAKE_COMMAND} -E copy_if_different ${CONFIG_H} ${PROJECT_BINARY_DIR}/config.h + ) + # compile main library; pull in all required includes and libraries include (OpmCompile) opm_compile (${project}) diff --git a/cmake/Modules/ConfigVars.cmake b/cmake/Modules/ConfigVars.cmake index 072d2b7..ad81e98 100644 --- a/cmake/Modules/ConfigVars.cmake +++ b/cmake/Modules/ConfigVars.cmake @@ -27,7 +27,6 @@ function (configure_vars obj syntax filename verb) # this is just to make the syntax look like the build-in commands - message (STATUS "Writing config file \"${filename}\"...") if (NOT ("${obj}" STREQUAL "FILE" AND (("${verb}" STREQUAL "WRITE") OR ("${verb}" STREQUAL "APPEND")))) message (FATAL_ERROR "Syntax error in argument list") @@ -47,10 +46,10 @@ function (configure_vars obj syntax filename verb) # to avoid confusion from other configuration files. get_filename_component (_config_path "${filename}" PATH) get_filename_component (_config_file "${filename}" NAME) - if ("${_config_file}" STREQUAL "config.h") + if ("${_config_file}" MATCHES "config\\.h(\\..+)?") add_definitions (-DHAVE_CONFIG_H=1) include_directories (BEFORE "${_config_path}") - endif ("${_config_file}" STREQUAL "config.h") + endif ("${_config_file}" MATCHES "config\\.h(\\..+)?") # only write the current value of each variable once set (_args ${ARGN}) diff --git a/cmake/Modules/OpmDistClean.cmake b/cmake/Modules/OpmDistClean.cmake index 03bba48..5bdea6d 100644 --- a/cmake/Modules/OpmDistClean.cmake +++ b/cmake/Modules/OpmDistClean.cmake @@ -17,6 +17,7 @@ macro (opm_dist_clean opm) cmake_install.cmake Makefile config.h + config.h.tmp ${${opm}_NAME}-config.cmake ${${opm}_NAME}-config-version.cmake ${${opm}_NAME}-install.cmake