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