From 5a0ef580bf85bc0cd4cf3b3bd7780c6e117844d5 Mon Sep 17 00:00:00 2001 From: Charles Karney Date: Sun, 6 Aug 2017 11:29:18 -0400 Subject: Add tests for C99 math functions, hypot, atanh, cbrt, etc. This tests whether the functions are declared in . If they are, then -DHAVE_C99_MATH=1 is added to the C flags. The intention is that this flag is only seen when building proj.4 and shouldn't be referenced in any of the installed include files. The next update to geodesic.c will use this flag. Left unaddressed is what to do if HAVE_C99_MATH is 0. The strategy in geodesic.c is to assume that the missing functions will need to be defined explicitly. A less safe alternative is to assume that the functions are in fact available in libm and that all that needs to be done is to declare the functions. --- CMakeLists.txt | 22 ++++++++++++++++++++++ configure.ac | 14 ++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb0cbcba..a6d5ae05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,28 @@ if (HAVE_PTHREAD_MUTEX_RECURSIVE_DEFN) add_definitions(-DHAVE_PTHREAD_MUTEX_RECURSIVE=1) endif() +include (CheckCSourceCompiles) +if (MSVC) + set (CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS} /WX") +else + set (CMAKE_REQUIRED_LIBRARIES m) + set (CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS} -Werror") +endif () +# Check whether the C99 math function: hypot, atanh, etc. are available. +check_c_source_compiles ( + "#include +int main() { + int q; + return (int)(hypot(3.0, 4.0) + atanh(0.8) + cbrt(8.0) + + remquo(100.0, 90.0, &q) + + remainder(100.0, 90.0) + copysigna(1.0, -0.0)); +}\n" C99_MATH) +if (C99_MATH) + add_definitions (-DHAVE_C99_MATH=1) +else () + add_definitions (-DHAVE_C99_MATH=0) +endif () + boost_report_value(PROJ_PLATFORM_NAME) boost_report_value(PROJ_COMPILER_NAME) diff --git a/configure.ac b/configure.ac index 68df28ec..e99389ee 100644 --- a/configure.ac +++ b/configure.ac @@ -29,6 +29,20 @@ CFLAGS="$save_CFLAGS" dnl We check for headers AC_HEADER_STDC +dnl Check for C99 math functions +save_CFLAGS="$CFLAGS" +CFLAGS="$CFLAGS -Wall -Werror" +AC_MSG_CHECKING([for C99 math functions]) +AC_LINK_IFELSE([AC_LANG_PROGRAM( + [#include ], + [int q; + return (int)(hypot(3.0, 4.0) + atanh(0.8) + cbrt(8.0) + + remquo(100.0, 90.0, &q) + + remainder(100.0, 90.0) + copysign(1.0, -0.0));])], + [AC_MSG_RESULT([yes]);C99_MATH="-DHAVE_C99_MATH=1"], + [AC_MSG_RESULT([no]);C99_MATH="-DHAVE_C99_MATH=0"]) +CFLAGS="$save_CFLAGS $C99_MATH" + AC_CHECK_FUNC(localeconv, [AC_DEFINE(HAVE_LOCALECONV,1,[Define to 1 if you have localeconv])]) dnl --------------------------------------------------------------------------- -- cgit v1.2.3