CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. set(DEPS_INSTALL_DIR "${CMAKE_BINARY_DIR}/usr" CACHE PATH "Dependencies install directory.")
  19. set(DEPS_BIN_DIR "${DEPS_INSTALL_DIR}/bin" CACHE PATH "Dependencies binary install directory.")
  20. set(DEPS_LIB_DIR "${DEPS_INSTALL_DIR}/lib" CACHE PATH "Dependencies library install directory.")
  21. set(DEPS_BUILD_DIR "${CMAKE_BINARY_DIR}/build" CACHE PATH "Dependencies build directory.")
  22. set(DEPS_DOWNLOAD_DIR "${DEPS_BUILD_DIR}/downloads" CACHE PATH "Dependencies download directory.")
  23. option(USE_BUNDLED "Use bundled dependencies." ON)
  24. option(USE_BUNDLED_GPERF "Use the bundled version of gperf." ${USE_BUNDLED})
  25. option(USE_BUNDLED_UNIBILIUM "Use the bundled unibilium." ${USE_BUNDLED})
  26. option(USE_BUNDLED_LIBTERMKEY "Use the bundled libtermkey." ${USE_BUNDLED})
  27. option(USE_BUNDLED_LIBVTERM "Use the bundled libvterm." ${USE_BUNDLED})
  28. option(USE_BUNDLED_LIBUV "Use the bundled libuv." ${USE_BUNDLED})
  29. option(USE_BUNDLED_MSGPACK "Use the bundled msgpack." ${USE_BUNDLED})
  30. option(USE_BUNDLED_LUAJIT "Use the bundled version of luajit." ${USE_BUNDLED})
  31. option(USE_BUNDLED_LUAROCKS "Use the bundled version of luarocks." ${USE_BUNDLED})
  32. option(USE_BUNDLED_LUV "Use the bundled version of luv." ${USE_BUNDLED})
  33. #XXX(tarruda): Lua is only used for debugging the functional test client, no
  34. # build it unless explicitly requested
  35. option(USE_BUNDLED_LUA "Use the bundled version of lua." OFF)
  36. if(USE_BUNDLED AND MSVC)
  37. option(USE_BUNDLED_GETTEXT "Use the bundled version of gettext." ON)
  38. option(USE_BUNDLED_LIBICONV "Use the bundled version of libiconv." ON)
  39. else()
  40. option(USE_BUNDLED_GETTEXT "Use the bundled version of gettext." OFF)
  41. option(USE_BUNDLED_LIBICONV "Use the bundled version of libiconv." OFF)
  42. endif()
  43. option(USE_EXISTING_SRC_DIR "Skip download of deps sources in case of existing source directory." OFF)
  44. if(WIN32)
  45. find_package(Git)
  46. if(NOT Git_FOUND)
  47. message(FATAL_ERROR "Git is required to apply patches for Windows.")
  48. endif()
  49. endif()
  50. if(UNIX)
  51. find_program(MAKE_PRG NAMES gmake make)
  52. if(MAKE_PRG)
  53. execute_process(
  54. COMMAND "${MAKE_PRG}" --version
  55. OUTPUT_VARIABLE MAKE_VERSION_INFO)
  56. if(NOT "${OUTPUT_VARIABLE}" MATCHES ".*GNU.*")
  57. unset(MAKE_PRG)
  58. endif()
  59. endif()
  60. if(NOT MAKE_PRG)
  61. message(FATAL_ERROR "GNU Make is required to build the dependencies.")
  62. else()
  63. message(STATUS "Found GNU Make at ${MAKE_PRG}")
  64. endif()
  65. endif()
  66. # When using make, use the $(MAKE) variable to avoid warning about the job
  67. # server.
  68. if(CMAKE_GENERATOR MATCHES "Makefiles")
  69. set(MAKE_PRG "$(MAKE)")
  70. endif()
  71. if(MINGW AND CMAKE_GENERATOR MATCHES "Ninja")
  72. find_program(MAKE_PRG NAMES mingw32-make)
  73. if(NOT MAKE_PRG)
  74. message(FATAL_ERROR "GNU Make for mingw32 is required to build the dependecies.")
  75. else()
  76. message(STATUS "Found GNU Make for mingw32: ${MAKE_PRG}")
  77. endif()
  78. endif()
  79. if(CMAKE_C_COMPILER_ARG1)
  80. set(DEPS_C_COMPILER "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
  81. else()
  82. set(DEPS_C_COMPILER "${CMAKE_C_COMPILER}")
  83. endif()
  84. if(USE_BUNDLED_GPERF)
  85. enable_language(CXX)
  86. endif()
  87. if(CMAKE_CXX_COMPILER)
  88. set(DEPS_CXX_COMPILER "${CMAKE_CXX_COMPILER}")
  89. endif()
  90. if(CMAKE_OSX_SYSROOT)
  91. set(DEPS_C_COMPILER "${DEPS_C_COMPILER} -isysroot${CMAKE_OSX_SYSROOT}")
  92. if(DEPS_CXX_COMPILER)
  93. set(DEPS_CXX_COMPILER "${DEPS_CXX_COMPILER} -isysroot${CMAKE_OSX_SYSROOT}")
  94. endif()
  95. endif()
  96. # Cross compiling: use these for dependencies built for the
  97. # HOST system, when not crosscompiling these should be the
  98. # same as DEPS_*. Except when targeting Unix in which case
  99. # want all the dependencies to use the same compiler.
  100. if(CMAKE_CROSSCOMPILING AND NOT UNIX)
  101. set(HOSTDEPS_INSTALL_DIR "${CMAKE_BINARY_DIR}/host")
  102. set(HOSTDEPS_BIN_DIR "${HOSTDEPS_INSTALL_DIR}/bin")
  103. set(HOSTDEPS_LIB_DIR "${HOSTDEPS_INSTALL_DIR}/lib")
  104. set(HOSTDEPS_C_COMPILER "${HOST_C_COMPILER}")
  105. set(HOSTDEPS_CXX_COMPILER "${HOST_CXX_COMPILER}")
  106. else()
  107. set(HOSTDEPS_INSTALL_DIR "${DEPS_INSTALL_DIR}")
  108. set(HOSTDEPS_BIN_DIR "${DEPS_BIN_DIR}")
  109. set(HOSTDEPS_LIB_DIR "${DEPS_LIB_DIR}")
  110. set(HOSTDEPS_C_COMPILER "${DEPS_C_COMPILER}")
  111. set(HOSTDEPS_CXX_COMPILER "${DEPS_CXX_COMPILER}")
  112. endif()
  113. include(ExternalProject)
  114. if(WIN32)
  115. # "nvim" branch of https://github.com/neovim/libuv
  116. set(LIBUV_URL https://github.com/neovim/libuv/archive/eeae18d085de25f138c23966f98a179f0fb609e7.tar.gz)
  117. set(LIBUV_SHA256 c37d0b7cb1defe69ae8dbb4d712c0d7cf838d6539178e8bcf71c72579ab5b666)
  118. else()
  119. set(LIBUV_URL https://github.com/libuv/libuv/archive/v1.30.0.tar.gz)
  120. set(LIBUV_SHA256 44c8fdadf3b3f393006a4ac4ba144020673a3f9cd72bed1fbb2c366ebcf0d199)
  121. endif()
  122. set(MSGPACK_URL https://github.com/msgpack/msgpack-c/releases/download/cpp-3.0.0/msgpack-3.0.0.tar.gz)
  123. set(MSGPACK_SHA256 bfbb71b7c02f806393bc3cbc491b40523b89e64f83860c58e3e54af47de176e4)
  124. # https://github.com/LuaJIT/LuaJIT/tree/v2.0
  125. set(LUAJIT_URL https://github.com/LuaJIT/LuaJIT/archive/61464b0a5b685489bee7b6680c0e9663f2143a84.tar.gz)
  126. set(LUAJIT_SHA256 033fa4ef19f559ef18a9b9fb017d0cb8be58befe05ab604e92814234910f1c68)
  127. set(LUA_URL https://www.lua.org/ftp/lua-5.1.5.tar.gz)
  128. set(LUA_SHA256 2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333)
  129. set(LUAROCKS_URL https://github.com/luarocks/luarocks/archive/v2.4.4.tar.gz)
  130. set(LUAROCKS_SHA256 9eb3d0738fd02ad8bf39bcedccac4e83e9b5fff2bcca247c3584b925b2075d9c)
  131. set(UNIBILIUM_URL https://github.com/neovim/unibilium/archive/92d929f.tar.gz)
  132. set(UNIBILIUM_SHA256 29815283c654277ef77a3adcc8840db79ddbb20a0f0b0c8f648bd8cd49a02e4b)
  133. set(LIBTERMKEY_URL http://www.leonerd.org.uk/code/libtermkey/libtermkey-0.21.1.tar.gz)
  134. set(LIBTERMKEY_SHA256 cecbf737f35d18f433c8d7864f63c0f878af41f8bd0255a3ebb16010dc044d5f)
  135. set(LIBVTERM_URL http://www.leonerd.org.uk/code/libvterm/libvterm-0.1.4.tar.gz)
  136. set(LIBVTERM_SHA256 bc70349e95559c667672fc8c55b9527d9db9ada0fb80a3beda533418d782d3dd)
  137. set(LUV_VERSION 1.30.0-0)
  138. set(LUV_URL https://github.com/luvit/luv/archive/${LUV_VERSION}.tar.gz)
  139. set(LUV_SHA256 6e468fa17bf222ca8ce0bfffdbdf947fc897da48643a12955db92f80e2c852f5)
  140. set(LUA_COMPAT53_URL https://github.com/keplerproject/lua-compat-5.3/archive/v0.7.tar.gz)
  141. set(LUA_COMPAT53_SHA256 bec3a23114a3d9b3218038309657f0f506ad10dfbc03bb54e91da7e5ffdba0a2)
  142. set(GPERF_URL https://github.com/neovim/deps/raw/ff5b4b18a87397a8564016071ae64f64bcd8c635/opt/gperf-3.1.tar.gz)
  143. set(GPERF_SHA256 588546b945bba4b70b6a3a616e80b4ab466e3f33024a352fc2198112cdbb3ae2)
  144. # 7za.exe cat.exe curl.exe ca-bundle.crt diff.exe tee.exe tidy.exe xxd.exe
  145. set(WINTOOLS_URL https://github.com/neovim/deps/raw/2f9acbecf06365c10baa3c0087f34a54c9c6f949/opt/win32tools.zip)
  146. set(WINTOOLS_SHA256 8bfce7e3a365721a027ce842f2ec1cf878f1726233c215c05964aac07300798c)
  147. set(WINGUI_URL https://github.com/equalsraf/neovim-qt/releases/download/v0.2.15/neovim-qt.zip)
  148. set(WINGUI_SHA256 b519ecb80b60522d25043f2d076a55656f5fbe5adf7f7e2943e5d8b161043987)
  149. set(WIN32YANK_X86_URL https://github.com/equalsraf/win32yank/releases/download/v0.0.4/win32yank-x86.zip)
  150. set(WIN32YANK_X86_SHA256 62f34e5a46c5d4a7b3f3b512e1ff7b77fedd432f42581cbe825233a996eed62c)
  151. set(WIN32YANK_X86_64_URL https://github.com/equalsraf/win32yank/releases/download/v0.0.4/win32yank-x64.zip)
  152. set(WIN32YANK_X86_64_SHA256 33a747a92da60fb65e668edbf7661d3d902411a2d545fe9dc08623cecd142a20)
  153. set(WINPTY_URL https://github.com/rprichard/winpty/releases/download/0.4.3/winpty-0.4.3-msvc2015.zip)
  154. set(WINPTY_SHA256 35a48ece2ff4acdcbc8299d4920de53eb86b1fb41e64d2fe5ae7898931bcee89)
  155. set(GETTEXT_URL https://ftp.gnu.org/pub/gnu/gettext/gettext-0.19.8.1.tar.gz)
  156. set(GETTEXT_SHA256 ff942af0e438ced4a8b0ea4b0b6e0d6d657157c5e2364de57baa279c1c125c43)
  157. set(LIBICONV_URL https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz)
  158. set(LIBICONV_SHA256 ccf536620a45458d26ba83887a983b96827001e92a13847b45e4925cc8913178)
  159. if(USE_BUNDLED_UNIBILIUM)
  160. include(BuildUnibilium)
  161. endif()
  162. if(USE_BUNDLED_LIBTERMKEY)
  163. include(BuildLibtermkey)
  164. if(USE_BUNDLED_UNIBILIUM)
  165. add_dependencies(libtermkey unibilium)
  166. endif()
  167. endif()
  168. if(USE_BUNDLED_LIBVTERM)
  169. include(BuildLibvterm)
  170. endif()
  171. if(USE_BUNDLED_LIBUV)
  172. include(BuildLibuv)
  173. endif()
  174. if(USE_BUNDLED_MSGPACK)
  175. include(BuildMsgpack)
  176. endif()
  177. if(USE_BUNDLED_LUAJIT)
  178. include(BuildLuajit)
  179. endif()
  180. if(USE_BUNDLED_LUA AND NOT CMAKE_CROSSCOMPILING)
  181. include(BuildLua)
  182. endif()
  183. if(USE_BUNDLED_LUAROCKS)
  184. include(BuildLuarocks)
  185. endif()
  186. if(USE_BUNDLED_LUV)
  187. include(BuildLuv)
  188. endif()
  189. if(USE_BUNDLED_GPERF)
  190. include(BuildGperf)
  191. endif()
  192. if(USE_BUNDLED_GETTEXT)
  193. include(BuildGettext)
  194. endif()
  195. if(USE_BUNDLED_LIBICONV)
  196. include(BuildLibiconv)
  197. endif()
  198. if(WIN32)
  199. include(GetBinaryDeps)
  200. GetBinaryDep(TARGET wintools
  201. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${DEPS_INSTALL_DIR}/bin)
  202. GetBinaryDep(TARGET wingui
  203. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory bin ${DEPS_INSTALL_DIR}/bin
  204. COMMAND ${CMAKE_COMMAND} -E copy_directory share ${DEPS_INSTALL_DIR}/share)
  205. include(TargetArch)
  206. GetBinaryDep(TARGET "win32yank_${TARGET_ARCH}"
  207. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy win32yank.exe ${DEPS_INSTALL_DIR}/bin)
  208. if("${TARGET_ARCH}" STREQUAL "X86_64")
  209. set(TARGET_ARCH x64)
  210. elseif(TARGET_ARCH STREQUAL "X86")
  211. set(TARGET_ARCH ia32)
  212. endif()
  213. GetBinaryDep(TARGET winpty
  214. INSTALL_COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/bin
  215. COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/winpty/${TARGET_ARCH}/bin/*
  216. -DTO=${DEPS_INSTALL_DIR}/bin/
  217. -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake
  218. COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/winpty/include/*
  219. -DTO=${DEPS_INSTALL_DIR}/include/
  220. -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake
  221. COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/winpty/${TARGET_ARCH}/lib/*
  222. -DTO=${DEPS_INSTALL_DIR}/lib/
  223. -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake)
  224. endif()
  225. add_custom_target(clean-shared-libraries
  226. COMMAND ${CMAKE_COMMAND}
  227. -DREMOVE_FILE_GLOB=${DEPS_INSTALL_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}*${CMAKE_SHARED_LIBRARY_SUFFIX}*
  228. -P ${PROJECT_SOURCE_DIR}/cmake/RemoveFiles.cmake
  229. DEPENDS ${THIRD_PARTY_DEPS}
  230. )
  231. add_custom_target(third-party ALL
  232. COMMAND ${CMAKE_COMMAND} -E touch .third-party
  233. DEPENDS clean-shared-libraries)