CMakeLists.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. # This is not meant to be included by the top-level.
  2. cmake_minimum_required (VERSION 2.8.12)
  3. project(NVIM_DEPS C)
  4. # Needed for: check_c_compiler_flag()
  5. include(CheckCCompilerFlag)
  6. # Point CMake at any custom modules we may ship
  7. list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${PROJECT_SOURCE_DIR}/../cmake")
  8. # In Windows/MSVC CMAKE_BUILD_TYPE changes the paths/linking of the build
  9. # recipes (libuv, msgpack), make sure it is set
  10. if(NOT CMAKE_BUILD_TYPE)
  11. set(CMAKE_BUILD_TYPE Release)
  12. endif()
  13. set(DEFAULT_MAKE_CFLAGS CFLAGS+=-g)
  14. check_c_compiler_flag(-Og HAS_OG_FLAG)
  15. if(HAS_OG_FLAG)
  16. set(DEFAULT_MAKE_CFLAGS CFLAGS+=-Og ${DEFAULT_MAKE_CFLAGS})
  17. endif()
  18. if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
  19. # pkg-config 29.2 has a bug on OpenBSD which causes it to drop any paths that
  20. # *contain* system include paths. To avoid this, we prefix what would be
  21. # "/usr/include" as "/_usr/include".
  22. # This check is also performed in the root CMakeLists.txt
  23. # https://github.com/neovim/neovim/pull/14745#issuecomment-860201794
  24. set(DEPS_INSTALL_DIR "${CMAKE_BINARY_DIR}/_usr" CACHE PATH "Dependencies install directory.")
  25. else()
  26. set(DEPS_INSTALL_DIR "${CMAKE_BINARY_DIR}/usr" CACHE PATH "Dependencies install directory.")
  27. endif()
  28. set(DEPS_BIN_DIR "${DEPS_INSTALL_DIR}/bin" CACHE PATH "Dependencies binary install directory.")
  29. set(DEPS_LIB_DIR "${DEPS_INSTALL_DIR}/lib" CACHE PATH "Dependencies library install directory.")
  30. set(DEPS_BUILD_DIR "${CMAKE_BINARY_DIR}/build" CACHE PATH "Dependencies build directory.")
  31. set(DEPS_DOWNLOAD_DIR "${DEPS_BUILD_DIR}/downloads" CACHE PATH "Dependencies download directory.")
  32. option(USE_BUNDLED "Use bundled dependencies." ON)
  33. option(USE_BUNDLED_GPERF "Use the bundled version of gperf." ${USE_BUNDLED})
  34. option(USE_BUNDLED_UNIBILIUM "Use the bundled unibilium." ${USE_BUNDLED})
  35. option(USE_BUNDLED_LIBTERMKEY "Use the bundled libtermkey." ${USE_BUNDLED})
  36. option(USE_BUNDLED_LIBVTERM "Use the bundled libvterm." ${USE_BUNDLED})
  37. option(USE_BUNDLED_LIBUV "Use the bundled libuv." ${USE_BUNDLED})
  38. option(USE_BUNDLED_MSGPACK "Use the bundled msgpack." ${USE_BUNDLED})
  39. option(USE_BUNDLED_LUAJIT "Use the bundled version of luajit." ${USE_BUNDLED})
  40. option(USE_BUNDLED_LUAROCKS "Use the bundled version of luarocks." ${USE_BUNDLED})
  41. option(USE_BUNDLED_LUV "Use the bundled version of luv." ${USE_BUNDLED})
  42. #XXX(tarruda): Lua is only used for debugging the functional test client, no
  43. # build it unless explicitly requested
  44. option(USE_BUNDLED_LUA "Use the bundled version of lua." OFF)
  45. option(USE_BUNDLED_TS_PARSERS "Use the bundled treesitter parsers." ${USE_BUNDLED})
  46. option(USE_BUNDLED_TS "Use the bundled treesitter runtime." ${USE_BUNDLED})
  47. if(USE_BUNDLED AND MSVC)
  48. option(USE_BUNDLED_GETTEXT "Use the bundled version of gettext." ON)
  49. option(USE_BUNDLED_LIBICONV "Use the bundled version of libiconv." ON)
  50. else()
  51. option(USE_BUNDLED_GETTEXT "Use the bundled version of gettext." OFF)
  52. option(USE_BUNDLED_LIBICONV "Use the bundled version of libiconv." OFF)
  53. endif()
  54. option(USE_EXISTING_SRC_DIR "Skip download of deps sources in case of existing source directory." OFF)
  55. if(WIN32)
  56. find_package(Git)
  57. if(NOT Git_FOUND)
  58. message(FATAL_ERROR "Git is required to apply patches for Windows.")
  59. endif()
  60. endif()
  61. if(UNIX)
  62. find_program(MAKE_PRG NAMES gmake make)
  63. if(MAKE_PRG)
  64. execute_process(
  65. COMMAND "${MAKE_PRG}" --version
  66. OUTPUT_VARIABLE MAKE_VERSION_INFO)
  67. if(NOT "${OUTPUT_VARIABLE}" MATCHES ".*GNU.*")
  68. unset(MAKE_PRG)
  69. endif()
  70. endif()
  71. if(NOT MAKE_PRG)
  72. message(FATAL_ERROR "GNU Make is required to build the dependencies.")
  73. else()
  74. message(STATUS "Found GNU Make at ${MAKE_PRG}")
  75. endif()
  76. endif()
  77. # When using make, use the $(MAKE) variable to avoid warning about the job
  78. # server.
  79. if(CMAKE_GENERATOR MATCHES "Makefiles")
  80. set(MAKE_PRG "$(MAKE)")
  81. endif()
  82. if(MINGW AND CMAKE_GENERATOR MATCHES "Ninja")
  83. find_program(MAKE_PRG NAMES mingw32-make)
  84. if(NOT MAKE_PRG)
  85. message(FATAL_ERROR "GNU Make for mingw32 is required to build the dependencies.")
  86. else()
  87. message(STATUS "Found GNU Make for mingw32: ${MAKE_PRG}")
  88. endif()
  89. endif()
  90. if(CMAKE_C_COMPILER_ARG1)
  91. set(DEPS_C_COMPILER "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
  92. else()
  93. set(DEPS_C_COMPILER "${CMAKE_C_COMPILER}")
  94. endif()
  95. if(USE_BUNDLED_GPERF)
  96. enable_language(CXX)
  97. endif()
  98. if(CMAKE_CXX_COMPILER)
  99. set(DEPS_CXX_COMPILER "${CMAKE_CXX_COMPILER}")
  100. endif()
  101. if(CMAKE_OSX_SYSROOT)
  102. set(DEPS_C_COMPILER "${DEPS_C_COMPILER} -isysroot${CMAKE_OSX_SYSROOT}")
  103. if(DEPS_CXX_COMPILER)
  104. set(DEPS_CXX_COMPILER "${DEPS_CXX_COMPILER} -isysroot${CMAKE_OSX_SYSROOT}")
  105. endif()
  106. endif()
  107. if(CMAKE_OSX_ARCHITECTURES)
  108. string(REPLACE ";" "|" CMAKE_OSX_ARCHITECTURES_ALT_SEP "${CMAKE_OSX_ARCHITECTURES}")
  109. # The LuaJIT build does not like being passed multiple `-arch` flags
  110. # so we handle a universal build the old-fashioned way.
  111. set(LUAJIT_C_COMPILER "${DEPS_C_COMPILER}")
  112. foreach(ARCH IN LISTS CMAKE_OSX_ARCHITECTURES)
  113. set(DEPS_C_COMPILER "${DEPS_C_COMPILER} -arch ${ARCH}")
  114. if(DEPS_CXX_COMPILER)
  115. set(DEPS_CXX_COMPILER "${DEPS_CXX_COMPILER} -arch ${ARCH}")
  116. endif()
  117. endforeach()
  118. endif()
  119. # If the macOS deployment target is not set manually (via $MACOSX_DEPLOYMENT_TARGET),
  120. # fall back to local system version. Needs to be done here and in top-level CMakeLists.txt.
  121. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  122. if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
  123. execute_process(COMMAND sw_vers -productVersion
  124. OUTPUT_VARIABLE MACOS_VERSION
  125. OUTPUT_STRIP_TRAILING_WHITESPACE)
  126. set(CMAKE_OSX_DEPLOYMENT_TARGET "${MACOS_VERSION}")
  127. endif()
  128. message("-- Using deployment target ${CMAKE_OSX_DEPLOYMENT_TARGET}")
  129. endif()
  130. set(HOSTDEPS_INSTALL_DIR "${DEPS_INSTALL_DIR}")
  131. set(HOSTDEPS_BIN_DIR "${DEPS_BIN_DIR}")
  132. set(HOSTDEPS_LIB_DIR "${DEPS_LIB_DIR}")
  133. set(HOSTDEPS_C_COMPILER "${DEPS_C_COMPILER}")
  134. set(HOSTDEPS_CXX_COMPILER "${DEPS_CXX_COMPILER}")
  135. include(ExternalProject)
  136. set(LIBUV_URL https://github.com/libuv/libuv/archive/v1.44.1.tar.gz)
  137. set(LIBUV_SHA256 e91614e6dc2dd0bfdd140ceace49438882206b7a6fb00b8750914e67a9ed6d6b)
  138. set(MSGPACK_URL https://github.com/msgpack/msgpack-c/releases/download/cpp-3.0.0/msgpack-3.0.0.tar.gz)
  139. set(MSGPACK_SHA256 bfbb71b7c02f806393bc3cbc491b40523b89e64f83860c58e3e54af47de176e4)
  140. # https://github.com/LuaJIT/LuaJIT/tree/v2.1
  141. set(LUAJIT_URL https://github.com/LuaJIT/LuaJIT/archive/91bc6b8ad1f373c1ce9003dc024b2e21fad0e444.tar.gz)
  142. set(LUAJIT_SHA256 81895031fdb87602c7dde52280259c60b1ffd1b5a8a3c2792d3e2390481163fa)
  143. set(LUA_URL https://www.lua.org/ftp/lua-5.1.5.tar.gz)
  144. set(LUA_SHA256 2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333)
  145. set(LUAROCKS_URL https://github.com/luarocks/luarocks/archive/v3.8.0.tar.gz)
  146. set(LUAROCKS_SHA256 ab6612ca9ab87c6984871d2712d05525775e8b50172701a0a1cabddf76de2be7)
  147. set(UNIBILIUM_URL https://github.com/neovim/unibilium/archive/92d929f.tar.gz)
  148. set(UNIBILIUM_SHA256 29815283c654277ef77a3adcc8840db79ddbb20a0f0b0c8f648bd8cd49a02e4b)
  149. set(LIBTERMKEY_URL https://www.leonerd.org.uk/code/libtermkey/libtermkey-0.22.tar.gz)
  150. set(LIBTERMKEY_SHA256 6945bd3c4aaa83da83d80a045c5563da4edd7d0374c62c0d35aec09eb3014600)
  151. set(LIBVTERM_URL https://www.leonerd.org.uk/code/libvterm/libvterm-0.1.4.tar.gz)
  152. set(LIBVTERM_SHA256 bc70349e95559c667672fc8c55b9527d9db9ada0fb80a3beda533418d782d3dd)
  153. set(LUV_VERSION 1.43.0-0)
  154. set(LUV_URL https://github.com/luvit/luv/archive/c51e7052ec4f0a25058f70c1b4ee99dd36180e59.tar.gz)
  155. set(LUV_SHA256 cabb7e650f35992686eb95ae167c71614e281cd2979fc804e4e70f8051555728)
  156. set(LUA_COMPAT53_URL https://github.com/keplerproject/lua-compat-5.3/archive/v0.9.tar.gz)
  157. set(LUA_COMPAT53_SHA256 ad05540d2d96a48725bb79a1def35cf6652a4e2ec26376e2617c8ce2baa6f416)
  158. set(GPERF_URL https://github.com/neovim/deps/raw/ff5b4b18a87397a8564016071ae64f64bcd8c635/opt/gperf-3.1.tar.gz)
  159. set(GPERF_SHA256 588546b945bba4b70b6a3a616e80b4ab466e3f33024a352fc2198112cdbb3ae2)
  160. # cat.exe curl.exe curl-ca-bundle.crt diff.exe tee.exe xxd.exe
  161. set(WINTOOLS_URL https://github.com/neovim/deps/raw/d66e306abf5b846484b4f2adffd896bce7e065d2/opt/win32tools.zip)
  162. set(WINTOOLS_SHA256 2fb2f8d69070b3f16e029913fb95008e6be33893d77fc358012396c275a0fdb7)
  163. set(WINGUI_URL https://github.com/equalsraf/neovim-qt/releases/download/v0.2.16.1/neovim-qt.zip)
  164. set(WINGUI_SHA256 ddb4492db03da407703fb0ab271c4eb060250d1a7d71200e2b3b981cb0de59de)
  165. set(WIN32YANK_X86_URL https://github.com/equalsraf/win32yank/releases/download/v0.0.4/win32yank-x86.zip)
  166. set(WIN32YANK_X86_SHA256 62f34e5a46c5d4a7b3f3b512e1ff7b77fedd432f42581cbe825233a996eed62c)
  167. set(WIN32YANK_X86_64_URL https://github.com/equalsraf/win32yank/releases/download/v0.0.4/win32yank-x64.zip)
  168. set(WIN32YANK_X86_64_SHA256 33a747a92da60fb65e668edbf7661d3d902411a2d545fe9dc08623cecd142a20)
  169. set(WINPTY_URL https://github.com/rprichard/winpty/releases/download/0.4.3/winpty-0.4.3-msvc2015.zip)
  170. set(WINPTY_SHA256 35a48ece2ff4acdcbc8299d4920de53eb86b1fb41e64d2fe5ae7898931bcee89)
  171. set(GETTEXT_URL https://ftp.gnu.org/pub/gnu/gettext/gettext-0.20.1.tar.gz)
  172. set(GETTEXT_SHA256 66415634c6e8c3fa8b71362879ec7575e27da43da562c798a8a2f223e6e47f5c)
  173. set(LIBICONV_URL https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz)
  174. set(LIBICONV_SHA256 ccf536620a45458d26ba83887a983b96827001e92a13847b45e4925cc8913178)
  175. set(TREESITTER_C_URL https://github.com/tree-sitter/tree-sitter-c/archive/v0.20.1.tar.gz)
  176. set(TREESITTER_C_SHA256 ffcc2ef0eded59ad1acec9aec4f9b0c7dd209fc1a85d85f8b0e81298e3dddcc2)
  177. set(TREESITTER_URL https://github.com/tree-sitter/tree-sitter/archive/v0.20.6.tar.gz)
  178. set(TREESITTER_SHA256 4d37eaef8a402a385998ff9aca3e1043b4a3bba899bceeff27a7178e1165b9de)
  179. if(USE_BUNDLED_UNIBILIUM)
  180. include(BuildUnibilium)
  181. endif()
  182. if(USE_BUNDLED_LIBTERMKEY)
  183. include(BuildLibtermkey)
  184. if(USE_BUNDLED_UNIBILIUM)
  185. add_dependencies(libtermkey unibilium)
  186. endif()
  187. endif()
  188. if(USE_BUNDLED_LIBVTERM)
  189. include(BuildLibvterm)
  190. endif()
  191. if(USE_BUNDLED_LIBUV)
  192. include(BuildLibuv)
  193. endif()
  194. if(USE_BUNDLED_MSGPACK)
  195. include(BuildMsgpack)
  196. endif()
  197. if(USE_BUNDLED_LUAJIT)
  198. include(BuildLuajit)
  199. endif()
  200. if(USE_BUNDLED_LUA)
  201. include(BuildLua)
  202. endif()
  203. if(USE_BUNDLED_LUAROCKS)
  204. include(BuildLuarocks)
  205. endif()
  206. if(USE_BUNDLED_LUV)
  207. include(BuildLuv)
  208. endif()
  209. if(USE_BUNDLED_GPERF)
  210. include(BuildGperf)
  211. endif()
  212. if(USE_BUNDLED_GETTEXT)
  213. include(BuildGettext)
  214. endif()
  215. if(USE_BUNDLED_LIBICONV)
  216. include(BuildLibiconv)
  217. endif()
  218. if(USE_BUNDLED_TS_PARSERS)
  219. include(BuildTreesitterParsers)
  220. endif()
  221. if(USE_BUNDLED_TS)
  222. include(BuildTreesitter)
  223. endif()
  224. if(WIN32)
  225. include(GetBinaryDeps)
  226. GetBinaryDep(TARGET wintools
  227. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${DEPS_INSTALL_DIR}/bin)
  228. GetBinaryDep(TARGET wingui
  229. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory bin ${DEPS_INSTALL_DIR}/bin
  230. COMMAND ${CMAKE_COMMAND} -E copy_directory share ${DEPS_INSTALL_DIR}/share)
  231. include(TargetArch)
  232. GetBinaryDep(TARGET "win32yank_${TARGET_ARCH}"
  233. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy win32yank.exe ${DEPS_INSTALL_DIR}/bin)
  234. if("${TARGET_ARCH}" STREQUAL "X86_64")
  235. set(TARGET_ARCH x64)
  236. elseif(TARGET_ARCH STREQUAL "X86")
  237. set(TARGET_ARCH ia32)
  238. endif()
  239. GetBinaryDep(TARGET winpty
  240. INSTALL_COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/bin
  241. COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/winpty/${TARGET_ARCH}/bin/*
  242. -DTO=${DEPS_INSTALL_DIR}/bin/
  243. -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake
  244. COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/winpty/include/*
  245. -DTO=${DEPS_INSTALL_DIR}/include/
  246. -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake
  247. COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/winpty/${TARGET_ARCH}/lib/*
  248. -DTO=${DEPS_INSTALL_DIR}/lib/
  249. -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake)
  250. endif()
  251. # clean-shared-libraries removes ${DEPS_INSTALL_DIR}/lib/nvim/parser/c.dll,
  252. # resulting in MSVC build failure in CI.
  253. if (MSVC)
  254. set(ALL_DEPS ${THIRD_PARTY_DEPS})
  255. else()
  256. add_custom_target(clean-shared-libraries
  257. COMMAND ${CMAKE_COMMAND}
  258. -DREMOVE_FILE_GLOB=${DEPS_INSTALL_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}*${CMAKE_SHARED_LIBRARY_SUFFIX}*
  259. -P ${PROJECT_SOURCE_DIR}/cmake/RemoveFiles.cmake
  260. DEPENDS ${THIRD_PARTY_DEPS}
  261. )
  262. set(ALL_DEPS clean-shared-libraries)
  263. endif()
  264. add_custom_target(third-party ALL
  265. COMMAND ${CMAKE_COMMAND} -E touch .third-party
  266. DEPENDS ${ALL_DEPS}
  267. )