summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMake/resources.cmake8
-rw-r--r--configh.cmake.in8
-rw-r--r--configh.in8
-rw-r--r--configure.ac3
-rw-r--r--src/Fl_Timeout.cxx8
5 files changed, 34 insertions, 1 deletions
diff --git a/CMake/resources.cmake b/CMake/resources.cmake
index 435ff32b8..c483a113e 100644
--- a/CMake/resources.cmake
+++ b/CMake/resources.cmake
@@ -156,10 +156,12 @@ find_library(LIB_GLEW NAMES GLEW glew32)
find_library(LIB_jpeg jpeg)
find_library(LIB_png png)
find_library(LIB_zlib z)
+find_library(LIB_m m)
mark_as_advanced(LIB_dl LIB_fontconfig LIB_freetype)
mark_as_advanced(LIB_GL LIB_MesaGL LIB_GLEW)
mark_as_advanced(LIB_jpeg LIB_png LIB_zlib)
+mark_as_advanced(LIB_m)
#######################################################################
# functions
@@ -206,6 +208,12 @@ check_function_exists(vsnprintf HAVE_VSNPRINTF)
check_function_exists(setenv HAVE_SETENV)
+if(LIB_m)
+ set(CMAKE_REQUIRED_LIBRARIES ${LIB_m})
+ check_function_exists(trunc HAVE_TRUNC)
+ set(CMAKE_REQUIRED_LIBRARIES)
+endif(LIB_m)
+
if(HAVE_SCANDIR AND NOT HAVE_SCANDIR_POSIX)
set(MSG "POSIX compatible scandir")
message(STATUS "Looking for ${MSG}")
diff --git a/configh.cmake.in b/configh.cmake.in
index 982e9f868..1bd719bbc 100644
--- a/configh.cmake.in
+++ b/configh.cmake.in
@@ -249,6 +249,14 @@
#cmakedefine01 HAVE_SETENV
/*
+ * HAVE_TRUNC:
+ *
+ * Whether or not POSIX trunc() is available from math.h.
+ */
+
+#cmakedefine01 HAVE_TRUNC
+
+/*
* Do we have various image libraries?
*/
diff --git a/configh.in b/configh.in
index 54ddf96ac..49ba71e00 100644
--- a/configh.in
+++ b/configh.in
@@ -248,6 +248,14 @@
#define HAVE_SETENV 0
/*
+ * HAVE_TRUNC:
+ *
+ * Whether or not POSIX trunc() is available from math.h.
+ */
+
+#define HAVE_TRUNC 0
+
+/*
* Do we have various image libraries?
*/
diff --git a/configure.ac b/configure.ac
index 586aec5f4..9429b0458 100644
--- a/configure.ac
+++ b/configure.ac
@@ -635,6 +635,9 @@ AC_CHECK_FUNCS([setenv])
dnl FLTK library uses math library functions...
AC_SEARCH_LIBS([pow], [m])
+AC_CHECK_HEADERS([math.h])
+AC_CHECK_FUNCS([trunc])
+
dnl Check for largefile support...
AC_SYS_LARGEFILE
diff --git a/src/Fl_Timeout.cxx b/src/Fl_Timeout.cxx
index bc3d0cb84..921c40c75 100644
--- a/src/Fl_Timeout.cxx
+++ b/src/Fl_Timeout.cxx
@@ -2,7 +2,7 @@
// Timeout support functions for the Fast Light Tool Kit (FLTK).
//
// Author: Albrecht Schlosser
-// Copyright 2021-2023 by Bill Spitzak and others.
+// Copyright 2021-2024 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -15,12 +15,18 @@
// https://www.fltk.org/bugs.php
//
+#include <config.h>
+
#include "Fl_Timeout.h"
#include "Fl_System_Driver.H"
#include <stdio.h>
#include <math.h> // for trunc()
+#if !HAVE_TRUNC
+static inline double trunc(double x) { x >= 0 ? floor(x) : ceil(x); }
+#endif // !HAVE_TRUNC
+
/**
\file Fl_Timeout.cxx
*/