diff --git a/Framework/Utilities/CMakeLists.txt b/Framework/Utilities/CMakeLists.txt index 4f68582b0d551701cd454e8758927c8688cb2da4..2f9b8e1e40676418860ba5217677e56222834685 100644 --- a/Framework/Utilities/CMakeLists.txt +++ b/Framework/Utilities/CMakeLists.txt @@ -1,8 +1,26 @@ +# +# cfenv feature test - select implementation to use +# +try_compile (HAS_FEENABLEEXCEPT "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/try_feenableexcept.cc") +if (HAS_FEENABLEEXCEPT) + set (CORSIKA_FENV "CorsikaFenvDefault.cc") + set_property(DIRECTORY ${CMAKE_HOME_DIRECTORY} APPEND PROPERTY COMPILE_DEFINITIONS "HAS_FEENABLEEXCEPT") +else () + if (APPLE) + set (CORSIKA_FENV "CorsikaFenvOSX.cc") + else() + set (CORSIKA_FENV "CorsikaFenvFallback.cc") + endif() +endif () + +# +# library setup +# set ( UTILITIES_SOURCES COMBoost.cc - CorsikaFenv.cc) + ${CORSIKA_FENV}) set ( UTILITIES_HEADERS diff --git a/Framework/Utilities/CorsikaFenv.h b/Framework/Utilities/CorsikaFenv.h index eeaecef96692347f54aace9839194e3132f422c4..e1977d6d2ec5178ae518538e2ef07dc0d74ac6ea 100644 --- a/Framework/Utilities/CorsikaFenv.h +++ b/Framework/Utilities/CorsikaFenv.h @@ -21,7 +21,10 @@ #include <cfenv> -#if !defined(__GLIBC__) +/* + * Same declaration of function as provided in GLIBC + * Repetition allowed in the case where cfenv defines the functions already, no clash. + */ extern "C" { int @@ -30,6 +33,5 @@ extern "C" { fedisableexcept(int excepts); } -#endif #endif //CORSIKA_CORSIKAFENV_H diff --git a/Framework/Utilities/CorsikaFenvDefault.cc b/Framework/Utilities/CorsikaFenvDefault.cc new file mode 100644 index 0000000000000000000000000000000000000000..f51fe55dca288307ecd0a8d7a86419d7c03e1dc0 --- /dev/null +++ b/Framework/Utilities/CorsikaFenvDefault.cc @@ -0,0 +1,20 @@ +/** + * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu + * + * See file AUTHORS for a list of contributors. + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + * + * Versions of feenableexcept() and fedisableexcept() + * exist in fenv.h / cfenv headers for C 99 or C++ 11 + * Nothing needed. + * + * + * \author Lukas Nellen + * \date 14 Jan 2019 + * + */ + +// do nothing, functions exist in system libraries diff --git a/Framework/Utilities/CorsikaFenvFallback.cc b/Framework/Utilities/CorsikaFenvFallback.cc new file mode 100644 index 0000000000000000000000000000000000000000..ad495c4d3b0bc7396490fbcededc1d44c767806d --- /dev/null +++ b/Framework/Utilities/CorsikaFenvFallback.cc @@ -0,0 +1,37 @@ +/** + * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu + * + * See file AUTHORS for a list of contributors. + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + * + * Provide fallback versions of feenableexcept() and fedisableexcept() + * Don't exist in the standard + * fenv.h / cfenv headers for C 99 or C++ 11 + * + * For platforms without implementation; do-nothing dummy. + * + * \author Lukas Nellen + * \date 14 Jan 2019 + * + */ + +#include <corsika/utl/CorsikaFenv.h> +#include <cfenv> + +extern "C" { +#warning No enabling/disabling of floating point exceptions - platform needs better implementation + + int feenableexcept(int excepts) + { + return -1; + } + + int fedisableexcept(int excepts) + { + return -1; + } + +} diff --git a/Framework/Utilities/CorsikaFenv.cc b/Framework/Utilities/CorsikaFenvOSX.cc similarity index 66% rename from Framework/Utilities/CorsikaFenv.cc rename to Framework/Utilities/CorsikaFenvOSX.cc index 145adb4761f40938a101d05a8f4d6c6bb087efce..224e04e733da6cf760e91fe5e94873afe7848898 100644 --- a/Framework/Utilities/CorsikaFenv.cc +++ b/Framework/Utilities/CorsikaFenvOSX.cc @@ -1,11 +1,5 @@ /** - * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu - * - * See file AUTHORS for a list of contributors. - * - * This software is distributed under the terms of the GNU General Public - * Licence version 3 (GPL Version 3). See file LICENSE for a full version of - * the license. + * Import public domain code * * Provide portable or fallback versions of feenableexcept() and fedisableexcept() * Exist by default in glibc since version 2.2, but not in the standard @@ -19,11 +13,7 @@ #include <corsika/utl/CorsikaFenv.h> #include <cfenv> -#if defined(__GLIBC__) -// do nothing functions exist - -#elif defined(__APPLE__) && defined(__MACH__) -// Implementation of OS X on intel X64_86 +// Implementation for OS X on intel X64_86 // code from https://stackoverflow.com/questions/37819235/how-do-you-enable-floating-point-exceptions-for-clang-in-os-x // based on http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c @@ -68,23 +58,3 @@ extern "C" { } } - -#else -// unknown environment, dummy implementations - -extern "C" { -#warning No enabling/disabling of floating point exceptions - - int feenableexcept(int excepts) - { - return -1; - } - - int fedisableexcept(int excepts) - { - return -1; - } - -} - -#endif diff --git a/Framework/Utilities/try_feenableexcept.cc b/Framework/Utilities/try_feenableexcept.cc new file mode 100644 index 0000000000000000000000000000000000000000..270307b407a85881bcbc273c67c44e8d4e2dad60 --- /dev/null +++ b/Framework/Utilities/try_feenableexcept.cc @@ -0,0 +1,24 @@ +/** + * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu + * + * See file AUTHORS for a list of contributors. + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + * + * Test code for cmake to check if feenableexcept exists in cfenv + * + * \author Lukas Nellen + * \date 15 Jan 2019 + * + */ + +#include <cfenv> + +int +main() +{ + feenableexcept(FE_ALL_EXCEPT); + return 0; +} \ No newline at end of file