From 5329f80b32f965bd528496bb30916e7b268473c2 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 5 Mar 2023 17:51:55 +0100 Subject: [PATCH] Fix build errors with Cygwin (fixes #3639) --- src/filemanager.cpp | 5 +++-- src/proj_internal.h | 25 +++++++++++++++++++++---- test/unit/CMakeLists.txt | 8 ++++++++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/filemanager.cpp b/src/filemanager.cpp index 67215e1428..69a1cf6a94 100644 --- a/src/filemanager.cpp +++ b/src/filemanager.cpp @@ -29,6 +29,9 @@ #define FROM_PROJ_CPP #endif +// proj_config.h must be included before testing HAVE_LIBDL +#include "proj_config.h" + #if defined(HAVE_LIBDL) && !defined(_GNU_SOURCE) // Required for dladdr() on Cygwin #define _GNU_SOURCE @@ -50,8 +53,6 @@ #include -#include "proj_config.h" - #ifdef _WIN32 #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) #define UWP 1 diff --git a/src/proj_internal.h b/src/proj_internal.h index 785c849235..c50f1a6166 100644 --- a/src/proj_internal.h +++ b/src/proj_internal.h @@ -132,8 +132,21 @@ */ #ifndef M_PI #define M_PI 3.14159265358979323846 +#endif + +#ifndef M_1_PI +#define M_1_PI 0.318309886183790671538 +#endif + +#ifndef M_PI_2 #define M_PI_2 1.57079632679489661923 +#endif + +#ifndef M_PI_4 #define M_PI_4 0.78539816339744830962 +#endif + +#ifndef M_2_PI #define M_2_PI 0.63661977236758134308 #endif @@ -143,10 +156,14 @@ #endif /* some more useful math constants and aliases */ -#define M_FORTPI M_PI_4 /* pi/4 */ -#define M_HALFPI M_PI_2 /* pi/2 */ -#define M_PI_HALFPI 4.71238898038468985769 /* 1.5*pi */ -#define M_TWOPI 6.28318530717958647693 /* 2*pi */ +#define M_FORTPI M_PI_4 /* pi/4 */ +#define M_HALFPI M_PI_2 /* pi/2 */ +#define M_PI_HALFPI 4.71238898038468985769 /* 1.5*pi */ + +#ifndef M_TWOPI +#define M_TWOPI 6.28318530717958647693 /* 2*pi */ +#endif + #define M_TWO_D_PI M_2_PI /* 2/pi */ #define M_TWOPI_HALFPI 7.85398163397448309616 /* 2.5*pi */ diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index e1221ef4eb..1ec1dcb892 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -35,6 +35,14 @@ message(STATUS "Using internal GTest") configure_file( ${PROJ_SOURCE_DIR}/test/googletest/CMakeLists.txt.in ${PROJ_BINARY_DIR}/googletest-download/CMakeLists.txt) + +if(CYGWIN) +# needed at least with gcc 11.3.0 Cygwin, otherwise build errors in +# in googletest-src/googletest/include/gtest/internal/gtest-port.h related to +# fileno() and other functions, when building gtest or including it +add_definitions(-D_GNU_SOURCE) +endif() + execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . RESULT_VARIABLE result WORKING_DIRECTORY ${PROJ_BINARY_DIR}/googletest-download)