File: setup.cmake

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (705 lines) | stat: -rw-r--r-- 22,116 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
#############################################################################
# Name:        build/cmake/setup.cmake
# Purpose:     Create and configure setup.h
# Author:      Tobias Taschner
# Created:     2016-09-22
# Copyright:   (c) 2016 wxWidgets development team
# Licence:     wxWindows licence
#############################################################################

# Include modules required for setup.h generation
include(CheckCSourceCompiles)
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)
include(CheckCXXSymbolExists)
include(CheckFunctionExists)
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
include(CheckIncludeFiles)
include(CheckPrototypeDefinition)
include(CheckStructHasMember)
include(CheckSymbolExists)
include(CheckTypeSize)
include(CMakePushCheckState)
include(TestBigEndian)

# Add a definition to setup.h and append it to a list of defines for
# for compile checks
macro(wx_setup_definition def)
    set(${def} YES)
    list(APPEND CMAKE_REQUIRED_DEFINITIONS -D${def})
endmacro()

# Add define based on system name
string(TOUPPER ${CMAKE_SYSTEM_NAME} wxSYS_NAME)
wx_setup_definition(__${wxSYS_NAME}__)

if(WIN32)
    wx_setup_definition(__WIN32__)
endif()

if(CYGWIN)
    wx_setup_definition(__GNUWIN32__)
endif()

if(UNIX)
    wx_setup_definition(wxUSE_UNIX)
    wx_setup_definition(__UNIX__)
    list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_FILE_OFFSET_BITS=64)
endif()

if(UNIX AND NOT APPLE)
    wx_setup_definition(_GNU_SOURCE)
endif()

if(APPLE)
    wx_setup_definition(__BSD__)
endif()

if(WXGTK)
    # Add GTK version definitions
    foreach(gtk_version 2.0 2.10 2.18 2.20 3.0 3.90.0)
        if(NOT wxTOOLKIT_VERSION VERSION_LESS gtk_version)
            if(gtk_version EQUAL 3.90.0)
                set(__WXGTK4__ ON)
            elseif(gtk_version EQUAL 3.0)
                set(__WXGTK3__ ON)
            else()
                string(REPLACE . "" gtk_version_dotless ${gtk_version})
                set(__WXGTK${gtk_version_dotless}__ ON)
            endif()
        endif()
    endforeach()
endif()

set(wxINSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")

check_include_files("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)

if(NOT WIN32 AND wxUSE_VISIBILITY)
    check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY)
else()
    set(HAVE_VISIBILITY 0)
endif()

if(MSVC)
    set(DISABLE_ALL_WARNINGS "/w")
else()
    set(DISABLE_ALL_WARNINGS "-w")
endif()

# wx_check_cxx_source_compiles(<code> <var> [headers...])
function(wx_check_cxx_source_compiles code res_var)
    set(src)
    foreach(header ${ARGN})
        if(header STREQUAL "DEFINITION")
            set(is_definition TRUE)
        elseif(is_definition)
            set(src "${src}${header}")
            set(is_definition FALSE)
        else()
            set(src "${src}#include <${header}>\n")
        endif()
    endforeach()
    set(src "${src}\n\nint main(int argc, char* argv[]) {\n ${code}\nreturn 0; }")
    # We're not interested in any warnings that can arise in the test, which is
    # especially important if -Werror is globally in effect.
    cmake_push_check_state()
    set(CMAKE_REQUIRED_FLAGS ${DISABLE_ALL_WARNINGS})
    check_cxx_source_compiles("${src}" ${res_var})
    cmake_pop_check_state()
endfunction()

# wx_check_c_source_compiles(<code> <var> [headers...])
function(wx_check_c_source_compiles code res_var)
    set(src)
    foreach(header ${ARGN})
        if(header STREQUAL "DEFINITION")
            set(is_definition TRUE)
        elseif(is_definition)
            set(src "${src}${header}")
            set(is_definition FALSE)
        else()
            set(src "${src}#include <${header}>\n")
        endif()
    endforeach()
    set(src "${src}\n\nint main(int argc, char* argv[]) {\n ${code}\nreturn 0; }")
    check_c_source_compiles("${src}" ${res_var})
endfunction()

# wx_check_funcs(<...>)
# define a HAVE_... for every function in list if available
function(wx_check_funcs)
    foreach(func ${ARGN})
        string(TOUPPER ${func} func_upper)
        check_function_exists(${func} HAVE_${func_upper})
    endforeach()
endfunction()

if(NOT MSVC)
    check_symbol_exists(va_copy stdarg.h HAVE_VA_COPY)
    if(NOT HAVE_VA_COPY)
        # try to understand how can we copy va_lists
        set(VA_LIST_IS_ARRAY YES)
    endif()
endif()

wx_check_cxx_source_compiles("
    std::string foo, bar;
    foo.compare(bar);
    foo.compare(1, 1, bar);
    foo.compare(1, 1, bar, 1, 1);
    foo.compare(\"\");
    foo.compare(1, 1, \"\");
    foo.compare(1, 1, \"\", 2);"
    HAVE_STD_STRING_COMPARE
    string
    )

wx_check_cxx_source_compiles(
    "std::wstring s;"
    HAVE_STD_WSTRING
    string
    )

wx_check_cxx_source_compiles("
    std::hash_map<double*, char*, std::hash<double*>, std::equal_to<double*> > test1;
    std::hash_set<char*, std::hash<char*>, std::equal_to<char*> > test2;"
    HAVE_HASH_MAP
    hash_map hash_set
    )
set(HAVE_STD_HASH_MAP ${HAVE_HASH_MAP})

wx_check_cxx_source_compiles("
    __gnu_cxx::hash_map<double*, char*, __gnu_cxx::hash<double*>, std::equal_to<double*> > test1;
    __gnu_cxx::hash_set<char*, __gnu_cxx::hash<char*>, std::equal_to<char*> > test2;"
    HAVE_EXT_HASH_MAP
    ext/hash_map ext/hash_set
    )
set(HAVE_GNU_CXX_HASH_MAP ${HAVE_EXT_HASH_MAP})

wx_check_cxx_source_compiles("
    std::unordered_map<double*, char*> test1;
    std::unordered_set<char*> test2;"
    HAVE_STD_UNORDERED_MAP
    unordered_map unordered_set
    )
set(HAVE_STD_UNORDERED_SET ${HAVE_STD_UNORDERED_MAP})

wx_check_cxx_source_compiles("
    std::tr1::unordered_map<double*, char*> test1;
    std::tr1::unordered_set<char*> test2;"
    HAVE_TR1_UNORDERED_MAP
    tr1/unordered_map tr1/unordered_set
    )
set(HAVE_TR1_UNORDERED_SET ${HAVE_TR1_UNORDERED_MAP})

# Check for availability of GCC's atomic operations builtins.
wx_check_c_source_compiles("
    unsigned int value=0;
    /* wxAtomicInc doesn't use return value here */
    __sync_fetch_and_add(&value, 2);
    __sync_sub_and_fetch(&value, 1);
    /* but wxAtomicDec does, so mimic that: */
    volatile unsigned int r2 = __sync_sub_and_fetch(&value, 1);"
    HAVE_GCC_ATOMIC_BUILTINS
    )

macro(wx_get_socket_param_type name code)
    # This test needs to be done in C++ mode since gsocket.cpp now
    # is C++ code and pointer cast that are possible even without
    # warning in C still fail in C++.
    wx_check_cxx_source_compiles(
        "socklen_t len;
        ${code}"
        ${name}_IS_SOCKLEN_T
        sys/types.h sys/socket.h
        )
    if(${name}_IS_SOCKLEN_T)
        set(${name} socklen_t)
    else()
        wx_check_cxx_source_compiles(
            "size_t len;
            ${code}"
            ${name}_IS_SIZE_T
            sys/types.h sys/socket.h
            )
        if(${name}_IS_SIZE_T)
            set(${name} size_t)
        else()
            wx_check_cxx_source_compiles(
                "int len;
                ${code}"
                ${name}_IS_INT
                sys/types.h sys/socket.h
                )
            if(${name}_IS_INT)
                set(${name} int)
            else()
                message(ERROR "Couldn't find ${name} for this system")
            endif()
        endif()
    endif()
endmacro()

# the following tests are for Unix(like) systems only
if(UNIX)
    if(wxUSE_LIBICONV)
        set(HAVE_ICONV ON)
        set(ICONV_CONST " ")
        if(ICONV_SECOND_ARGUMENT_IS_CONST)
            set(ICONV_CONST "const")
        endif()
    endif()

    # check for POSIX signals if we need them
    if(wxUSE_ON_FATAL_EXCEPTION)
        wx_check_funcs(sigaction)
        if(NOT HAVE_SIGACTION)
            message(WARNING "No POSIX signal functions on this system, wxApp::OnFatalException will not be called")
            wx_option_force_value(wxUSE_ON_FATAL_EXCEPTION OFF)
        endif()
    endif()

    if(wxUSE_ON_FATAL_EXCEPTION)
        wx_check_cxx_source_compiles(
            "return 0; }
            extern void testSigHandler(int) { };
            int foo() {
            struct sigaction sa;
            sa.sa_handler = testSigHandler;"
            wxTYPE_SA_HANDLER_IS_INT
            signal.h
            )
        if(wxTYPE_SA_HANDLER_IS_INT)
            set(wxTYPE_SA_HANDLER int)
        else()
            set(wxTYPE_SA_HANDLER void)
        endif()
    endif()

    # backtrace() and backtrace_symbols() for wxStackWalker
    if(wxUSE_STACKWALKER)
        wx_check_cxx_source_compiles("
            void *trace[1];
            char **messages;
            backtrace(trace, 1);
            messages = backtrace_symbols(trace, 1);"
            wxHAVE_BACKTRACE
            execinfo.h)
        if(NOT wxHAVE_BACKTRACE)
            message(WARNING "backtrace() is not available, wxStackWalker will not be available")
            wx_option_force_value(wxUSE_STACKWALKER OFF)
        else()
            wx_check_cxx_source_compiles(
                "int rc;
                 __cxxabiv1::__cxa_demangle(\"foo\", 0, 0, &rc);"
                HAVE_CXA_DEMANGLE
                cxxabi.h)
        endif()
    endif()

    wx_check_funcs(mkstemp mktemp)

    # get the library function to use for wxGetDiskSpace(): it is statfs() under
    # Linux and *BSD and statvfs() under Solaris and NetBSD
    wx_check_c_source_compiles("
        return 0; }
        #include <sys/statvfs.h>

        int foo() {
        long l;
        struct statvfs fs;
        statvfs(\"/\", &fs);
        l = fs.f_bsize;
        l += fs.f_blocks;
        l += fs.f_bavail;"
        HAVE_STATVFS)
    if(HAVE_STATVFS)
        set(WX_STATFS_T "struct statvfs")
    else()
        wx_check_c_source_compiles("
            return 0; }
            #if defined(__BSD__)
            #include <sys/param.h>
            #include <sys/mount.h>
            #else
            #include <sys/vfs.h>
            #endif

            int foo() {
            long l;
            struct statfs fs;
            statfs(\"/\", &fs);
            l = fs.f_bsize;
            l += fs.f_blocks;
            l += fs.f_bavail;"
            HAVE_STATFS)
        if(HAVE_STATFS)
            set(WX_STATFS_T "struct statfs")
            wx_check_cxx_source_compiles("
                return 0; }
                #if defined(__BSD__)
                #include <sys/param.h>
                #include <sys/mount.h>
                #else
                #include <sys/vfs.h>
                #endif

                int foo() {
                struct statfs fs;
                statfs(\"/\", &fs);"
                HAVE_STATFS_DECL)
        endif()
    endif()

    if(NOT HAVE_STATFS AND NOT HAVE_STATVFS)
        message(WARNING "wxGetDiskSpace() function won't work without statfs()")
    endif()

    # check for fcntl() or at least flock() needed by Unix implementation of
    # wxSingleInstanceChecker
    if(wxUSE_SNGLINST_CHECKER)
        wx_check_funcs(fcntl flock)
        if(NOT HAVE_FCNTL AND NOT HAVE_FLOCK)
            message(WARNING "wxSingleInstanceChecker not available")
            wx_option_force_value(wxUSE_SNGLINST_CHECKER OFF)
        endif()
    endif()

    # look for a function to modify the environment
    wx_check_funcs(setenv putenv)
    if(HAVE_SETENV)
        wx_check_funcs(unsetenv)
    endif()

    set(HAVE_SOME_SLEEP_FUNC FALSE)
    if(APPLE)
        # Mac OS X/Darwin has both nanosleep and usleep
        # but only usleep is defined in unistd.h
        set(HAVE_USLEEP TRUE)
        set(HAVE_SOME_SLEEP_FUNC TRUE)
    endif()

    if(NOT HAVE_SOME_SLEEP_FUNC)
        # try nanosleep() in libc and libposix4, if this fails - usleep()
        check_symbol_exists(nanosleep time.h HAVE_NANOSLEEP)

        if(NOT HAVE_NANOSLEEP)
            check_symbol_exists(usleep unistd.h HAVE_USLEEP)
            if(NOT HAVE_USLEEP)
                message(WARNING "wxSleep() function will not work")
            endif()
        endif()
    endif()

    # check for uname (POSIX) and gethostname (BSD)
    check_symbol_exists(uname sys/utsname.h HAVE_UNAME)
    if(HAVE_UNAME)
        wx_check_funcs(gethostname)
    endif()

    cmake_push_check_state()
    list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_REENTRANT)
    wx_check_funcs(strtok_r)
    cmake_pop_check_state()

    # check for inet_addr and inet_aton (these may live either in libc, or in
    # libnsl or libresolv or libsocket)
    # TODO

    wx_check_funcs(fdopen)

    if(wxBUILD_LARGEFILE_SUPPORT)
        wx_check_funcs(fseeko)
    endif()

    if(wxUSE_TARSTREAM)
        wx_check_funcs(sysconf)

        cmake_push_check_state()
        list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_REENTRANT)
        check_symbol_exists(getpwuid_r pwd.h HAVE_GETPWUID_R)
        check_symbol_exists(getgrgid_r grp.h HAVE_GETGRGID_R)
        cmake_pop_check_state()
    endif()

    check_include_file(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)

    set(HAVE_UNIX98_PRINTF ON)

    if(wxUSE_SOCKETS)
        # determine the type of third argument for getsockname
        wx_get_socket_param_type(WX_SOCKLEN_T "getsockname(0, 0, &len);")
        # Do this again for getsockopt as it may be different
        wx_get_socket_param_type(SOCKOPTLEN_T "getsockopt(0, 0, 0, 0, &len);")

        check_symbol_exists(gethostbyname netdb.h HAVE_GETHOSTBYNAME)
        check_symbol_exists(gethostbyname_r netdb.h HAVE_GETHOSTBYNAME_R)
        if(HAVE_GETHOSTBYNAME_R)
            check_prototype_definition(gethostbyname_r
                "int gethostbyname_r(const char *name, struct hostent *hp, struct hostent_data *hdata)"
                "0"
                "netdb.h"
                HAVE_FUNC_GETHOSTBYNAME_R_3)

            check_prototype_definition(gethostbyname_r
                "struct hostent *gethostbyname_r(const char *name, struct hostent *hp, char *buf, size_t buflen, int *herr)"
                "NULL"
                "netdb.h"
                HAVE_FUNC_GETHOSTBYNAME_R_5)

            check_prototype_definition(gethostbyname_r
                "int gethostbyname_r(const char *name, struct hostent *hp, char *buf, size_t buflen, struct hostent **result, int *herr)"
                "0"
                "netdb.h"
                HAVE_FUNC_GETHOSTBYNAME_R_6)
        endif()

        check_symbol_exists(getservbyname netdb.h HAVE_GETSERVBYNAME)
        check_symbol_exists(inet_aton arpa/inet.h HAVE_INET_ATON)
        check_symbol_exists(inet_addr arpa/inet.h HAVE_INET_ADDR)
    endif(wxUSE_SOCKETS)

    if(wxUSE_JOYSTICK AND WXGTK)
        check_include_files("linux/joystick.h" HAVE_JOYSTICK_H)
        if(NOT HAVE_JOYSTICK_H)
            message(WARNING "wxJoystick is not available")
            wx_option_force_value(wxUSE_JOYSTICK OFF)
        endif()
    endif()
endif(UNIX)

if(CMAKE_USE_PTHREADS_INIT)
    cmake_push_check_state(RESET)
    set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
    wx_check_cxx_source_compiles("
        void *p;
        pthread_cleanup_push(ThreadCleanupFunc, p);
        pthread_cleanup_pop(0);"
        wxHAVE_PTHREAD_CLEANUP
        pthread.h
        DEFINITION
        "void ThreadCleanupFunc(void *p) { }\;"
        )
    wx_check_c_source_compiles(
        "pthread_mutexattr_t attr;
        pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);"
        HAVE_PTHREAD_MUTEXATTR_T
        pthread.h
        )
    if(HAVE_PTHREAD_MUTEXATTR_T)
        # check if we already have the declaration we need, it is not
        # present in some systems' headers
        wx_check_c_source_compiles(
            "pthread_mutexattr_t attr;
            pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);"
            HAVE_PTHREAD_MUTEXATTR_SETTYPE_DECL
            pthread.h
            )
    else()
        # don't despair, there may be another way to do it
        wx_check_c_source_compiles(
            "pthread_mutex_t attr = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;"
            HAVE_PTHREAD_RECURSIVE_MUTEX_INITIALIZER
            pthread.h
            )
        if(NOT HAVE_PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
            # this may break code working elsewhere, so at least warn about it
            message(WARNING "wxMutex won't be recursive on this platform")
        endif()
    endif()
    if(wxUSE_COMPILER_TLS)
        # test for compiler thread-specific variables support
        wx_check_c_source_compiles("
            static __thread int n = 0;
            static __thread int *p = 0;"
            HAVE___THREAD_KEYWORD
            pthread.h
            )
        wx_check_cxx_source_compiles(
            "void foo(abi::__forced_unwind&);"
            HAVE_ABI_FORCEDUNWIND
            cxxabi.h)
    endif()
    cmake_pop_check_state()
endif() # CMAKE_USE_PTHREADS_INIT

check_symbol_exists(localtime_r time.h HAVE_LOCALTIME_R)
check_symbol_exists(gmtime_r time.h HAVE_GMTIME_R)

# ---------------------------------------------------------------------------
# Checks for typedefs
# ---------------------------------------------------------------------------

# check what exactly size_t is on this machine - this is necessary to avoid
# ambiguous overloads in several places, notably wx/string.h and wx/array.h

# an obvious check like wx_check_cxx_source_compiles(struct Foo { ... };) doesn't work
# with egcs (at least) up to 1.1.1 as it allows you to compile duplicate
# methods in a local class (i.e. class inside a function) declaration
# without any objections!!
#
# hence the hack below: we must have Foo at global scope!
wx_check_cxx_source_compiles("return 0; }

            struct Foo { void foo(size_t); void foo(unsigned int); };

            int bar() {"
            wxSIZE_T_IS_NOT_UINT
            stddef.h)
if(wxSIZE_T_IS_NOT_UINT)
    wx_check_cxx_source_compiles("return 0; }

            struct Foo { void foo(size_t); void foo(unsigned long); };

            int bar() {"
            wxSIZE_T_IS_NOT_ULONG
            stddef.h)
    if(NOT wxSIZE_T_IS_NOT_ULONG)
        set(wxSIZE_T_IS_ULONG YES)
    endif()
else()
    set(wxSIZE_T_IS_UINT YES)
endif()

# check if wchar_t is separate type
wx_check_cxx_source_compiles("return 0; }

            struct Foo { void foo(wchar_t);
                         void foo(unsigned short);
                         void foo(unsigned int);
                         void foo(unsigned long); };

            int bar() {"
            wxWCHAR_T_IS_REAL_TYPE
            wchar.h)

# ---------------------------------------------------------------------------
# Checks for structures
# ---------------------------------------------------------------------------

check_struct_has_member("struct passwd" pw_gecos pwd.h HAVE_PW_GECOS)

# ---------------------------------------------------------------------------
# Check for functions
# ---------------------------------------------------------------------------

# Check various string symbols
foreach(func
    ftime
    wcsftime wprintf
    putws fputws wprintf vswprintf vswscanf
    wcsdup wcsnlen wcscasecmp wcsncasecmp
    wcsrctombs
    wcstoull
    wcslen
    )
    string(TOUPPER ${func} func_upper)
    check_symbol_exists(${func} wchar.h HAVE_${func_upper})
endforeach()

# Check various functions
wx_check_funcs(fsync
               snprintf vsnprintf strnlen strtoull
               setpriority
               gettimeofday
               )

if(MSVC)
    check_symbol_exists(vsscanf stdio.h HAVE_VSSCANF)
endif()

# at least under IRIX with mipsPro the C99 round() function is available when
# building using the C compiler but not when using C++ one
check_cxx_symbol_exists(round math.h HAVE_ROUND)

# Check includes
if(NOT MSVC_VERSION LESS 1600)
    check_include_file_cxx(tr1/type_traits HAVE_TR1_TYPE_TRAITS)
    check_include_file_cxx(type_traits HAVE_TYPE_TRAITS)
endif()
check_include_file(fcntl.h HAVE_FCNTL_H)
check_include_file(langinfo.h HAVE_LANGINFO_H)
check_include_file(sched.h HAVE_SCHED_H)
check_include_file(unistd.h HAVE_UNISTD_H)
check_include_file(wchar.h HAVE_WCHAR_H)
check_include_file(wcstr.h HAVE_WCSTR_H)

if(wxUSE_DATETIME)
    # check for timezone variable
    #   doesn't exist under Darwin / Mac OS X which uses tm_gmtoff instead
    foreach(timezone_def timezone _timezone __timezone)
        wx_check_cxx_source_compiles("
            int tz;
            tz = ${timezone_def};"
        wxTEST_TZ_${timezone_def}
        time.h
        )
        if(${wxTEST_TZ_${timezone_def}})
            set(WX_TIMEZONE ${timezone_def})
            break()
        endif()
    endforeach()

    check_struct_has_member("struct tm" tm_gmtoff time.h WX_GMTOFF_IN_TM)
endif()

cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN)
cmake_pop_check_state()
if(HAVE_DLOPEN)
    check_symbol_exists(dladdr dlfcn.h HAVE_DLADDR)
endif()

if(APPLE)
    set(wxUSE_EPOLL_DISPATCHER OFF)
    set(wxUSE_SELECT_DISPATCHER ON)
else()
    if(NOT WIN32)
        set(wxUSE_SELECT_DISPATCHER ON)
    endif()
    check_include_file(sys/epoll.h wxUSE_EPOLL_DISPATCHER)
endif()
check_include_file(sys/select.h HAVE_SYS_SELECT_H)

if(wxUSE_FSWATCHER)
    check_include_file(sys/inotify.h wxHAS_INOTIFY)
    if(NOT wxHAS_INOTIFY)
        check_include_file(sys/event.h wxHAS_KQUEUE)
    endif()
endif()

if(wxUSE_XLOCALE)
    check_include_file(xlocale.h HAVE_XLOCALE_H)
    set(CMAKE_EXTRA_INCLUDE_FILES locale.h)
    if(HAVE_XLOCALE_H)
        list(APPEND CMAKE_EXTRA_INCLUDE_FILES xlocale.h)
    endif()
    check_type_size(locale_t LOCALE_T)
    set(CMAKE_EXTRA_INCLUDE_FILES)
endif()

# Check sizes of various types
set(SYSTYPES size_t wchar_t int long short)

foreach(SYSTYPE ${SYSTYPES})
    string(TOUPPER ${SYSTYPE} SYSTYPE_UPPER)
    check_type_size(${SYSTYPE} SIZEOF_${SYSTYPE_UPPER})
    if(NOT HAVE_SIZEOF_${SYSTYPE_UPPER})
        # Add a definition if it is not available
        set(${SYSTYPE} ON)
    endif()
endforeach()

check_type_size("long long" SIZEOF_LONG_LONG)
check_type_size(ssize_t SSIZE_T)

test_big_endian(WORDS_BIGENDIAN)

configure_file(build/cmake/setup.h.in ${wxSETUP_HEADER_FILE})
if(DEFINED wxSETUP_HEADER_FILE_DEBUG)
    # The debug version may be configured with different values in the future
    configure_file(build/cmake/setup.h.in ${wxSETUP_HEADER_FILE_DEBUG})
endif()