CMakeLists.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. include(CheckTypeSize)
  2. include(CheckSymbolExists)
  3. include(CheckFunctionExists)
  4. include(CheckIncludeFiles)
  5. include(CheckCSourceRuns)
  6. include(CheckCSourceCompiles)
  7. check_c_source_compiles("
  8. #include <execinfo.h>
  9. int main(void)
  10. {
  11. void *trace[1];
  12. backtrace(trace, 1);
  13. return 0;
  14. }
  15. " HAVE_EXECINFO_BACKTRACE)
  16. check_c_source_compiles("
  17. int main(void)
  18. {
  19. int a = 42;
  20. __builtin_add_overflow(a, a, &a);
  21. __builtin_sub_overflow(a, a, &a);
  22. return 0;
  23. }
  24. " HAVE_BUILTIN_ADD_OVERFLOW)
  25. check_type_size("int" SIZEOF_INT LANGUAGE C)
  26. check_type_size("long" SIZEOF_LONG LANGUAGE C)
  27. check_type_size("intmax_t" SIZEOF_INTMAX_T LANGUAGE C)
  28. check_type_size("size_t" SIZEOF_SIZE_T LANGUAGE C)
  29. check_type_size("void *" SIZEOF_VOID_PTR LANGUAGE C)
  30. check_symbol_exists(_NSGetEnviron crt_externs.h HAVE__NSGETENVIRON)
  31. # Headers
  32. check_include_files(langinfo.h HAVE_LANGINFO_H)
  33. check_include_files(strings.h HAVE_STRINGS_H)
  34. check_include_files(sys/utsname.h HAVE_SYS_UTSNAME_H)
  35. check_include_files(termios.h HAVE_TERMIOS_H)
  36. check_include_files(sys/uio.h HAVE_SYS_UIO_H)
  37. check_include_files(sys/sdt.h HAVE_SYS_SDT_H)
  38. # Functions
  39. check_function_exists(fseeko HAVE_FSEEKO)
  40. check_function_exists(readv HAVE_READV)
  41. check_function_exists(readlink HAVE_READLINK)
  42. check_function_exists(strnlen HAVE_STRNLEN)
  43. check_function_exists(strcasecmp HAVE_STRCASECMP)
  44. check_function_exists(strncasecmp HAVE_STRNCASECMP)
  45. check_function_exists(strptime HAVE_STRPTIME)
  46. check_c_source_compiles("
  47. #include <sys/types.h>
  48. #include <dirent.h>
  49. #include <sys/file.h>
  50. int main(void)
  51. {
  52. DIR *dir = opendir(\"dirname\");
  53. dirfd(dir);
  54. flock(10, LOCK_SH);
  55. return 0;
  56. }
  57. " HAVE_DIRFD_AND_FLOCK)
  58. check_c_source_compiles("
  59. #include <pwd.h>
  60. int main(void)
  61. {
  62. getpwent();
  63. getpwuid(0);
  64. getpwnam(\"root\");
  65. return 0;
  66. }
  67. " HAVE_PWD_FUNCS)
  68. if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
  69. check_c_source_compiles("
  70. #include <termios.h>
  71. int
  72. main(void)
  73. {
  74. return forkpty(0, NULL, NULL, NULL);
  75. }
  76. " HAVE_FORKPTY)
  77. else()
  78. set(HAVE_FORKPTY 1)
  79. endif()
  80. # Symbols
  81. check_symbol_exists(FD_CLOEXEC "fcntl.h" HAVE_FD_CLOEXEC)
  82. if(HAVE_LANGINFO_H)
  83. check_symbol_exists(CODESET "langinfo.h" HAVE_NL_LANGINFO_CODESET)
  84. endif()
  85. check_include_files("endian.h" HAVE_ENDIAN_H)
  86. set(ENDIAN_INCLUDE_FILE "endian.h")
  87. if(NOT HAVE_ENDIAN_H)
  88. check_include_files("sys/endian.h" HAVE_SYS_ENDIAN_H)
  89. if (HAVE_SYS_ENDIAN_H)
  90. set(ENDIAN_INCLUDE_FILE "sys/endian.h")
  91. endif()
  92. endif()
  93. set(SI "#include <stdint.h>\n")
  94. set(MS "int main(int argc,char**argv)\n{\n uint64_t i=0x0102030405060708ULL;")
  95. set(ME "}")
  96. check_c_source_compiles("
  97. #define _BSD_SOURCE 1
  98. #define _DEFAULT_SOURCE 1
  99. ${SI}
  100. #include <${ENDIAN_INCLUDE_FILE}>
  101. #ifndef be64toh
  102. # error No be64toh macros
  103. #endif
  104. ${MS}
  105. uint64_t j = be64toh(i);
  106. return (j == 0); // j must not be zero
  107. ${ME}"
  108. HAVE_BE64TOH_MACROS)
  109. if(NOT "${HAVE_BE64TOH_MACROS}")
  110. check_function_exists(be64toh HAVE_BE64TOH_FUNC)
  111. endif()
  112. if("${HAVE_BE64TOH_MACROS}" OR "${HAVE_BE64TOH_FUNC}")
  113. set(HAVE_BE64TOH 1)
  114. endif()
  115. if (NOT "${HAVE_BE64TOH}")
  116. if (NOT "${CMAKE_CROSSCOMPILING}")
  117. # It is safe to make ORDER_BIG_ENDIAN not defined if
  118. # - HAVE_BE64TOH is true. In this case be64toh will be used unconditionally in
  119. # any case and ORDER_BIG_ENDIAN will not be examined.
  120. # - CMAKE_CROSSCOMPILING *and* HAVE_BE64TOH are both false. In this case
  121. # be64toh function which uses cycle and arithmetic operations is used which
  122. # will work regardless of endianness. Function is sub-optimal though.
  123. check_c_source_runs("
  124. ${SI}
  125. ${MS}
  126. char *s = (char *) &i;
  127. return (
  128. s[0] == 0x01
  129. && s[1] == 0x02
  130. && s[2] == 0x03
  131. && s[3] == 0x04
  132. && s[4] == 0x05
  133. && s[5] == 0x06
  134. && s[6] == 0x07
  135. && s[7] == 0x08) ? 0 : 1;
  136. ${ME}"
  137. ORDER_BIG_ENDIAN)
  138. endif()
  139. endif()
  140. configure_file (
  141. "${PROJECT_SOURCE_DIR}/cmake.config/config.h.in"
  142. "${PROJECT_BINARY_DIR}/cmake.config/auto/config.h"
  143. )
  144. configure_file(versiondef.h.in auto/versiondef.h.gen)
  145. file(GENERATE
  146. OUTPUT "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef-$<CONFIG>.h"
  147. INPUT "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef.h.gen")
  148. configure_file (
  149. "${PROJECT_SOURCE_DIR}/cmake.config/pathdef.c.in"
  150. "${PROJECT_BINARY_DIR}/cmake.config/auto/pathdef.c"
  151. ESCAPE_QUOTES)