Michal Vasko | 7a20d2e | 2021-05-19 16:40:23 +0200 | [diff] [blame] | 1 | # - Use compat library providing various functions and macros that may be missing on some systems |
| 2 | # Once done this will define |
| 3 | # |
| 4 | # compatsrc - sources to add to compilation |
| 5 | # |
| 6 | # Additionally, "compat.h" include directory is added and can be included. |
| 7 | # |
| 8 | # Author Michal Vasko <mvasko@cesnet.cz> |
| 9 | # Copyright (c) 2021 CESNET, z.s.p.o. |
| 10 | # |
| 11 | # This source code is licensed under BSD 3-Clause License (the "License"). |
| 12 | # You may not use this file except in compliance with the License. |
| 13 | # You may obtain a copy of the License at |
| 14 | # |
| 15 | # https://opensource.org/licenses/BSD-3-Clause |
| 16 | # |
Michal Vasko | 9e8ac26 | 2020-04-07 13:06:45 +0200 | [diff] [blame] | 17 | include(CheckSymbolExists) |
Michal Vasko | 7a20d2e | 2021-05-19 16:40:23 +0200 | [diff] [blame] | 18 | include(CheckFunctionExists) |
| 19 | include(CheckIncludeFile) |
Michal Vasko | 9e8ac26 | 2020-04-07 13:06:45 +0200 | [diff] [blame] | 20 | include(TestBigEndian) |
Michal Vasko | 7a20d2e | 2021-05-19 16:40:23 +0200 | [diff] [blame] | 21 | if(POLICY CMP0075) |
| 22 | cmake_policy(SET CMP0075 NEW) |
| 23 | endif() |
Michal Vasko | 9e8ac26 | 2020-04-07 13:06:45 +0200 | [diff] [blame] | 24 | |
| 25 | macro(USE_COMPAT) |
| 26 | # compatibility checks |
| 27 | set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200809L) |
| 28 | list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) |
Michal Vasko | 1ca3fa4 | 2020-05-29 08:43:45 +0200 | [diff] [blame] | 29 | list(APPEND CMAKE_REQUIRED_DEFINITIONS -D__BSD_VISIBLE=1) |
Michal Vasko | 7a20d2e | 2021-05-19 16:40:23 +0200 | [diff] [blame] | 30 | set(CMAKE_REQUIRED_LIBRARIES pthread) |
| 31 | |
Michal Vasko | 9e8ac26 | 2020-04-07 13:06:45 +0200 | [diff] [blame] | 32 | check_symbol_exists(vdprintf "stdio.h;stdarg.h" HAVE_VDPRINTF) |
| 33 | check_symbol_exists(asprintf "stdio.h" HAVE_ASPRINTF) |
| 34 | check_symbol_exists(vasprintf "stdio.h" HAVE_VASPRINTF) |
Michal Vasko | 7a20d2e | 2021-05-19 16:40:23 +0200 | [diff] [blame] | 35 | check_symbol_exists(getline "stdio.h" HAVE_GETLINE) |
| 36 | |
| 37 | check_symbol_exists(strndup "string.h" HAVE_STRNDUP) |
| 38 | check_symbol_exists(strnstr "string.h" HAVE_STRNSTR) |
| 39 | check_symbol_exists(strdupa "string.h" HAVE_STRDUPA) |
| 40 | check_symbol_exists(strchrnul "string.h" HAVE_STRCHRNUL) |
Michal Vasko | 9e8ac26 | 2020-04-07 13:06:45 +0200 | [diff] [blame] | 41 | |
| 42 | check_symbol_exists(get_current_dir_name "unistd.h" HAVE_GET_CURRENT_DIR_NAME) |
| 43 | |
Michal Vasko | 7a20d2e | 2021-05-19 16:40:23 +0200 | [diff] [blame] | 44 | check_function_exists(pthread_mutex_timedlock HAVE_PTHREAD_MUTEX_TIMEDLOCK) |
Michal Vasko | 9e8ac26 | 2020-04-07 13:06:45 +0200 | [diff] [blame] | 45 | |
Michal Vasko | 652eaa6 | 2020-04-21 14:11:21 +0200 | [diff] [blame] | 46 | TEST_BIG_ENDIAN(IS_BIG_ENDIAN) |
Michal Vasko | 9e8ac26 | 2020-04-07 13:06:45 +0200 | [diff] [blame] | 47 | |
Michal Vasko | 7a20d2e | 2021-05-19 16:40:23 +0200 | [diff] [blame] | 48 | check_include_file("stdatomic.h" HAVE_STDATOMIC) |
| 49 | |
| 50 | unset(CMAKE_REQUIRED_DEFINITIONS) |
| 51 | unset(CMAKE_REQUIRED_LIBRARIES) |
| 52 | |
| 53 | # header and source file (adding the source directly allows for hiding its symbols) |
| 54 | configure_file(${PROJECT_SOURCE_DIR}/compat/compat.h.in ${PROJECT_BINARY_DIR}/compat/compat.h @ONLY) |
| 55 | include_directories(${PROJECT_BINARY_DIR}/compat) |
| 56 | set(compatsrc ${PROJECT_SOURCE_DIR}/compat/compat.c) |
Michal Vasko | 9e8ac26 | 2020-04-07 13:06:45 +0200 | [diff] [blame] | 57 | endmacro() |