CMakeLists.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. # This is not meant to be included by the top-level.
  2. cmake_minimum_required (VERSION 3.10)
  3. project(NVIM_DEPS C)
  4. if(POLICY CMP0135)
  5. cmake_policy(SET CMP0135 NEW)
  6. endif()
  7. # Point CMake at any custom modules we may ship
  8. list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${PROJECT_SOURCE_DIR}/../cmake")
  9. include(CheckCCompilerFlag)
  10. include(Util)
  11. set(DEPS_CMAKE_ARGS
  12. -D CMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  13. -D CMAKE_C_STANDARD=99
  14. -D CMAKE_GENERATOR=${CMAKE_GENERATOR}
  15. -D CMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
  16. -D CMAKE_POSITION_INDEPENDENT_CODE=ON
  17. -D CMAKE_FIND_FRAMEWORK=${CMAKE_FIND_FRAMEWORK})
  18. set(DEPS_CMAKE_CACHE_ARGS -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES})
  19. set_default_buildtype()
  20. get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  21. if(NOT isMultiConfig)
  22. list(APPEND DEPS_CMAKE_ARGS -D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
  23. endif()
  24. set(DEFAULT_MAKE_CFLAGS CFLAGS+=-g)
  25. check_c_compiler_flag(-Og HAS_OG_FLAG)
  26. if(HAS_OG_FLAG)
  27. set(DEFAULT_MAKE_CFLAGS CFLAGS+=-Og ${DEFAULT_MAKE_CFLAGS})
  28. endif()
  29. set(DEPS_INSTALL_DIR "${CMAKE_BINARY_DIR}/usr")
  30. set(DEPS_BIN_DIR "${DEPS_INSTALL_DIR}/bin")
  31. set(DEPS_LIB_DIR "${DEPS_INSTALL_DIR}/lib")
  32. set(DEPS_BUILD_DIR "${CMAKE_BINARY_DIR}/build")
  33. set(DEPS_DOWNLOAD_DIR "${DEPS_BUILD_DIR}/downloads")
  34. list(APPEND DEPS_CMAKE_ARGS -D CMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR})
  35. option(USE_BUNDLED "Use bundled dependencies." ON)
  36. option(USE_BUNDLED_UNIBILIUM "Use the bundled unibilium." ${USE_BUNDLED})
  37. option(USE_BUNDLED_LIBTERMKEY "Use the bundled libtermkey." ${USE_BUNDLED})
  38. option(USE_BUNDLED_LIBVTERM "Use the bundled libvterm." ${USE_BUNDLED})
  39. option(USE_BUNDLED_LIBUV "Use the bundled libuv." ${USE_BUNDLED})
  40. option(USE_BUNDLED_MSGPACK "Use the bundled msgpack." ${USE_BUNDLED})
  41. option(USE_BUNDLED_LUAJIT "Use the bundled version of luajit." ${USE_BUNDLED})
  42. option(USE_BUNDLED_LUAROCKS "Use the bundled version of luarocks." ${USE_BUNDLED})
  43. option(USE_BUNDLED_LUV "Use the bundled version of luv." ${USE_BUNDLED})
  44. #XXX(tarruda): Lua is only used for debugging the functional test client, don't
  45. # build it unless explicitly requested
  46. option(USE_BUNDLED_LUA "Use the bundled version of lua." OFF)
  47. option(USE_BUNDLED_TS_PARSERS "Use the bundled treesitter parsers." ${USE_BUNDLED})
  48. option(USE_BUNDLED_TS "Use the bundled treesitter runtime." ${USE_BUNDLED})
  49. if(USE_BUNDLED AND MSVC)
  50. option(USE_BUNDLED_GETTEXT "Use the bundled version of gettext." ON)
  51. option(USE_BUNDLED_LIBICONV "Use the bundled version of libiconv." ON)
  52. else()
  53. option(USE_BUNDLED_GETTEXT "Use the bundled version of gettext." OFF)
  54. option(USE_BUNDLED_LIBICONV "Use the bundled version of libiconv." OFF)
  55. endif()
  56. if(WIN32)
  57. option(USE_BUNDLED_NVIMQT "Bundle neovim-qt" ON)
  58. endif()
  59. option(USE_EXISTING_SRC_DIR "Skip download of deps sources in case of existing source directory." OFF)
  60. find_package(Git)
  61. if(NOT Git_FOUND)
  62. message(FATAL_ERROR "Git is required to apply patches.")
  63. endif()
  64. if(UNIX)
  65. find_program(MAKE_PRG NAMES gmake make)
  66. if(NOT MAKE_PRG)
  67. message(FATAL_ERROR "GNU Make is required to build the dependencies.")
  68. else()
  69. message(STATUS "Found GNU Make at ${MAKE_PRG}")
  70. endif()
  71. endif()
  72. # When using make, use the $(MAKE) variable to avoid warning about the job
  73. # server.
  74. if(CMAKE_GENERATOR MATCHES "Makefiles")
  75. set(MAKE_PRG "$(MAKE)")
  76. endif()
  77. if(MINGW AND CMAKE_GENERATOR MATCHES "Ninja")
  78. find_program(MAKE_PRG NAMES mingw32-make)
  79. if(NOT MAKE_PRG)
  80. message(FATAL_ERROR "GNU Make for mingw32 is required to build the dependencies.")
  81. else()
  82. message(STATUS "Found GNU Make for mingw32: ${MAKE_PRG}")
  83. endif()
  84. endif()
  85. set(DEPS_C_COMPILER "${CMAKE_C_COMPILER}")
  86. if(CMAKE_OSX_SYSROOT)
  87. set(DEPS_C_COMPILER "${DEPS_C_COMPILER} -isysroot${CMAKE_OSX_SYSROOT}")
  88. endif()
  89. if(CMAKE_OSX_ARCHITECTURES)
  90. # The LuaJIT build does not like being passed multiple `-arch` flags
  91. # so we handle a universal build the old-fashioned way.
  92. set(LUAJIT_C_COMPILER "${DEPS_C_COMPILER}")
  93. foreach(ARCH IN LISTS CMAKE_OSX_ARCHITECTURES)
  94. set(DEPS_C_COMPILER "${DEPS_C_COMPILER} -arch ${ARCH}")
  95. endforeach()
  96. endif()
  97. # If the macOS deployment target is not set manually (via $MACOSX_DEPLOYMENT_TARGET),
  98. # fall back to local system version. Needs to be done here and in top-level CMakeLists.txt.
  99. if(APPLE)
  100. if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
  101. execute_process(COMMAND sw_vers -productVersion
  102. OUTPUT_VARIABLE MACOS_VERSION
  103. OUTPUT_STRIP_TRAILING_WHITESPACE)
  104. set(CMAKE_OSX_DEPLOYMENT_TARGET "${MACOS_VERSION}")
  105. endif()
  106. message(STATUS "Using deployment target ${CMAKE_OSX_DEPLOYMENT_TARGET}")
  107. endif()
  108. include(ExternalProject)
  109. set_directory_properties(PROPERTIES EP_PREFIX "${DEPS_BUILD_DIR}")
  110. set(LIBUV_URL https://github.com/libuv/libuv/archive/v1.46.0.tar.gz)
  111. set(LIBUV_SHA256 7aa66be3413ae10605e1f5c9ae934504ffe317ef68ea16fdaa83e23905c681bd)
  112. set(MSGPACK_URL https://github.com/msgpack/msgpack-c/releases/download/c-6.0.0/msgpack-c-6.0.0.tar.gz)
  113. set(MSGPACK_SHA256 3654f5e2c652dc52e0a993e270bb57d5702b262703f03771c152bba51602aeba)
  114. # https://github.com/LuaJIT/LuaJIT/tree/v2.1
  115. set(LUAJIT_URL https://github.com/LuaJIT/LuaJIT/archive/03c31124cc3b521ef54fe398e10fa55660a5057d.tar.gz)
  116. set(LUAJIT_SHA256 61dcc7ae3f543ae3cc30e66db060e31e2a77e4be34ee65e370c953d112b4d60c)
  117. set(LUA_URL https://www.lua.org/ftp/lua-5.1.5.tar.gz)
  118. set(LUA_SHA256 2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333)
  119. set(LUAROCKS_URL https://github.com/luarocks/luarocks/archive/v3.9.2.tar.gz)
  120. set(LUAROCKS_SHA256 a0b36cd68586cd79966d0106bb2e5a4f5523327867995fd66bee4237062b3e3b)
  121. set(UNIBILIUM_URL https://github.com/neovim/unibilium/archive/d72c3598e7ac5d1ebf86ee268b8b4ed95c0fa628.tar.gz)
  122. set(UNIBILIUM_SHA256 9c4747c862ab5e3076dcf8fa8f0ea7a6b50f20ec5905618b9536655596797487)
  123. set(LIBTERMKEY_URL https://github.com/neovim/deps/raw/aa004f1b2b6470a92363cba8e1cc1874141dacc4/opt/libtermkey-0.22.tar.gz)
  124. set(LIBTERMKEY_SHA256 6945bd3c4aaa83da83d80a045c5563da4edd7d0374c62c0d35aec09eb3014600)
  125. set(LIBVTERM_URL https://github.com/neovim/deps/raw/12c9dcf1d823ac4acbccf494c93c4774a87db11d/opt/libvterm-0.3.3.tar.gz)
  126. set(LIBVTERM_SHA256 09156f43dd2128bd347cbeebe50d9a571d32c64e0cf18d211197946aff7226e0)
  127. set(LUV_URL https://github.com/luvit/luv/archive/1.45.0-0.tar.gz)
  128. set(LUV_SHA256 97e89940f9eeaa8dfb34f1c19f80dd373299c42719d15228ec790f415d4e4965)
  129. set(LUA_COMPAT53_URL https://github.com/keplerproject/lua-compat-5.3/archive/v0.9.tar.gz)
  130. set(LUA_COMPAT53_SHA256 ad05540d2d96a48725bb79a1def35cf6652a4e2ec26376e2617c8ce2baa6f416)
  131. # Windows only: cat.exe diff.exe tee.exe xxd.exe
  132. set(CAT_URL https://github.com/neovim/deps/raw/21c5e8bdda33521a6ed497b315e03265a2785cbc/opt/cat.exe)
  133. set(CAT_SHA256 93b8d307bb15af3968920bdea3beb869a49d166f9164853c58a4e6ffdcae61c6)
  134. set(DIFF_URL https://github.com/neovim/deps/raw/21c5e8bdda33521a6ed497b315e03265a2785cbc/opt/diff.exe)
  135. set(DIFF_SHA256 4ceceebc8150422c6d8d9a06c2e9686d5a5d90f1033f60ad92ab81fe810e2a28)
  136. set(TEE_URL https://github.com/neovim/deps/raw/21c5e8bdda33521a6ed497b315e03265a2785cbc/opt/tee.exe)
  137. set(TEE_SHA256 950eea4e17fa3a7e89fa2c55374037b5797b3f1a54fea1304634884ab42ec14d)
  138. set(XXD_URL https://github.com/neovim/deps/raw/21c5e8bdda33521a6ed497b315e03265a2785cbc/opt/xxd.exe)
  139. set(XXD_SHA256 7a581e3882d28161cc52850f9a11d634b3eaf2c029276f093c1ed4c90e45a10c)
  140. set(WINGUI_URL https://github.com/equalsraf/neovim-qt/releases/download/v0.2.17/neovim-qt.zip)
  141. set(WINGUI_SHA256 502e386eef677c2c2e0c11d8cbb27f3e12b4d96818369417e8da4129c4580c25)
  142. set(WIN32YANK_X86_64_URL https://github.com/equalsraf/win32yank/releases/download/v0.1.1/win32yank-x64.zip)
  143. set(WIN32YANK_X86_64_SHA256 247c9a05b94387a884b49d3db13f806b1677dfc38020f955f719be6902260cd6)
  144. set(GETTEXT_URL https://ftp.gnu.org/pub/gnu/gettext/gettext-0.20.1.tar.gz)
  145. set(GETTEXT_SHA256 66415634c6e8c3fa8b71362879ec7575e27da43da562c798a8a2f223e6e47f5c)
  146. set(LIBICONV_URL https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz)
  147. set(LIBICONV_SHA256 ccf536620a45458d26ba83887a983b96827001e92a13847b45e4925cc8913178)
  148. set(TREESITTER_C_URL https://github.com/tree-sitter/tree-sitter-c/archive/v0.20.5.tar.gz)
  149. set(TREESITTER_C_SHA256 694a5408246ee45d535df9df025febecdb50bee764df64a94346b9805a5f349b )
  150. set(TREESITTER_LUA_URL https://github.com/MunifTanjim/tree-sitter-lua/archive/v0.0.18.tar.gz)
  151. set(TREESITTER_LUA_SHA256 659beef871a7fa1d9a02c23f5ebf55019aa3adce6d7f5441947781e128845256)
  152. set(TREESITTER_VIM_URL https://github.com/neovim/tree-sitter-vim/archive/v0.3.0.tar.gz)
  153. set(TREESITTER_VIM_SHA256 403acec3efb7cdb18ff3d68640fc823502a4ffcdfbb71cec3f98aa786c21cbe2)
  154. set(TREESITTER_VIMDOC_URL https://github.com/neovim/tree-sitter-vimdoc/archive/v2.0.0.tar.gz)
  155. set(TREESITTER_VIMDOC_SHA256 1ff8f4afd3a9599dd4c3ce87c155660b078c1229704d1a254433e33794b8f274)
  156. set(TREESITTER_QUERY_URL https://github.com/nvim-treesitter/tree-sitter-query/archive/v0.1.0.tar.gz)
  157. set(TREESITTER_QUERY_SHA256 e2b806f80e8bf1c4f4e5a96248393fe6622fc1fc6189d6896d269658f67f914c)
  158. set(TREESITTER_URL https://github.com/tree-sitter/tree-sitter/archive/v0.20.8.tar.gz)
  159. set(TREESITTER_SHA256 6181ede0b7470bfca37e293e7d5dc1d16469b9485d13f13a605baec4a8b1f791)
  160. if(USE_EXISTING_SRC_DIR)
  161. get_cmake_property(VARS VARIABLES)
  162. foreach (VAR ${VARS})
  163. if(VAR MATCHES "^.*URL$")
  164. unset(${VAR})
  165. endif()
  166. endforeach()
  167. endif()
  168. if(USE_BUNDLED_UNIBILIUM)
  169. include(BuildUnibilium)
  170. endif()
  171. if(USE_BUNDLED_LIBTERMKEY)
  172. include(BuildLibtermkey)
  173. if(USE_BUNDLED_UNIBILIUM)
  174. add_dependencies(libtermkey unibilium)
  175. endif()
  176. endif()
  177. if(USE_BUNDLED_LIBVTERM)
  178. include(BuildLibvterm)
  179. endif()
  180. if(USE_BUNDLED_LIBUV)
  181. include(BuildLibuv)
  182. endif()
  183. if(USE_BUNDLED_MSGPACK)
  184. include(BuildMsgpack)
  185. endif()
  186. if(USE_BUNDLED_LUAJIT)
  187. include(BuildLuajit)
  188. endif()
  189. if(USE_BUNDLED_LUA)
  190. include(BuildLua)
  191. endif()
  192. if(USE_BUNDLED_LUAROCKS)
  193. include(BuildLuarocks)
  194. endif()
  195. if(USE_BUNDLED_LUV)
  196. include(BuildLuv)
  197. endif()
  198. if(USE_BUNDLED_GETTEXT)
  199. include(BuildGettext)
  200. endif()
  201. if(USE_BUNDLED_LIBICONV)
  202. include(BuildLibiconv)
  203. endif()
  204. if(USE_BUNDLED_TS_PARSERS)
  205. include(BuildTreesitterParsers)
  206. endif()
  207. if(USE_BUNDLED_TS)
  208. include(BuildTreesitter)
  209. endif()
  210. if(WIN32)
  211. include(GetBinaryDeps)
  212. GetExecutable(TARGET cat)
  213. GetExecutable(TARGET diff)
  214. GetExecutable(TARGET tee)
  215. GetExecutable(TARGET xxd)
  216. if(USE_BUNDLED_NVIMQT)
  217. GetBinaryDep(TARGET wingui
  218. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory bin ${DEPS_BIN_DIR}
  219. COMMAND ${CMAKE_COMMAND} -E copy_directory share ${DEPS_INSTALL_DIR}/share)
  220. endif()
  221. GetBinaryDep(TARGET win32yank_X86_64
  222. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy win32yank.exe ${DEPS_BIN_DIR})
  223. endif()