]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cmake/config-ix.cmake
Vendor import of libc++ trunk r300422:
[FreeBSD/FreeBSD.git] / cmake / config-ix.cmake
1 include(CheckLibraryExists)
2 include(CheckCCompilerFlag)
3 include(CheckCXXCompilerFlag)
4
5 if(WIN32 AND NOT MINGW)
6   # NOTE(compnerd) this is technically a lie, there is msvcrt, but for now, lets
7   # let the default linking take care of that.
8   set(LIBCXX_HAS_C_LIB NO)
9 else()
10   check_library_exists(c fopen "" LIBCXX_HAS_C_LIB)
11 endif()
12
13 if (NOT LIBCXX_USE_COMPILER_RT)
14   if(WIN32 AND NOT MINGW)
15     set(LIBCXX_HAS_GCC_S_LIB NO)
16   else()
17     check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXX_HAS_GCC_S_LIB)
18   endif()
19 endif()
20
21 # libc++ is built with -nodefaultlibs, so we want all our checks to also
22 # use this option, otherwise we may end up with an inconsistency between
23 # the flags we think we require during configuration (if the checks are
24 # performed without -nodefaultlibs) and the flags that are actually
25 # required during compilation (which has the -nodefaultlibs). libc is
26 # required for the link to go through. We remove sanitizers from the
27 # configuration checks to avoid spurious link errors.
28 check_c_compiler_flag(-nodefaultlibs LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG)
29 if (LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG)
30   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
31   if (LIBCXX_HAS_C_LIB)
32     list(APPEND CMAKE_REQUIRED_LIBRARIES c)
33   endif ()
34   if (LIBCXX_USE_COMPILER_RT)
35     list(APPEND CMAKE_REQUIRED_FLAGS -rtlib=compiler-rt)
36     find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
37     list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBCXX_BUILTINS_LIBRARY}")
38   elseif (LIBCXX_HAS_GCC_S_LIB)
39     list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
40   endif ()
41   if (MINGW)
42     # Mingw64 requires quite a few "C" runtime libraries in order for basic
43     # programs to link successfully with -nodefaultlibs.
44     list(APPEND CMAKE_REQUIRED_LIBRARIES mingw32 gcc gcc_eh mingwex msvcrt gcc)
45   endif()
46   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
47     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
48   endif ()
49   if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES -fsanitize-coverage)
50     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters")
51   endif ()
52 endif ()
53
54 if(NOT WIN32 OR MINGW)
55   include(CheckLibcxxAtomic)
56 endif()
57
58 # Check compiler flags
59
60 check_cxx_compiler_flag(/WX                     LIBCXX_HAS_WX_FLAG)
61 check_cxx_compiler_flag(/WX-                    LIBCXX_HAS_NO_WX_FLAG)
62 check_cxx_compiler_flag(/EHsc                   LIBCXX_HAS_EHSC_FLAG)
63 check_cxx_compiler_flag(/EHs-                   LIBCXX_HAS_NO_EHS_FLAG)
64 check_cxx_compiler_flag(/EHa-                   LIBCXX_HAS_NO_EHA_FLAG)
65 check_cxx_compiler_flag(/GR-                    LIBCXX_HAS_NO_GR_FLAG)
66
67
68 # Check libraries
69 if(WIN32 AND NOT MINGW)
70   # TODO(compnerd) do we want to support an emulation layer that allows for the
71   # use of pthread-win32 or similar libraries to emulate pthreads on Windows?
72   set(LIBCXX_HAS_PTHREAD_LIB NO)
73   set(LIBCXX_HAS_M_LIB NO)
74   set(LIBCXX_HAS_RT_LIB NO)
75 else()
76   check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB)
77   check_library_exists(m ccos "" LIBCXX_HAS_M_LIB)
78   check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB)
79 endif()