From f852e1bd3062c5784941bcb00c0c49b8a2bd9fcf Mon Sep 17 00:00:00 2001 From: maier Date: Thu, 20 Sep 2012 00:11:17 +0000 Subject: [PATCH] Prettify the macros git-svn-id: https://svn.dealii.org/branches/branch_cmake@26540 0785d39b-7218-0410-832d-ea1e28bc413d --- .../check/check_for_compiler_features.cmake | 5 +- .../cmake/macros/macro_add_flags.cmake | 6 + .../macros/macro_check_cxx_compiler_bug.cmake | 19 +-- .../macros/macro_configure_feature.cmake | 124 ++++++++---------- .../macros/macro_enable_if_supported.cmake | 12 +- .../macros/macro_expand_instantiations.cmake | 8 +- .../macro_get_cxx_source_return_value.cmake | 3 + .../cmake/macros/macro_list_contains.cmake | 11 ++ .../cmake/macros/macro_strip_flag.cmake | 6 + 9 files changed, 109 insertions(+), 85 deletions(-) diff --git a/deal.II/contrib/cmake/check/check_for_compiler_features.cmake b/deal.II/contrib/cmake/check/check_for_compiler_features.cmake index 85f590a2b4..c5f0ba59c1 100644 --- a/deal.II/contrib/cmake/check/check_for_compiler_features.cmake +++ b/deal.II/contrib/cmake/check/check_for_compiler_features.cmake @@ -3,10 +3,12 @@ # + # # Check whether the std::vector::iterator is just a plain pointer # -CHECK_CXX_COMPILER_BUG( # Yes. It is not a bug. But the logic is the same. +# (Yes. It is not a bug. But the logic is the same.) +CHECK_CXX_COMPILER_BUG( " #include template void f(T) {} @@ -398,3 +400,4 @@ IF(NOT CMAKE_SYSTEM_NAME MATCHES "CYGWIN") ENABLE_IF_SUPPORTED(CMAKE_CXX_FLAGS_DEBUG "-Wa,--compress-debug-sections") ENABLE_IF_SUPPORTED(CMAKE_C_FLAGS_DEBUG "-Wa,--compress-debug-sections") ENDIF() + diff --git a/deal.II/contrib/cmake/macros/macro_add_flags.cmake b/deal.II/contrib/cmake/macros/macro_add_flags.cmake index 38acfad7ab..3e4728de9c 100644 --- a/deal.II/contrib/cmake/macros/macro_add_flags.cmake +++ b/deal.II/contrib/cmake/macros/macro_add_flags.cmake @@ -1,3 +1,9 @@ +# +# A small macro used for (string-)appending flags to a variable +# +# Usage: +# ADD_FLAGS(variable flag) +# MACRO(ADD_FLAGS variable flag) SET(${variable} "${${variable}} ${flag}") diff --git a/deal.II/contrib/cmake/macros/macro_check_cxx_compiler_bug.cmake b/deal.II/contrib/cmake/macros/macro_check_cxx_compiler_bug.cmake index 0e38b74598..d69350adc8 100644 --- a/deal.II/contrib/cmake/macros/macro_check_cxx_compiler_bug.cmake +++ b/deal.II/contrib/cmake/macros/macro_check_cxx_compiler_bug.cmake @@ -1,12 +1,15 @@ -INCLUDE(CheckCXXSourceCompiles) +# +# Check for a compiler bug. +# +# Usage: +# CHECK_CXX_COMPILER_BUG(source var) +# +# where source is a snipped of source code and var is a variable that will +# be set to true if source could not be compiled and linked successfully. +# (This just inverts the logic of CHECK_CXX_SOURCE_COMPILES.) +# MACRO(CHECK_CXX_COMPILER_BUG source var) - - # - # Check for a compiler bug, i.e. if source does not compile, define var - # This just inverts the logic of CHECK_CXX_SOURCE_COMPILES. - # - CHECK_CXX_SOURCE_COMPILES( "${source}" ${var}_OK) @@ -17,5 +20,5 @@ MACRO(CHECK_CXX_COMPILER_BUG source var) MESSAGE(STATUS "Test unsuccessful, define ${var}") SET(${var} 1) ENDIF() - ENDMACRO() + diff --git a/deal.II/contrib/cmake/macros/macro_configure_feature.cmake b/deal.II/contrib/cmake/macros/macro_configure_feature.cmake index 37e3e421a7..18a319777d 100644 --- a/deal.II/contrib/cmake/macros/macro_configure_feature.cmake +++ b/deal.II/contrib/cmake/macros/macro_configure_feature.cmake @@ -1,65 +1,65 @@ # -# This macro is used in the feature configuration mechanism of deal.II +# This macro is used for the feature configuration in deal.II # # Usage: +# CONFIGURE_FEATURE(feature) # -# CONFIGURE_FEATURE(feature) # +# For a feature ${feature} (written in all caps) the following options, +# variables and macros have to be defined (except marked as optional): # -# This macro assumes the following macros and variables to be defined: +# DEAL_II_WITH_${feature} (option, mandatory) +# determines whether the feature will be configured, if +# DEAL_II_FEATURE_AUTODETECTION is OFF. If +# DEAL_II_FEATURE_AUTODETECTION is ON, this option will be set if +# configuring the feature was successful. # # FEATURE_${feature}_DEPENDS (variable, optional) -# -# a variable which contains an optional list of features this feature -# depends on (and which have to be enbled for this feature to work.) -# +# a variable which contains an optional list of other features +# this feature depends on (and which have to be enbled for this feature +# to work.) The features must be given with the full option toggle: +# DEAL_II_WITH_[...] # # FEATURE_${feature}_HAVE_CONTRIB (variable, optional) -# -# which shall either be set to TRUE if all necessary libraries of the +# which should either be set to TRUE if all necessary libraries of the # features comes bundled with deal.II and hence can be supported # without external dependencies, or unset. # # FEATURE_${feature}_CONFIGURE_CONTRIB(var) (macro, optional) +# which should setup all necessary configuration for the feature with +# contrib source dependencies. var set to TRUE indicates success, +# otherwise this script gives an error. # -# which shall setup all necessary configuration for the feature with -# contrib source dependencies. var set to TRUE shall indicate success. -# -# -# FEATURE_${feature}_FIND_EXTERNAL(var) (macro) -# -# which shall set var to TRUE if all dependencies for the feature are +# FEATURE_${feature}_FIND_EXTERNAL(var) (macro, mandatory) +# which should set var to TRUE if all dependencies for the feature are # fullfilled. In this case all necessary variables for # FEATURE_${feature}_CONFIGURE_EXTERNAL must be set. Otherwise # var should remain unset. +# This macro should give an error (SEND_ERROR or FATAL_ERROR). # -# FEATURE_${feature}_CONFIGURE_EXTERNAL(var) (macro) -# -# which shall setup all necessary configuration for the feature with -# external dependencies. var set to TRUE shall indicate success. +# FEATURE_${feature}_CONFIGURE_EXTERNAL(var) (macro, mandatory) # +# which should setup all necessary configuration for the feature with +# external dependencies. var set to TRUE indicates success, +# otherwise this script gives an error. # # FEATURE_${feature}_CUSTOM_ERROR_MESSAGE() (variable, optional) -# -# which shall either be set to TRUE if FEATURE_${feature}_ERROR_MESSAGE +# which should either be set to TRUE if FEATURE_${feature}_ERROR_MESSAGE # is set up, or be undefined. # # FEATURE_${feature}_ERROR_MESSAGE() (macro, optional) -# -# which shall print a meaningfull error message if case no external -# library is found (and contrib is not allowed to be used.) -# If not defined, a suitable default error message will be printed. +# which should print a meaningfull error message (with SEND_ERROR) for +# the case that no external library was found (and contrib is not +# allowed to be used.) If not defined, a suitable default error message +# will be printed. # # + # -# FAT NOTE: -# This script is arcane black magic. But at least for the better good: We -# don't have to copy the configuration logic to every single -# configure_.cmake script. +# Some helper macros: # - # # Some black magic to have substitution in command names: # @@ -83,7 +83,7 @@ ENDMACRO() # -# A small macro to post an error message: +# A small macro to post a default error message: # MACRO(FEATURE_ERROR_MESSAGE feature) STRING(TOLOWER ${feature} feature_lowercase) @@ -109,6 +109,12 @@ ENDMACRO() MACRO(CONFIGURE_FEATURE feature) + # + # This script is arcane black magic. But at least for the better good: We + # don't have to copy the configuration logic to every single + # configure_.cmake script... + # + # # Check for correct include order of the configure_*.cmake files: @@ -127,18 +133,17 @@ MACRO(CONFIGURE_FEATURE feature) ENDIF() ENDFOREACH() - + # # Only try to configure ${feature} if we have to: + # IF(DEAL_II_FEATURE_AUTODETECTION OR DEAL_II_WITH_${feature}) # # Are all dependencies fullfilled? # SET(macro_dependencies_ok TRUE) - FOREACH(macro_dependency ${FEATURE_${feature}_DEPENDS}) IF(NOT ${macro_dependency}) - IF(DEAL_II_FEATURE_AUTODETECTION) MESSAGE(STATUS "DEAL_II_WITH_${feature} has unmet configuration requirements: " @@ -151,25 +156,19 @@ MACRO(CONFIGURE_FEATURE feature) "${macro_dependency} has to be set to \"ON\"." ) ENDIF() - SET(macro_dependencies_ok FALSE) ENDIF() ENDFOREACH() - IF(macro_dependencies_ok) - # - # First case: DEAL_II_FORCE_CONTRIB_${feature} is defined: - # IF(DEAL_II_FORCE_CONTRIB_${feature}) + # + # First case: DEAL_II_FORCE_CONTRIB_${feature} is defined: + # IF(FEATURE_${feature}_HAVE_CONTRIB) RUN_COMMAND( - " - FEATURE_${feature}_CONFIGURE_CONTRIB( - FEATURE_${feature}_CONTRIB_CONFIGURED - ) - " + "FEATURE_${feature}_CONFIGURE_CONTRIB(FEATURE_${feature}_CONTRIB_CONFIGURED)" ) IF(FEATURE_${feature}_CONTRIB_CONFIGURED) MESSAGE(STATUS @@ -192,26 +191,20 @@ MACRO(CONFIGURE_FEATURE feature) ENDIF() ELSE(DEAL_II_FORCE_CONTRIB_${feature}) - # - # Second case: We are allowed to search for an external library: + # Second case: We are allowed to search for an external library # + RUN_COMMAND( "FEATURE_${feature}_FIND_EXTERNAL(FEATURE_${feature}_EXTERNAL_FOUND)" ) IF(FEATURE_${feature}_EXTERNAL_FOUND) - MESSAGE(STATUS "All external dependencies for DEAL_II_WITH_${feature} are fullfilled." ) - RUN_COMMAND( - " - FEATURE_${feature}_CONFIGURE_EXTERNAL( - FEATURE_${feature}_EXTERNAL_CONFIGURED - ) - " + "FEATURE_${feature}_CONFIGURE_EXTERNAL(FEATURE_${feature}_EXTERNAL_CONFIGURED)" ) IF(FEATURE_${feature}_EXTERNAL_CONFIGURED) @@ -228,7 +221,7 @@ MACRO(CONFIGURE_FEATURE feature) ) ENDIF() - ELSE() + ELSE(FEATURE_${feature}_EXTERNAL_FOUND) MESSAGE(STATUS "DEAL_II_WITH_${feature} has unmet external dependencies." @@ -236,11 +229,7 @@ MACRO(CONFIGURE_FEATURE feature) IF(FEATURE_${feature}_HAVE_CONTRIB AND DEAL_II_ALLOW_CONTRIB) RUN_COMMAND( - " - FEATURE_${feature}_CONFIGURE_CONTRIB( - FEATURE_${feature}_CONTRIB_CONFIGURED - ) - " + "FEATURE_${feature}_CONFIGURE_CONTRIB(FEATURE_${feature}_CONTRIB_CONFIGURED)" ) IF(FEATURE_${feature}_CONTRIB_CONFIGURED) MESSAGE(STATUS @@ -260,22 +249,17 @@ MACRO(CONFIGURE_FEATURE feature) SET_CACHED_OPTION(DEAL_II_WITH_${feature} OFF) ELSE() IF(FEATURE_${feature}_CUSTOM_ERROR_MESSAGE) - RUN_COMMAND( - " - FEATURE_${feature}_ERROR_MESSAGE() - " - ) + RUN_COMMAND("FEATURE_${feature}_ERROR_MESSAGE()") ELSE() FEATURE_ERROR_MESSAGE(${feature}) ENDIF() ENDIF() ENDIF() - ENDIF() - ENDIF(DEAL_II_FORCE_CONTRIB_${feature}) - ENDIF() - - ENDIF() + ENDIF(FEATURE_${feature}_EXTERNAL_FOUND) + ENDIF(DEAL_II_FORCE_CONTRIB_${feature}) + ENDIF(macro_dependencies_ok) + ENDIF(DEAL_II_FEATURE_AUTODETECTION OR DEAL_II_WITH_${feature}) SET(FEATURE_${feature}_PROCESSED TRUE) diff --git a/deal.II/contrib/cmake/macros/macro_enable_if_supported.cmake b/deal.II/contrib/cmake/macros/macro_enable_if_supported.cmake index 04753df5fb..c936958d88 100644 --- a/deal.II/contrib/cmake/macros/macro_enable_if_supported.cmake +++ b/deal.II/contrib/cmake/macros/macro_enable_if_supported.cmake @@ -1,8 +1,18 @@ +# +# Tests whether the cxx compiler understands flag. If so, add it to +# variable. +# +# Usage: +# ENABLE_IF_SUPPORTED(variable flag) +# + MACRO(ENABLE_IF_SUPPORTED variable flag) CHECK_CXX_COMPILER_FLAG( "${flag}" - DEAL_II_HAVE_FLAG_${flag}) + DEAL_II_HAVE_FLAG_${flag} + ) IF(DEAL_II_HAVE_FLAG_${flag}) SET(${variable} "${${variable}} ${flag}") ENDIF() ENDMACRO() + diff --git a/deal.II/contrib/cmake/macros/macro_expand_instantiations.cmake b/deal.II/contrib/cmake/macros/macro_expand_instantiations.cmake index 8c37612fdd..7336bff86a 100644 --- a/deal.II/contrib/cmake/macros/macro_expand_instantiations.cmake +++ b/deal.II/contrib/cmake/macros/macro_expand_instantiations.cmake @@ -1,9 +1,8 @@ # -# A macro for the inst.in file expansion: +# A macro for the inst.in file expansion # # Usage: -# -# macro_expand_instantiations(target inst_in_files) +# macro_expand_instantiations(target inst_in_files) # # Options: # @@ -18,7 +17,6 @@ # MACRO(macro_expand_instantiations target inst_in_files) - FOREACH (inst_in_file ${inst_in_files}) STRING(REGEX REPLACE "\\.in$" "" inst_file "${inst_in_file}" ) @@ -49,5 +47,5 @@ MACRO(macro_expand_instantiations target inst_in_files) # before target will be processed. # ADD_DEPENDENCIES(${target} ${target}.inst) - ENDMACRO() + diff --git a/deal.II/contrib/cmake/macros/macro_get_cxx_source_return_value.cmake b/deal.II/contrib/cmake/macros/macro_get_cxx_source_return_value.cmake index 1ebc0301ed..e79b3b0889 100644 --- a/deal.II/contrib/cmake/macros/macro_get_cxx_source_return_value.cmake +++ b/deal.II/contrib/cmake/macros/macro_get_cxx_source_return_value.cmake @@ -1,3 +1,6 @@ +# +# TODO: Description... +# MACRO(GET_CXX_SOURCE_RETURN_VALUE SOURCE VAR EXIT_CODE) # diff --git a/deal.II/contrib/cmake/macros/macro_list_contains.cmake b/deal.II/contrib/cmake/macros/macro_list_contains.cmake index 6e38d25519..e806c67883 100644 --- a/deal.II/contrib/cmake/macros/macro_list_contains.cmake +++ b/deal.II/contrib/cmake/macros/macro_list_contains.cmake @@ -1,3 +1,13 @@ +# +# A small macro to test whether a given list contains an element. +# +# Usage: +# LIST_CONTAINS(var value list) +# +# var is set to true if list contains value as an element compared via +# STREQUAL. +# + MACRO(LIST_CONTAINS var value) SET(${var}) FOREACH (value2 ${ARGN}) @@ -6,3 +16,4 @@ MACRO(LIST_CONTAINS var value) ENDIF (${value} STREQUAL ${value2}) ENDFOREACH (value2) ENDMACRO(LIST_CONTAINS) + diff --git a/deal.II/contrib/cmake/macros/macro_strip_flag.cmake b/deal.II/contrib/cmake/macros/macro_strip_flag.cmake index fd663fc2cf..d5d046c555 100644 --- a/deal.II/contrib/cmake/macros/macro_strip_flag.cmake +++ b/deal.II/contrib/cmake/macros/macro_strip_flag.cmake @@ -1,3 +1,9 @@ +# +# Remove the first occurence of flag in the string variable. +# +# Usage: +# STRIP_FLAG(variable flag) +# MACRO(STRIP_FLAG variable flag) IF(NOT "${variable}" STREQUAL "") -- 2.39.5