From c1ea7bd0b60eed6ebcdf9a713ca69034f6f07179 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Sun, 9 Mar 2025 14:06:35 +0200 Subject: [PATCH] CMake: Revise tuklib_use_system_extensions Define NetBSD and Darwin/macOS feature test macros. Autoconf defines these too (and a few others). Define the macros on Windows except with MSVC. The _GNU_SOURCE macro makes a difference with mingw-w64. Use a function instead of a macro. Don't take the TARGET_OR_ALL argument because there's always global effect because the global variable CMAKE_REQUIRED_DEFINITIONS is modified. --- CMakeLists.txt | 2 +- cmake/tuklib_common.cmake | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3de1321f..32506cdd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -286,7 +286,7 @@ endif() # _GNU_SOURCE and such definitions. This specific macro is special since # it also adds the definitions to CMAKE_REQUIRED_DEFINITIONS. -tuklib_use_system_extensions(ALL) +tuklib_use_system_extensions() # Check for large file support. It's required on some 32-bit platforms and # even on 64-bit MinGW-w64 to get 64-bit off_t. This can be forced off on diff --git a/cmake/tuklib_common.cmake b/cmake/tuklib_common.cmake index a7f101fa..b575506a 100644 --- a/cmake/tuklib_common.cmake +++ b/cmake/tuklib_common.cmake @@ -26,25 +26,28 @@ endfunction() # This is an over-simplified version of AC_USE_SYSTEM_EXTENSIONS in Autoconf # or gl_USE_SYSTEM_EXTENSIONS in gnulib. -macro(tuklib_use_system_extensions TARGET_OR_ALL) - if(NOT WIN32) - # FIXME? The Solaris-specific __EXTENSIONS__ should be conditional - # even on Solaris. See gnulib: git log m4/extensions.m4. - # FIXME? gnulib and autoconf.git has lots of new stuff. - tuklib_add_definitions("${TARGET_OR_ALL}" - _GNU_SOURCE - __EXTENSIONS__ - _POSIX_PTHREAD_SEMANTICS - _TANDEM_SOURCE - _ALL_SOURCE +function(tuklib_use_system_extensions) + if(NOT MSVC) + add_compile_definitions( + _GNU_SOURCE # glibc, musl, mingw-w64 + _NETBSD_SOURCE # NetBSD, MINIX 3 + _OPENBSD_SOURCE # Also NetBSD! + __EXTENSIONS__ # Solaris + _POSIX_PTHREAD_SEMANTICS # Solaris + _DARWIN_C_SOURCE # macOS + _TANDEM_SOURCE # HP NonStop + _ALL_SOURCE # AIX, z/OS ) list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE + -D_NETBSD_SOURCE + -D_OPENBSD_SOURCE -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS + -D_DARWIN_C_SOURCE -D_TANDEM_SOURCE -D_ALL_SOURCE ) endif() -endmacro() +endfunction()