2024-02-12 17:09:10 +02:00
|
|
|
# SPDX-License-Identifier: 0BSD
|
|
|
|
|
|
|
|
#############################################################################
|
2020-02-24 23:38:16 +02:00
|
|
|
#
|
|
|
|
# tuklib_common.cmake - common functions and macros for tuklib_*.cmake files
|
|
|
|
#
|
|
|
|
# Author: Lasse Collin
|
|
|
|
#
|
2024-02-12 17:09:10 +02:00
|
|
|
#############################################################################
|
2020-02-24 23:38:16 +02:00
|
|
|
|
|
|
|
function(tuklib_add_definitions TARGET_OR_ALL DEFINITIONS)
|
2020-02-25 20:42:31 +02:00
|
|
|
# DEFINITIONS may be an empty string/list but it's fine here. There is
|
|
|
|
# no need to quote ${DEFINITIONS} as empty arguments are fine here.
|
2020-02-24 23:38:16 +02:00
|
|
|
if(TARGET_OR_ALL STREQUAL "ALL")
|
|
|
|
add_compile_definitions(${DEFINITIONS})
|
|
|
|
else()
|
2020-02-25 20:42:31 +02:00
|
|
|
target_compile_definitions("${TARGET_OR_ALL}" PRIVATE ${DEFINITIONS})
|
2020-02-24 23:38:16 +02:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(tuklib_add_definition_if TARGET_OR_ALL VAR)
|
|
|
|
if(${VAR})
|
2020-02-25 20:42:31 +02:00
|
|
|
tuklib_add_definitions("${TARGET_OR_ALL}" "${VAR}")
|
2020-02-24 23:38:16 +02:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# This is an over-simplified version of AC_USE_SYSTEM_EXTENSIONS in Autoconf
|
|
|
|
# or gl_USE_SYSTEM_EXTENSIONS in gnulib.
|
2025-03-09 14:06:35 +02:00
|
|
|
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
|
2020-02-24 23:38:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
list(APPEND CMAKE_REQUIRED_DEFINITIONS
|
|
|
|
-D_GNU_SOURCE
|
2025-03-09 14:06:35 +02:00
|
|
|
-D_NETBSD_SOURCE
|
|
|
|
-D_OPENBSD_SOURCE
|
2020-02-24 23:38:16 +02:00
|
|
|
-D__EXTENSIONS__
|
|
|
|
-D_POSIX_PTHREAD_SEMANTICS
|
2025-03-09 14:06:35 +02:00
|
|
|
-D_DARWIN_C_SOURCE
|
2020-02-24 23:38:16 +02:00
|
|
|
-D_TANDEM_SOURCE
|
|
|
|
-D_ALL_SOURCE
|
|
|
|
)
|
|
|
|
endif()
|
2025-03-09 14:06:35 +02:00
|
|
|
endfunction()
|