CMakeLists.txt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. include(CheckTypeSize)
  2. include(CheckSymbolExists)
  3. include(CheckFunctionExists)
  4. include(CheckIncludeFiles)
  5. include(CheckCSourceRuns)
  6. include(CheckCSourceCompiles)
  7. include(TestBigEndian)
  8. check_c_source_compiles("
  9. #include <execinfo.h>
  10. int main(void)
  11. {
  12. void *trace[1];
  13. backtrace(trace, 1);
  14. return 0;
  15. }
  16. " HAVE_EXECINFO_BACKTRACE)
  17. check_c_source_compiles("
  18. int main(void)
  19. {
  20. int a = 42;
  21. __builtin_add_overflow(a, a, &a);
  22. __builtin_sub_overflow(a, a, &a);
  23. return 0;
  24. }
  25. " HAVE_BUILTIN_ADD_OVERFLOW)
  26. check_type_size("int" SIZEOF_INT LANGUAGE C)
  27. check_type_size("long" SIZEOF_LONG LANGUAGE C)
  28. check_type_size("intmax_t" SIZEOF_INTMAX_T LANGUAGE C)
  29. check_type_size("size_t" SIZEOF_SIZE_T LANGUAGE C)
  30. check_type_size("void *" SIZEOF_VOID_PTR LANGUAGE C)
  31. check_symbol_exists(_NSGetEnviron crt_externs.h HAVE__NSGETENVIRON)
  32. # Headers
  33. check_include_files(langinfo.h HAVE_LANGINFO_H)
  34. check_include_files(strings.h HAVE_STRINGS_H)
  35. check_include_files(sys/utsname.h HAVE_SYS_UTSNAME_H)
  36. check_include_files(termios.h HAVE_TERMIOS_H)
  37. check_include_files(sys/uio.h HAVE_SYS_UIO_H)
  38. check_include_files(sys/sdt.h HAVE_SYS_SDT_H)
  39. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  40. check_include_files(sys/xattr.h HAVE_XATTR)
  41. endif()
  42. # Functions
  43. check_function_exists(fseeko HAVE_FSEEKO)
  44. check_function_exists(readv HAVE_READV)
  45. check_function_exists(readlink HAVE_READLINK)
  46. check_function_exists(strnlen HAVE_STRNLEN)
  47. check_function_exists(strcasecmp HAVE_STRCASECMP)
  48. check_function_exists(strncasecmp HAVE_STRNCASECMP)
  49. check_function_exists(strptime HAVE_STRPTIME)
  50. check_c_source_compiles("
  51. #include <sys/types.h>
  52. #include <dirent.h>
  53. #include <sys/file.h>
  54. int main(void)
  55. {
  56. DIR *dir = opendir(\"dirname\");
  57. dirfd(dir);
  58. flock(10, LOCK_SH);
  59. return 0;
  60. }
  61. " HAVE_DIRFD_AND_FLOCK)
  62. check_c_source_compiles("
  63. #include <pwd.h>
  64. int main(void)
  65. {
  66. getpwent();
  67. getpwuid(0);
  68. getpwnam(\"root\");
  69. return 0;
  70. }
  71. " HAVE_PWD_FUNCS)
  72. check_c_source_compiles("
  73. #include <intrin.h>
  74. int main(void)
  75. {
  76. unsigned long index;
  77. unsigned char mask = 0x8000;
  78. _BitScanForward64(&index, mask);
  79. return 0;
  80. }
  81. " HAVE_BITSCANFORWARD64)
  82. if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
  83. check_c_source_compiles("
  84. #include <termios.h>
  85. int
  86. main(void)
  87. {
  88. return forkpty(0, NULL, NULL, NULL);
  89. }
  90. " HAVE_FORKPTY)
  91. else()
  92. set(HAVE_FORKPTY 1)
  93. endif()
  94. # Symbols
  95. check_symbol_exists(FD_CLOEXEC "fcntl.h" HAVE_FD_CLOEXEC)
  96. if(HAVE_LANGINFO_H)
  97. check_symbol_exists(CODESET "langinfo.h" HAVE_NL_LANGINFO_CODESET)
  98. endif()
  99. check_include_files("endian.h" HAVE_ENDIAN_H)
  100. set(ENDIAN_INCLUDE_FILE "endian.h")
  101. if(NOT HAVE_ENDIAN_H)
  102. check_include_files("sys/endian.h" HAVE_SYS_ENDIAN_H)
  103. if (HAVE_SYS_ENDIAN_H)
  104. set(ENDIAN_INCLUDE_FILE "sys/endian.h")
  105. endif()
  106. endif()
  107. set(SI "#include <stdint.h>\n")
  108. set(MS "int main(int argc,char**argv)\n{\n uint64_t i=0x0102030405060708ULL;")
  109. set(ME "}")
  110. check_c_source_compiles("
  111. #define _BSD_SOURCE 1
  112. #define _DEFAULT_SOURCE 1
  113. ${SI}
  114. #include <${ENDIAN_INCLUDE_FILE}>
  115. #ifndef be64toh
  116. # error No be64toh macros
  117. #endif
  118. ${MS}
  119. uint64_t j = be64toh(i);
  120. return (j == 0); // j must not be zero
  121. ${ME}"
  122. HAVE_BE64TOH_MACROS)
  123. if(NOT "${HAVE_BE64TOH_MACROS}")
  124. check_function_exists(be64toh HAVE_BE64TOH_FUNC)
  125. endif()
  126. if("${HAVE_BE64TOH_MACROS}" OR "${HAVE_BE64TOH_FUNC}")
  127. set(HAVE_BE64TOH 1)
  128. endif()
  129. test_big_endian(ORDER_BIG_ENDIAN)
  130. configure_file (
  131. "${PROJECT_SOURCE_DIR}/cmake.config/config.h.in"
  132. "${PROJECT_BINARY_DIR}/cmake.config/auto/config.h"
  133. )
  134. set(VERSION_STRING "${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} ")
  135. foreach(BUILD_TYPE Debug Release RelWithDebInfo MinSizeRel)
  136. string(TOUPPER ${BUILD_TYPE} BUILD_TYPE_UPPER)
  137. set(GEN_CONFIG "$<CONFIG:${BUILD_TYPE}>")
  138. set(GEN_RHS "${CMAKE_C_FLAGS_${BUILD_TYPE_UPPER}} ")
  139. string(APPEND VERSION_STRING "$<${GEN_CONFIG}:${GEN_RHS}>")
  140. set(GEN_RHS "$<$<BOOL:$<TARGET_PROPERTY:nvim_bin,INTERPROCEDURAL_OPTIMIZATION_${BUILD_TYPE_UPPER}>>:${CMAKE_C_COMPILE_OPTIONS_IPO}>")
  141. string(APPEND VERSION_STRING "$<${GEN_CONFIG}:${GEN_RHS}>")
  142. endforeach()
  143. string(APPEND VERSION_STRING " ")
  144. function(append_target_expression)
  145. cmake_parse_arguments(ARG
  146. ""
  147. "PREFIX;PROPERTY"
  148. ""
  149. ${ARGN})
  150. set(TARGET_EXPRESSION "$<TARGET_PROPERTY:nvim_bin,${ARG_PROPERTY}>")
  151. set(TARGET_EXPRESSION "$<REMOVE_DUPLICATES:${TARGET_EXPRESSION}>")
  152. set(TARGET_EXPRESSION "${ARG_PREFIX}$<JOIN:${TARGET_EXPRESSION}, ${ARG_PREFIX}>")
  153. set(VERSION_STRING "${VERSION_STRING} ${TARGET_EXPRESSION} " PARENT_SCOPE)
  154. endfunction()
  155. append_target_expression(PROPERTY COMPILE_OPTIONS)
  156. append_target_expression(PROPERTY LINK_OPTIONS)
  157. append_target_expression(PREFIX "-D" PROPERTY COMPILE_DEFINITIONS)
  158. append_target_expression(PREFIX "-I" PROPERTY INCLUDE_DIRECTORIES)
  159. string(REPLACE ";" " " VERSION_STRING "${VERSION_STRING}")
  160. string(REPLACE " " " " VERSION_STRING "${VERSION_STRING}")
  161. configure_file(versiondef.h.in auto/versiondef.h.gen)
  162. file(GENERATE
  163. OUTPUT "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef-$<CONFIG>.h"
  164. INPUT "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef.h.gen")
  165. configure_file (
  166. "${PROJECT_SOURCE_DIR}/cmake.config/pathdef.h.in"
  167. "${PROJECT_BINARY_DIR}/cmake.config/auto/pathdef.h"
  168. ESCAPE_QUOTES)