IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 7948ce1f authored by Ralf Ulrich's avatar Ralf Ulrich
Browse files

Merge branch 'osx-brew-fixes' into 'master'

OSX brew fixes

See merge request AirShowerPhysics/corsika!60
parents 33f597da 43942e1a
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
include (CorsikaUtilities) # a few cmake function
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_EXTENSIONS OFF)
enable_testing ()
set (CTEST_OUTPUT_ON_FAILURE 1)
......@@ -42,12 +43,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g") # -O2 would not trade speed for size, neither O2/3 use fast-math
# clang produces a lot of unecessary warnings without this:
add_compile_options("$<$<CXX_COMPILER_ID:Clang>:-Wno-nonportable-include-path>")
# check if we are on OSX:
if (APPLE)
add_compile_definitions (CORSIKA_OSX)
endif (APPLE)
add_compile_options("$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-Wno-nonportable-include-path>")
# unit testing coverage, does not work yet
#include (CodeCoverage)
......@@ -65,6 +61,10 @@ endif (APPLE)
# dependencies
find_package (Boost 1.60 REQUIRED)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif (Boost_FOUND)
find_package (Eigen3 REQUIRED)
#find_package (HDF5) # not yet needed
......
......@@ -31,10 +31,11 @@
#include <corsika/random/RNGManager.h>
#include <corsika/utl/CorsikaFenv.h>
#include <boost/type_index.hpp>
using boost::typeindex::type_id_with_cvr;
#include <fenv.h>
#include <iostream>
#include <limits>
#include <typeinfo>
......
#
# 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
)
${CORSIKA_FENV})
set (
UTILITIES_HEADERS
COMBoost.h
Bit.h
Singleton.h
CorsikaFenv.h
)
set (
......@@ -58,5 +77,13 @@ target_link_libraries (
CORSIKAutilities
CORSIKAthirdparty # for catch2
)
CORSIKA_ADD_TEST(testCOMBoost)
add_executable (testCorsikaFenv testCorsikaFenv.cc)
target_link_libraries (
testCorsikaFenv
CORSIKAutilities
CORSIKAthirdparty # for catch2
)
CORSIKA_ADD_TEST(testCOMBoost)
add_test(testCorsikaFenv testCorsikaFenv)
/**
* (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 portable or fallback versions of feenableexcept() and fedisableexcept()
* Exist by default in glibc since version 2.2, but not in the standard
* fenv.h / cfenv headers for C 99 or C++ 11
*
* \author Lukas Nellen
* \date 14 Jan 2019
*
*/
#ifndef CORSIKA_CORSIKAFENV_H
#define CORSIKA_CORSIKAFENV_H
#include <cfenv>
/*
* Same declaration of function as provided in GLIBC
* Repetition allowed in the case where cfenv defines the functions already, no clash.
*/
extern "C" {
int
feenableexcept(int excepts);
int
fedisableexcept(int excepts);
}
#endif //CORSIKA_CORSIKAFENV_H
/**
* (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
/**
* (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;
}
}
/**
* 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
* fenv.h / cfenv headers for C 99 or C++ 11
*
* \author Lukas Nellen
* \date 14 Jan 2019
*
*/
#include <corsika/utl/CorsikaFenv.h>
#include <cfenv>
// 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
extern "C" {
int
feenableexcept(int excepts) {
static fenv_t fenv;
int new_excepts = excepts & FE_ALL_EXCEPT;
// previous masks
int old_excepts;
if (fegetenv(&fenv)) {
return -1;
}
old_excepts = fenv.__control & FE_ALL_EXCEPT;
// unmask
fenv.__control &= ~new_excepts;
fenv.__mxcsr &= ~(new_excepts << 7);
return fesetenv(&fenv) ? -1 : old_excepts;
}
int
fedisableexcept(int excepts) {
static fenv_t fenv;
int new_excepts = excepts & FE_ALL_EXCEPT;
// all previous masks
int old_excepts;
if (fegetenv(&fenv)) {
return -1;
}
old_excepts = fenv.__control & FE_ALL_EXCEPT;
// mask
fenv.__control |= new_excepts;
fenv.__mxcsr |= new_excepts << 7;
return fesetenv(&fenv) ? -1 : old_excepts;
}
}
/**
* (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.
*/
#include <corsika/utl/CorsikaFenv.h>
#include <cmath>
#include <iostream>
#include <csignal>
extern "C" {
static void
handle_fpe(int /*signo*/ ) {
exit(0);
}
}
int
main() {
feenableexcept(FE_ALL_EXCEPT);
signal(SIGFPE, handle_fpe);
std::cout << std::log(0.) << std::endl;
exit(1);
}
\ No newline at end of file
/**
* (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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment