CMakeLists.txt 5.1 KB

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