4a33fd4b580227a125f4931a4c9337d44ed46ce9
[flac.git] / cmake / UseSystemExtensions.cmake
1 cmake_minimum_required(VERSION 3.12)
2
3 include(CheckCSourceCompiles)
4
5 check_c_source_compiles("
6     int main()
7     {
8     #ifndef _FORTIFY_SOURCE
9         return 0;
10     #else
11         this_is_an_error;
12     #endif
13     }"
14     DODEFINE_FORTIFY_SOURCE)
15 check_c_source_compiles("
16     #include <wchar.h>
17     mbstate_t x;
18     int main() { return 0; }"
19     HAVE_MBSTATE)
20 if(NOT HAVE_MBSTATE)
21     check_c_source_compiles("
22         #define _XOPEN_SOURCE 500
23         #include <wchar.h>
24         mbstate_t x;
25         int main() { return 0; }"
26         DODEFINE_XOPEN_SOURCE)
27 endif()
28 check_c_source_compiles("
29     #define __EXTENSIONS__ 1
30     #include <stdio.h>
31     #ifdef HAVE_SYS_TYPES_H
32     # include <sys/types.h>
33     #endif
34     #ifdef HAVE_SYS_STAT_H
35     # include <sys/stat.h>
36     #endif
37     #ifdef STDC_HEADERS
38     # include <stdlib.h>
39     # include <stddef.h>
40     #else
41     # ifdef HAVE_STDLIB_H
42     #  include <stdlib.h>
43     # endif
44     #endif
45     #ifdef HAVE_STRING_H
46     # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
47     #  include <memory.h>
48     # endif
49     # include <string.h>
50     #endif
51     #ifdef HAVE_STRINGS_H
52     # include <strings.h>
53     #endif
54     #ifdef HAVE_INTTYPES_H
55     # include <inttypes.h>
56     #endif
57     #ifdef HAVE_STDINT_H
58     # include <stdint.h>
59     #endif
60     #ifdef HAVE_UNISTD_H
61     # include <unistd.h>
62     #endif
63     int main() { return 0; }"
64     DODEFINE_EXTENSIONS)
65
66 add_compile_definitions(
67     _ALL_SOURCE
68     _DARWIN_C_SOURCE
69     _GNU_SOURCE
70     _POSIX_PTHREAD_SEMANTICS
71     __STDC_WANT_IEC_60559_ATTRIBS_EXT__
72     __STDC_WANT_IEC_60559_BFP_EXT__
73     __STDC_WANT_IEC_60559_DFP_EXT__
74     __STDC_WANT_IEC_60559_FUNCS_EXT__
75     __STDC_WANT_IEC_60559_TYPES_EXT__
76     __STDC_WANT_LIB_EXT2__
77     __STDC_WANT_MATH_SPEC_FUNCS__
78     _TANDEM_SOURCE
79     $<$<AND:$<BOOL:${DODEFINE_FORTIFY_SOURCE}>,$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>>:_FORTIFY_SOURCE=2>
80     $<$<BOOL:${DODEFINE_XOPEN_SOURCE}>:_XOPEN_SOURCE=500>
81     $<$<BOOL:${DODEFINE_EXTENTIONS}>:__EXTENSIONS__>)