mirror of
https://github.com/fltk/fltk.git
synced 2026-02-06 00:01:57 +08:00
Add replacement for potentially missing trunc() (#944)
- add configure + CMake checks to define HAVE_TRUNC in config.h - src/Fl_Timeout.cxx: add local replacement function
This commit is contained in:
@@ -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}")
|
||||
|
||||
@@ -248,6 +248,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?
|
||||
*/
|
||||
|
||||
@@ -247,6 +247,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?
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user