From: maier Date: Tue, 18 Sep 2012 19:37:57 +0000 (+0000) Subject: Some progress in the quest for sane compiler flags... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe2008175a92e579391d08dc796664c2a9501a9f;p=dealii-svn.git Some progress in the quest for sane compiler flags... git-svn-id: https://svn.dealii.org/branches/branch_cmake@26481 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/contrib/cmake/setup_cached_compiler_flags.cmake b/deal.II/contrib/cmake/setup_cached_compiler_flags.cmake index d9df7c961b..700653081b 100644 --- a/deal.II/contrib/cmake/setup_cached_compiler_flags.cmake +++ b/deal.II/contrib/cmake/setup_cached_compiler_flags.cmake @@ -12,15 +12,23 @@ # process CMAKE_{C|CXX}_FLAGS are already set to stupid default values. # (And _cannot_ be sanely set from this script afterwards...) # -# To mitigate this problem, we do the following: We set cached -# CMAKE_{C|CXX}_FLAGS variables with empty strings prior to initializing -# the compiler, so that no default values are set. +# To mitigate this problem, we do the following: # -# The compiler-flag setup in setup_compiler_flags.cmake later adds our -# (target and platform dependend) default choice of flags. +# - We initialize the cached CMAKE_{C|CXX}_FLAGS variables with empty +# strings prior to initializing the compiler, so that no default values +# are set. # -# We add the cached variables _to the end_ of this default choice to allow -# the user to overwrite our choice of compiler flags. +# - We save the cached variables (possibly altered by the user via command +# line or ccmake) in _SAVED and set to an empty +# string. +# +# - This way we can happily set our default flags in +# setup_compiler_flags.cmake (if the user lets us, see +# DEAL_II_SETUP_DEFAULT_COMPILER_FLAGS) +# +# - At the end of the configuration step we add _SAVED +# _AT THE END_ of the respective allowing the user to +# effectively overwrite our default setting. # @@ -35,9 +43,11 @@ SET(CMAKE_BUILD_TYPE IF( NOT CMAKE_BUILD_TYPE MATCHES "Release" AND NOT CMAKE_BUILD_TYPE MATCHES "Debug" ) - + # + # This is cruel, I know. But it is better to only have a known number of + # options for CMAKE_BUILD_TYPE... + # MESSAGE(FATAL_ERROR "CMAKE_BUILD_TYPE does neither match Release, nor Debug.") - ENDIF() @@ -55,16 +65,19 @@ SET(deal_ii_used_flags ) FOREACH(flags ${deal_ii_used_flags}) + # "CACHE" ensures that we only set the variable if it is not already set + # as a cached variable, effectively we're setting a default value: SET(${flags} "" CACHE STRING "The user supplied cache variable will be appended _at the end_ of the auto generated ${flags} variable" ) - # - # Save the cached variable at this point and clear it. - # ${flags}_SAVED will be appended to ${flags} in - # setup_cached_compiler_flags_finalize.cmake (called at the end of the - # main CMakeLists.txt file). - # - SET(${flags}_SAVED "${${flags}}") - SET(${flags} "") + # + # Save the initial (cached) variable at this point and clear it. + # ${flags}_SAVED will be appended to ${flags} in + # setup_cached_compiler_flags_finalize.cmake (called at the end of the + # main CMakeLists.txt file). + # + SET(${flags}_SAVED "${${flags}}") + SET(${flags} "") ENDFOREACH() + diff --git a/deal.II/contrib/cmake/setup_finalize.cmake b/deal.II/contrib/cmake/setup_finalize.cmake index e77a847a28..5310a4a403 100644 --- a/deal.II/contrib/cmake/setup_finalize.cmake +++ b/deal.II/contrib/cmake/setup_finalize.cmake @@ -1,13 +1,17 @@ # -# Append the saved cache variable ${flags}_SAVED at the end of ${flags} +# Append the saved initial (cached) variables ${flags}_SAVED at the end of +# ${flags}, see setup_cached_compiler_flags.cmake and the main +# CMakeLists.txt for details. # FOREACH(flags ${deal_ii_used_flags}) SET(${flags} "${${flags}} ${${flags}_SAVED}") ENDFOREACH() + # # And print out a nice configuration summary: # + MESSAGE(" * *