ConfigureChecks.cmake 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. include(CheckCCompilerFlag)
  2. include(CheckCSourceCompiles)
  3. include(CheckIncludeFile)
  4. include(CheckIncludeFiles)
  5. include(CheckLibraryExists)
  6. include(CheckSymbolExists)
  7. include(TestBigEndian)
  8. check_include_file("dlfcn.h" HAVE_DLFCN_H)
  9. check_include_file("fcntl.h" HAVE_FCNTL_H)
  10. check_include_file("inttypes.h" HAVE_INTTYPES_H)
  11. check_include_file("memory.h" HAVE_MEMORY_H)
  12. check_include_file("stdint.h" HAVE_STDINT_H)
  13. check_include_file("stdlib.h" HAVE_STDLIB_H)
  14. check_include_file("strings.h" HAVE_STRINGS_H)
  15. check_include_file("string.h" HAVE_STRING_H)
  16. check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
  17. check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
  18. check_include_file("unistd.h" HAVE_UNISTD_H)
  19. check_symbol_exists("getpagesize" "unistd.h" HAVE_GETPAGESIZE)
  20. check_symbol_exists("mmap" "sys/mman.h" HAVE_MMAP)
  21. check_symbol_exists("getrandom" "sys/random.h" HAVE_GETRANDOM)
  22. check_symbol_exists("arc4random_buf" "stdlib.h" HAVE_ARC4RANDOM_BUF)
  23. if(NOT HAVE_ARC4RANDOM_BUF)
  24. check_symbol_exists("arc4random" "stdlib.h" HAVE_ARC4RANDOM)
  25. endif()
  26. set(CMAKE_REQUIRED_LIBRARIES)
  27. #/* Define to 1 if you have the ANSI C header files. */
  28. check_include_files("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
  29. test_big_endian(WORDS_BIGENDIAN)
  30. #/* 1234 = LIL_ENDIAN, 4321 = BIGENDIAN */
  31. if(WORDS_BIGENDIAN)
  32. set(BYTEORDER 4321)
  33. else(WORDS_BIGENDIAN)
  34. set(BYTEORDER 1234)
  35. endif(WORDS_BIGENDIAN)
  36. if(HAVE_SYS_TYPES_H)
  37. check_c_source_compiles("
  38. #include <sys/types.h>
  39. int main(void) {
  40. const off_t offset = -123;
  41. (void)offset;
  42. return 0;
  43. }"
  44. HAVE_OFF_T)
  45. endif()
  46. if(NOT HAVE_OFF_T)
  47. set(off_t "long")
  48. endif()
  49. check_c_source_compiles("
  50. #define _GNU_SOURCE
  51. #include <stdlib.h> /* for NULL */
  52. #include <unistd.h> /* for syscall */
  53. #include <sys/syscall.h> /* for SYS_getrandom */
  54. int main(void) {
  55. syscall(SYS_getrandom, NULL, 0, 0);
  56. return 0;
  57. }"
  58. HAVE_SYSCALL_GETRANDOM)
  59. # If the compiler produces non-English messages and does not
  60. # listen to CMake's request for English through environment variables
  61. # LC_ALL/LC_MESSAGES/LANG, then command `check_c_compiler_flag` can produce
  62. # false positives as seen with e.g. `cl` of MSVC 19.44.35217 configured
  63. # to report errors in Italian language.
  64. check_c_compiler_flag("-no-such-thing" _FLAG_DETECTION_UNUSABLE)
  65. if (_FLAG_DETECTION_UNUSABLE)
  66. message(WARNING
  67. "Your compiler breaks CMake's command `check_c_compiler_flag`."
  68. " HINT: Is it configured to report errors in a language other"
  69. " than English?"
  70. )
  71. set(FLAG_WSTRICT_ALIASING FALSE)
  72. set(FLAG_VISIBILITY FALSE)
  73. else()
  74. check_c_compiler_flag("-Wstrict-aliasing=3" FLAG_WSTRICT_ALIASING)
  75. check_c_compiler_flag("-fvisibility=hidden" FLAG_VISIBILITY)
  76. endif()
  77. check_library_exists(m cos "" _EXPAT_LIBM_FOUND)