From 56e8ee301e6bd817df3c8b9b3ddad4d89675570d Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Thu, 27 Aug 2015 17:23:21 -0500 Subject: [PATCH] CMake: Refactor DEAL_II_HAVE_FP_EXCEPTIONS - this is a language feature, not a platform feature, so move it to check_01_cxx_features.cmake - A test that _runs_ code *_must_* be guarded with DEAL_II_ALLOW_PLATFORM_INTROSPECTION - Demote DEAL_II_HAVE_FP_EXCEPTIONS to an ordinary variable. Naming convetion: Variables starting with "DEAL_II_HAVE" must be ordinary variables, or internal, cached variables. Note: It is not necessary to promote DEAL_II_HAVE_FP_EXCEPTIONS to cache in order to override it with -DDEAL_II_HAVE_FP_EXCEPTIONS... --- cmake/checks/check_01_cxx_features.cmake | 55 +++++++++++++++++++++ cmake/checks/check_02_system_features.cmake | 41 --------------- include/deal.II/base/config.h.in | 2 +- 3 files changed, 56 insertions(+), 42 deletions(-) diff --git a/cmake/checks/check_01_cxx_features.cmake b/cmake/checks/check_01_cxx_features.cmake index c39599d7a4..e154e345f2 100644 --- a/cmake/checks/check_01_cxx_features.cmake +++ b/cmake/checks/check_01_cxx_features.cmake @@ -25,6 +25,7 @@ # DEAL_II_HAVE_ISNAN # DEAL_II_HAVE_UNDERSCORE_ISNAN # DEAL_II_HAVE_ISFINITE +# DEAL_II_HAVE_FP_EXCEPTIONS # @@ -463,3 +464,57 @@ CHECK_CXX_SOURCE_COMPILES( " DEAL_II_HAVE_ISFINITE) + +# +# Check that we can use feenableexcept. Sets DEAL_II_HAVE_FP_EXCEPTIONS +# +# The test is a bit more complicated because we also check that no garbage +# exception is thrown if we convert -std::numeric_limits::max to a +# string. This sadly happens with some compiler support libraries :-( +# +# - Timo Heister, 2015 +# + +IF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION) + CHECK_CXX_SOURCE_RUNS( + " + #include + #include + #include + + int main() + { + feenableexcept(FE_DIVBYZERO|FE_INVALID); + std::ostringstream description; + const double lower_bound = -std::numeric_limits::max(); + + description << lower_bound; + + return 0; + } + " + DEAL_II_HAVE_FP_EXCEPTIONS) +ELSE() + # + # If we are not allowed to do platform introspection, just test whether + # we can compile above code. + # + CHECK_CXX_SOURCE_COMPILES( + " + #include + #include + #include + + int main() + { + feenableexcept(FE_DIVBYZERO|FE_INVALID); + std::ostringstream description; + const double lower_bound = -std::numeric_limits::max(); + + description << lower_bound; + + return 0; + } + " + DEAL_II_HAVE_FP_EXCEPTIONS) +ENDIF() diff --git a/cmake/checks/check_02_system_features.cmake b/cmake/checks/check_02_system_features.cmake index a9c1ac4550..655e5eb561 100644 --- a/cmake/checks/check_02_system_features.cmake +++ b/cmake/checks/check_02_system_features.cmake @@ -19,7 +19,6 @@ # DEAL_II_HAVE_GETHOSTNAME # DEAL_II_HAVE_GETPID # DEAL_II_HAVE_JN -# DEAL_II_HAVE_FP_EXCEPTIONS # DEAL_II_HAVE_SYS_RESOURCE_H # DEAL_II_HAVE_SYS_TIME_H # DEAL_II_HAVE_SYS_TIMES_H @@ -68,46 +67,6 @@ IF(NOT m_LIBRARY MATCHES "-NOTFOUND") ENDIF() -# -# Check that we can use feenableexcept. Sets DEAL_II_HAVE_FP_EXCEPTIONS -# -# The test is a bit more complicated because we also check that no garbage -# exception is thrown if we convert -std::numeric_limits::max to a -# string. This sadly happens with some compiler support libraries :-( - -INCLUDE (CheckCXXSourceRuns) - -CHECK_CXX_SOURCE_RUNS(" - #include - #include - #include - - int main() - { - feenableexcept(FE_DIVBYZERO|FE_INVALID); - std::ostringstream description; - const double lower_bound = -std::numeric_limits::max(); - - description << lower_bound; - - return 0; - } - " - _HAVE_FP_EXCEPTIONS) - - -SET(DEAL_II_HAVE_FP_EXCEPTIONS ON CACHE BOOL "If ON, floating point exception are raised in debug mode when running the testsuite.") - -IF (DEAL_II_HAVE_FP_EXCEPTIONS) - IF(_HAVE_FP_EXCEPTIONS) - MESSAGE(STATUS "Checking for Floating Point Exception macros -- Success") - # nothing to set here -- DEAL_II_HAVE_FP_EXCEPTIONS is already ON - ELSE() - MESSAGE(STATUS "Checking for Floating Point Exception macros -- Failed") - SET(DEAL_II_HAVE_FP_EXCEPTIONS OFF CACHE BOOL "" FORCE) - ENDIF() -ENDIF() - ######################################################################## # # diff --git a/include/deal.II/base/config.h.in b/include/deal.II/base/config.h.in index 1e219c7e5f..72863f63b2 100644 --- a/include/deal.II/base/config.h.in +++ b/include/deal.II/base/config.h.in @@ -111,6 +111,7 @@ #cmakedefine DEAL_II_HAVE_STD_ISNAN #cmakedefine DEAL_II_HAVE_UNDERSCORE_ISNAN #cmakedefine DEAL_II_HAVE_ISFINITE +#cmakedefine DEAL_II_HAVE_FP_EXCEPTIONS /*********************************************************************** @@ -128,7 +129,6 @@ #cmakedefine DEAL_II_HAVE_GETPID #cmakedefine DEAL_II_HAVE_TIMES #cmakedefine DEAL_II_HAVE_JN -#cmakedefine DEAL_II_HAVE_FP_EXCEPTIONS #cmakedefine DEAL_II_MSVC -- 2.39.5