Skip to content

Commit

Permalink
Autodetect availability of FPE ops
Browse files Browse the repository at this point in the history
Use CMake to detect the availability of feclearexcept, feenableexcept,
fedisableexcept.

Fixes #4645.

Signed-off-by: Paul Cercueil <[email protected]>
  • Loading branch information
pcercuei committed Jul 20, 2019
1 parent 3a314cf commit 74108bd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
endif (CMAKE_COMPILER_IS_GNUCXX)

include(CheckSymbolExists)
check_symbol_exists(feclearexcept "fenv.h" HAS_FECLEAREXCEPT)
check_symbol_exists(feenableexcept "fenv.h" HAS_FEENABLEEXCEPT)
check_symbol_exists(fedisableexcept "fenv.h" HAS_FEDISABLEEXCEPT)
if (HAS_FECLEAREXCEPT AND HAS_FEENABLEEXCEPT AND HAS_FEDISABLEEXCEPT)
set(HAS_FPE_OPS ON)
endif()

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel."
Expand Down
1 change: 1 addition & 0 deletions buildopts.h.cmakein
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@

#cmakedefine01 WITH_OBJECTVIEWER
#cmakedefine01 WITH_DEVKEYS
#cmakedefine01 HAS_FPE_OPS

#endif /* BUILDOPTS_H */
5 changes: 3 additions & 2 deletions src/posix/OSPosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "FileSystem.h"
#include "OS.h"
#include "buildopts.h"
#include <SDL.h>
#include <fenv.h>
#include <sys/time.h>
Expand Down Expand Up @@ -48,7 +49,7 @@ namespace OS {

void EnableFPE()
{
#if defined(_GNU_SOURCE) && !defined(__APPLE__)
#if HAS_FPE_OPS
// clear any outstanding exceptions before enabling, otherwise they'll
// trip immediately
feclearexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
Expand All @@ -58,7 +59,7 @@ namespace OS {

void DisableFPE()
{
#if defined(_GNU_SOURCE) && !defined(__APPLE__)
#if HAS_FPE_OPS
fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
#endif
}
Expand Down

0 comments on commit 74108bd

Please sign in to comment.