CMakeLists.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. include(CheckTypeSize)
  2. include(CheckSymbolExists)
  3. include(CheckFunctionExists)
  4. include(CheckIncludeFiles)
  5. include(CheckCSourceRuns)
  6. include(CheckCSourceCompiles)
  7. check_type_size("int" SIZEOF_INT)
  8. check_type_size("long" SIZEOF_LONG)
  9. check_type_size("intmax_t" SIZEOF_INTMAX_T)
  10. check_type_size("size_t" SIZEOF_SIZE_T)
  11. check_type_size("long long" SIZEOF_LONG_LONG)
  12. check_type_size("void *" SIZEOF_VOID_PTR)
  13. check_symbol_exists(_NSGetEnviron crt_externs.h HAVE__NSGETENVIRON)
  14. # Headers
  15. check_include_files(langinfo.h HAVE_LANGINFO_H)
  16. check_include_files(locale.h HAVE_LOCALE_H)
  17. check_include_files(pwd.h HAVE_PWD_H)
  18. check_include_files(strings.h HAVE_STRINGS_H)
  19. check_include_files(sys/wait.h HAVE_SYS_WAIT_H)
  20. if(NOT HAVE_SYS_WAIT_H AND UNIX)
  21. # See if_cscope.c
  22. message(SEND_ERROR "header sys/wait.h is required for Unix")
  23. endif()
  24. check_include_files(sys/utsname.h HAVE_SYS_UTSNAME_H)
  25. check_include_files(termios.h HAVE_TERMIOS_H)
  26. check_include_files(sys/uio.h HAVE_SYS_UIO_H)
  27. check_include_files(sys/sdt.h HAVE_SYS_SDT_H)
  28. # Functions
  29. check_function_exists(fseeko HAVE_FSEEKO)
  30. check_function_exists(getpwent HAVE_GETPWENT)
  31. check_function_exists(getpwnam HAVE_GETPWNAM)
  32. check_function_exists(getpwuid HAVE_GETPWUID)
  33. check_function_exists(readv HAVE_READV)
  34. if(Iconv_FOUND)
  35. set(HAVE_ICONV 1)
  36. endif()
  37. check_function_exists(opendir HAVE_OPENDIR)
  38. check_function_exists(readlink HAVE_READLINK)
  39. check_function_exists(setpgid HAVE_SETPGID)
  40. check_function_exists(setsid HAVE_SETSID)
  41. check_function_exists(sigaction HAVE_SIGACTION)
  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. if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
  47. check_c_source_compiles("
  48. #include <termios.h>
  49. int
  50. main(void)
  51. {
  52. return forkpty(0, NULL, NULL, NULL);
  53. }
  54. " HAVE_FORKPTY)
  55. else()
  56. set(HAVE_FORKPTY 1)
  57. endif()
  58. # Symbols
  59. check_symbol_exists(FD_CLOEXEC "fcntl.h" HAVE_FD_CLOEXEC)
  60. if(HAVE_LANGINFO_H)
  61. check_symbol_exists(CODESET "langinfo.h" HAVE_NL_LANGINFO_CODESET)
  62. endif()
  63. check_include_files("endian.h" HAVE_ENDIAN_H)
  64. check_include_files("sys/endian.h" HAVE_SYS_ENDIAN_H)
  65. set(ENDIAN_INCLUDE_FILE "endian.h")
  66. if(HAVE_SYS_ENDIAN_H AND NOT HAVE_ENDIAN_H)
  67. set(ENDIAN_INCLUDE_FILE "sys/endian.h")
  68. endif()
  69. set(SI "#include <stdint.h>\n")
  70. set(MS "int main(int argc,char**argv)\n{\n uint64_t i=0x0102030405060708ULL;")
  71. set(ME "}")
  72. check_c_source_compiles("
  73. #define _BSD_SOURCE 1
  74. #define _DEFAULT_SOURCE 1
  75. ${SI}
  76. #include <${ENDIAN_INCLUDE_FILE}>
  77. #ifndef be64toh
  78. # error No be64toh macros
  79. #endif
  80. ${MS}
  81. uint64_t j = be64toh(i);
  82. return (j == 0); // j must not be zero
  83. ${ME}"
  84. HAVE_BE64TOH_MACROS)
  85. if(NOT "${HAVE_BE64TOH_MACROS}")
  86. check_function_exists(be64toh HAVE_BE64TOH_FUNC)
  87. endif()
  88. if("${HAVE_BE64TOH_MACROS}" OR "${HAVE_BE64TOH_FUNC}")
  89. set(HAVE_BE64TOH 1)
  90. endif()
  91. if (NOT "${HAVE_BE64TOH}")
  92. if (NOT "${CMAKE_CROSSCOMPILING}")
  93. # It is safe to make ORDER_BIG_ENDIAN not defined if
  94. # - HAVE_BE64TOH is true. In this case be64toh will be used unconditionally in
  95. # any case and ORDER_BIG_ENDIAN will not be examined.
  96. # - CMAKE_CROSSCOMPILING *and* HAVE_BE64TOH are both false. In this case
  97. # be64toh function which uses cycle and arithmetic operations is used which
  98. # will work regardless of endianness. Function is sub-optimal though.
  99. check_c_source_runs("
  100. ${SI}
  101. ${MS}
  102. char *s = (char *) &i;
  103. return (
  104. s[0] == 0x01
  105. && s[1] == 0x02
  106. && s[2] == 0x03
  107. && s[3] == 0x04
  108. && s[4] == 0x05
  109. && s[5] == 0x06
  110. && s[6] == 0x07
  111. && s[7] == 0x08) ? 0 : 1;
  112. ${ME}"
  113. ORDER_BIG_ENDIAN)
  114. endif()
  115. endif()
  116. # generate configuration header and update include directories
  117. configure_file (
  118. "${PROJECT_SOURCE_DIR}/config/config.h.in"
  119. "${PROJECT_BINARY_DIR}/config/auto/config.h"
  120. )
  121. # generate version definitions
  122. configure_file (
  123. "${PROJECT_SOURCE_DIR}/config/versiondef.h.in"
  124. "${PROJECT_BINARY_DIR}/config/auto/versiondef.h"
  125. )
  126. # generate pathdef.c
  127. find_program(WHOAMI_PROG whoami)
  128. find_program(HOSTNAME_PROG hostname)
  129. if (DEFINED ENV{USERNAME})
  130. set(USERNAME $ENV{USERNAME})
  131. elseif (NOT DEFINED USERNAME AND EXISTS ${WHOAMI_PROG})
  132. execute_process(COMMAND ${WHOAMI_PROG}
  133. OUTPUT_STRIP_TRAILING_WHITESPACE
  134. OUTPUT_VARIABLE USERNAME)
  135. endif()
  136. if (DEFINED ENV{HOSTNAME})
  137. set(HOSTNAME $ENV{HOSTNAME})
  138. elseif (EXISTS ${HOSTNAME_PROG})
  139. execute_process(COMMAND ${HOSTNAME_PROG}
  140. OUTPUT_STRIP_TRAILING_WHITESPACE
  141. OUTPUT_VARIABLE HOSTNAME)
  142. endif()
  143. configure_file (
  144. "${PROJECT_SOURCE_DIR}/config/pathdef.c.in"
  145. "${PROJECT_BINARY_DIR}/config/auto/pathdef.c"
  146. ESCAPE_QUOTES)