config-ix.cmake 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. include(CMakePushCheckState)
  2. include(CheckCCompilerFlag)
  3. include(CheckCXXCompilerFlag)
  4. include(CheckLibraryExists)
  5. include(CheckSymbolExists)
  6. include(CheckCSourceCompiles)
  7. check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB)
  8. if (NOT LIBUNWIND_USE_COMPILER_RT)
  9. if (ANDROID)
  10. check_library_exists(gcc __gcc_personality_v0 "" LIBUNWIND_HAS_GCC_LIB)
  11. else ()
  12. check_library_exists(gcc_s __gcc_personality_v0 "" LIBUNWIND_HAS_GCC_S_LIB)
  13. check_library_exists(gcc __absvdi2 "" LIBUNWIND_HAS_GCC_LIB)
  14. endif ()
  15. endif()
  16. # libunwind is using -nostdlib++ at the link step when available,
  17. # otherwise -nodefaultlibs is used. We want all our checks to also
  18. # use one of these options, otherwise we may end up with an inconsistency between
  19. # the flags we think we require during configuration (if the checks are
  20. # performed without one of those options) and the flags that are actually
  21. # required during compilation (which has the -nostdlib++ or -nodefaultlibs). libc is
  22. # required for the link to go through. We remove sanitizers from the
  23. # configuration checks to avoid spurious link errors.
  24. check_c_compiler_flag(-nostdlib++ LIBUNWIND_SUPPORTS_NOSTDLIBXX_FLAG)
  25. if (LIBUNWIND_SUPPORTS_NOSTDLIBXX_FLAG)
  26. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
  27. else()
  28. check_c_compiler_flag(-nodefaultlibs LIBUNWIND_SUPPORTS_NODEFAULTLIBS_FLAG)
  29. if (LIBUNWIND_SUPPORTS_NODEFAULTLIBS_FLAG)
  30. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
  31. endif()
  32. endif()
  33. if (LIBUNWIND_SUPPORTS_NOSTDLIBXX_FLAG OR LIBUNWIND_SUPPORTS_NODEFAULTLIBS_FLAG)
  34. if (LIBUNWIND_HAS_C_LIB)
  35. list(APPEND CMAKE_REQUIRED_LIBRARIES c)
  36. endif ()
  37. if (LIBUNWIND_USE_COMPILER_RT)
  38. find_compiler_rt_library(builtins LIBUNWIND_BUILTINS_LIBRARY)
  39. list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBUNWIND_BUILTINS_LIBRARY}")
  40. else ()
  41. if (LIBUNWIND_HAS_GCC_S_LIB)
  42. list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
  43. endif ()
  44. if (LIBUNWIND_HAS_GCC_LIB)
  45. list(APPEND CMAKE_REQUIRED_LIBRARIES gcc)
  46. endif ()
  47. endif ()
  48. if (MINGW)
  49. # Mingw64 requires quite a few "C" runtime libraries in order for basic
  50. # programs to link successfully with -nodefaultlibs.
  51. if (LIBUNWIND_USE_COMPILER_RT)
  52. set(MINGW_RUNTIME ${LIBUNWIND_BUILTINS_LIBRARY})
  53. else ()
  54. set(MINGW_RUNTIME gcc_s gcc)
  55. endif()
  56. set(MINGW_LIBRARIES mingw32 ${MINGW_RUNTIME} moldname mingwex msvcrt advapi32
  57. shell32 user32 kernel32 mingw32 ${MINGW_RUNTIME}
  58. moldname mingwex msvcrt)
  59. list(APPEND CMAKE_REQUIRED_LIBRARIES ${MINGW_LIBRARIES})
  60. endif()
  61. if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
  62. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
  63. endif ()
  64. if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES -fsanitize-coverage)
  65. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters")
  66. endif ()
  67. endif ()
  68. # Check compiler pragmas
  69. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  70. cmake_push_check_state()
  71. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unknown-pragmas")
  72. check_c_source_compiles("
  73. #pragma comment(lib, \"c\")
  74. int main() { return 0; }
  75. " LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
  76. cmake_pop_check_state()
  77. endif()
  78. # Check compiler flags
  79. check_cxx_compiler_flag(-nostdinc++ LIBUNWIND_HAS_NOSTDINCXX_FLAG)
  80. # Check symbols
  81. check_symbol_exists(__arm__ "" LIBUNWIND_TARGET_ARM)
  82. check_symbol_exists(__USING_SJLJ_EXCEPTIONS__ "" LIBUNWIND_USES_SJLJ_EXCEPTIONS)
  83. check_symbol_exists(__ARM_DWARF_EH__ "" LIBUNWIND_USES_DWARF_EH)
  84. if(LIBUNWIND_TARGET_ARM AND NOT LIBUNWIND_USES_SJLJ_EXCEPTIONS AND NOT LIBUNWIND_USES_DWARF_EH)
  85. # This condition is copied from __libunwind_config.h
  86. set(LIBUNWIND_USES_ARM_EHABI ON)
  87. endif()
  88. # Check libraries
  89. if(FUCHSIA)
  90. set(LIBUNWIND_HAS_DL_LIB NO)
  91. set(LIBUNWIND_HAS_PTHREAD_LIB NO)
  92. else()
  93. check_library_exists(dl dladdr "" LIBUNWIND_HAS_DL_LIB)
  94. check_library_exists(pthread pthread_once "" LIBUNWIND_HAS_PTHREAD_LIB)
  95. endif()