From: Matthias Maier Date: Wed, 13 Jul 2016 12:57:28 +0000 (-0500) Subject: CMake: Bugfix: Properly fix (CMAKE|DEAL_II)_CXX_FLAGS* caching X-Git-Tag: v8.5.0-rc1~874^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2822%2Fhead;p=dealii.git CMake: Bugfix: Properly fix (CMAKE|DEAL_II)_CXX_FLAGS* caching Well, #2793 did not really solve the problem. This commit reorganizes the caching process entirely: * always store CMAKE_* variables in internal cache * do not force update cached DEAL_II_* variables * fix the issue of simultaneous usage of CMAKE_* and DEAL_II_* variables by prepending DEAL_II_* variables *after* the cache setup --- diff --git a/cmake/setup_cached_variables.cmake b/cmake/setup_cached_variables.cmake index 28881b7199..3bbd7c1e0b 100644 --- a/cmake/setup_cached_variables.cmake +++ b/cmake/setup_cached_variables.cmake @@ -104,7 +104,7 @@ OPTION(DEAL_II_FORCE_AUTODETECTION ######################################################################## # # -# Compilation and linking: # +# Configuration options for Compilation and linking: # # # ######################################################################## @@ -183,27 +183,11 @@ SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH "ON" CACHE BOOL MARK_AS_ADVANCED(CMAKE_INSTALL_RPATH_USE_LINK_PATH) -# -# Translate CMake specific variables to deal.II naming: -# - -FOREACH(_flag CXX_FLAGS CXX_FLAGS_RELEASE CXX_FLAGS_DEBUG) - IF(NOT "${CMAKE_${_flag}}" STREQUAL "") - MESSAGE(STATUS - "Prepending \${CMAKE_${_flag}} to \${DEAL_II_${_flag}}" - ) - SET(DEAL_II_${_flag} "${CMAKE_${_flag}} ${DEAL_II_${_flag}}") - ENDIF() -ENDFOREACH() - -FOREACH(_flag LINKER_FLAGS LINKER_FLAGS_DEBUG LINKER_FLAGS_RELEASE) - IF(NOT "${CMAKE_SHARED_${_flag}}" STREQUAL "") - MESSAGE(STATUS - "Prepending \${CMAKE_SHARED_${_flag}} to \${DEAL_II_${_flag}}" - ) - SET(DEAL_II_${_flag} "${CMAKE_${_flag}} ${DEAL_II_${_flag}}") - ENDIF() -ENDFOREACH() +######################################################################## +# # +# Compilation and linking: # +# # +######################################################################## # # Hide all unused CMake variables: @@ -232,12 +216,13 @@ SET(DEAL_II_REMOVED_FLAGS CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO ) FOREACH(_flag ${DEAL_II_REMOVED_FLAGS}) - # Go away... + # + # Promote all variables to internal cache. This prevents CMake from + # populating these variables with default values. Further, store the + # actual content of the variables such that users can still use + # CMAKE_CXX_FLAGS(|_RELEASE|_DEBUG). + # SET(${_flag} ${${_flag}} CACHE INTERNAL "" FORCE) - # Also set it to an empty string for the configuration run so that it - # does not confuse the build system (to unset is not an option - it is - # cached...) - SET(${_flag} "") ENDFOREACH() # @@ -253,15 +238,51 @@ SET(DEAL_II_USED_FLAGS DEAL_II_LINKER_FLAGS_RELEASE ) FOREACH(_flag ${DEAL_II_USED_FLAGS}) - # - # Promote to cache: - # SET(${_flag} "${${_flag}}" CACHE STRING "The user supplied cache variable will be appended _at the end_ of the configuration step to the auto generated ${_flag} variable" - FORCE ) MARK_AS_ADVANCED(${_flag}) +ENDFOREACH() + +FOREACH(_variable + DEAL_II_DEFINITIONS + DEAL_II_DEFINITIONS_DEBUG + DEAL_II_DEFINITIONS_RELEASE + ) + SET(${_variable} ${${_variable}} CACHE STRING + "Additional, user supplied compile definitions" + ) + MARK_AS_ADVANCED(${_variable}) +ENDFOREACH() + +# +# Translate CMake specific variables to deal.II naming: +# + +FOREACH(_flag CXX_FLAGS CXX_FLAGS_RELEASE CXX_FLAGS_DEBUG) + IF(NOT "${CMAKE_${_flag}}" STREQUAL "") + MESSAGE(STATUS + "Prepending \${CMAKE_${_flag}} to \${DEAL_II_${_flag}}" + ) + SET(DEAL_II_${_flag} "${CMAKE_${_flag}} ${DEAL_II_${_flag}}") + ENDIF() +ENDFOREACH() + +FOREACH(_flag LINKER_FLAGS LINKER_FLAGS_DEBUG LINKER_FLAGS_RELEASE) + IF(NOT "${CMAKE_SHARED_${_flag}}" STREQUAL "") + MESSAGE(STATUS + "Prepending \${CMAKE_SHARED_${_flag}} to \${DEAL_II_${_flag}}" + ) + SET(DEAL_II_${_flag} "${CMAKE_${_flag}} ${DEAL_II_${_flag}}") + ENDIF() +ENDFOREACH() + +# +# Store user supplied flags in ${_flag}_SAVED and clear configuration +# variables. +# +FOREACH(_flag ${DEAL_II_USED_FLAGS}) # # The order of compiler and linker flags is important. In order to # provide an override mechanism we have to save the initial (cached) @@ -274,21 +295,15 @@ FOREACH(_flag ${DEAL_II_USED_FLAGS}) SET(${_flag} "") ENDFOREACH() -FOREACH(_variable - DEAL_II_DEFINITIONS - DEAL_II_DEFINITIONS_DEBUG - DEAL_II_DEFINITIONS_RELEASE - ) - # - # Promote to cache: - # - SET(${_variable} ${${_variable}} CACHE STRING - "Additional, user supplied compile definitions" - ) - MARK_AS_ADVANCED(${_variable}) +# +# Also set all unused CMAKE_* flags to an empty string for the +# configuration run so that it does not confuse the build system (to unset +# is not an option - it is cached...) +# +FOREACH(_flag ${DEAL_II_REMOVED_FLAGS}) + SET(${_flag} "") ENDFOREACH() - # # Finally, read in CXXFLAGS and LDFLAGS from environment and prepend them # to the saved variables: @@ -296,6 +311,7 @@ ENDFOREACH() # Also strip leading and trailing whitespace from linker flags to make # old cmake versions happy # + SET(DEAL_II_CXX_FLAGS_SAVED "$ENV{CXXFLAGS} ${DEAL_II_CXX_FLAGS_SAVED}") STRING(STRIP "${DEAL_II_CXX_FLAGS_SAVED}" DEAL_II_CXX_FLAGS_SAVED) SET(DEAL_II_LINKER_FLAGS_SAVED "$ENV{LDFLAGS} ${DEAL_II_LINKER_FLAGS_SAVED}") diff --git a/doc/news/changes.h b/doc/news/changes.h index b62949bd57..fe3edfa31f 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -365,8 +365,15 @@ inconvenience this causes. "-fuse-ld=gold" linker flag if openmpi is incompatible with it.
(Wolfgang Bangerth, Martin Kronbichler, Matthias Maier, 2016/07/13) + +
  • Fixed: CMake now handles mixed compiler and linker setup via + DEAL_II_CXX_FLAGS* / DEAL_II_LINKER_FLAGS* and + CMAKE_CXX_FLAGS* properly. +
    + (Matthias Maier, 2016/07/13)
  • +
  • Fixed: FEValues::reinit() would sometimes try to be overly clever and not re-compute information when called with the same cell twice in a row, even if the underlying triangulation had