BuildLuarocks.cmake 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # Luarocks recipe. Luarocks is only required when building Neovim, when
  2. # cross compiling we still want to build for the HOST system, whenever
  3. # writing a recipe that is meant for cross-compile, use the HOSTDEPS_* variables
  4. # instead of DEPS_* - check the main CMakeLists.txt for a list.
  5. #
  6. # NOTE: LuaRocks rocks need to "DEPENDS" on the previous module, because
  7. # running luarocks in parallel will break, e.g. when some rocks have
  8. # the same dependency..
  9. option(USE_BUNDLED_BUSTED "Use the bundled version of busted to run tests." ON)
  10. # BuildLuarocks(CONFIGURE_COMMAND ... BUILD_COMMAND ... INSTALL_COMMAND ...)
  11. # Reusable function to build luarocks, wraps ExternalProject_Add.
  12. # Failing to pass a command argument will result in no command being run
  13. function(BuildLuarocks)
  14. cmake_parse_arguments(_luarocks
  15. ""
  16. ""
  17. "CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND"
  18. ${ARGN})
  19. if(NOT _luarocks_CONFIGURE_COMMAND AND NOT _luarocks_BUILD_COMMAND
  20. AND NOT _luarocks_INSTALL_COMMAND)
  21. message(FATAL_ERROR "Must pass at least one of CONFIGURE_COMMAND, BUILD_COMMAND, INSTALL_COMMAND")
  22. endif()
  23. ExternalProject_Add(luarocks
  24. PREFIX ${DEPS_BUILD_DIR}
  25. URL ${LUAROCKS_URL}
  26. DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/luarocks
  27. DOWNLOAD_COMMAND ${CMAKE_COMMAND}
  28. -DPREFIX=${DEPS_BUILD_DIR}
  29. -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/luarocks
  30. -DURL=${LUAROCKS_URL}
  31. -DEXPECTED_SHA256=${LUAROCKS_SHA256}
  32. -DTARGET=luarocks
  33. -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
  34. -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
  35. BUILD_IN_SOURCE 1
  36. CONFIGURE_COMMAND "${_luarocks_CONFIGURE_COMMAND}"
  37. BUILD_COMMAND "${_luarocks_BUILD_COMMAND}"
  38. INSTALL_COMMAND "${_luarocks_INSTALL_COMMAND}")
  39. endfunction()
  40. # The luarocks binary location
  41. set(LUAROCKS_BINARY ${HOSTDEPS_BIN_DIR}/luarocks)
  42. # Arguments for calls to 'luarocks build'
  43. if(NOT MSVC)
  44. # In MSVC don't pass the compiler/linker to luarocks, the bundled
  45. # version already knows, and passing them here breaks the build
  46. set(LUAROCKS_BUILDARGS CC=${HOSTDEPS_C_COMPILER} LD=${HOSTDEPS_C_COMPILER})
  47. endif()
  48. if(UNIX OR (MINGW AND CMAKE_CROSSCOMPILING))
  49. if(USE_BUNDLED_LUAJIT)
  50. list(APPEND LUAROCKS_OPTS
  51. --with-lua=${HOSTDEPS_INSTALL_DIR}
  52. --with-lua-include=${HOSTDEPS_INSTALL_DIR}/include/luajit-2.0
  53. --lua-suffix=jit)
  54. elseif(USE_BUNDLED_LUA)
  55. list(APPEND LUAROCKS_OPTS
  56. --with-lua=${HOSTDEPS_INSTALL_DIR})
  57. else()
  58. find_package(LuaJit)
  59. if(LUAJIT_FOUND)
  60. list(APPEND LUAROCKS_OPTS
  61. --lua-version=5.1
  62. --with-lua-include=${LUAJIT_INCLUDE_DIRS}
  63. --lua-suffix=jit)
  64. endif()
  65. endif()
  66. BuildLuarocks(
  67. CONFIGURE_COMMAND ${DEPS_BUILD_DIR}/src/luarocks/configure
  68. --prefix=${HOSTDEPS_INSTALL_DIR} --force-config ${LUAROCKS_OPTS}
  69. INSTALL_COMMAND ${MAKE_PRG} -j1 bootstrap)
  70. elseif(MSVC OR MINGW)
  71. if(MINGW)
  72. set(COMPILER_FLAG /MW)
  73. elseif(MSVC)
  74. set(COMPILER_FLAG /MSVC)
  75. endif()
  76. # Ignore USE_BUNDLED_LUAJIT - always ON for native Win32
  77. BuildLuarocks(INSTALL_COMMAND install.bat /FORCECONFIG /NOREG /NOADMIN /Q /F
  78. /LUA ${DEPS_INSTALL_DIR}
  79. /LIB ${DEPS_LIB_DIR}
  80. /BIN ${DEPS_BIN_DIR}
  81. /INC ${DEPS_INSTALL_DIR}/include/luajit-2.0
  82. /P ${DEPS_INSTALL_DIR}/luarocks /TREE ${DEPS_INSTALL_DIR}
  83. /SCRIPTS ${DEPS_BIN_DIR}
  84. /CMOD ${DEPS_BIN_DIR}
  85. ${COMPILER_FLAG}
  86. /LUAMOD ${DEPS_BIN_DIR}/lua)
  87. set(LUAROCKS_BINARY ${DEPS_INSTALL_DIR}/luarocks/luarocks.bat)
  88. else()
  89. message(FATAL_ERROR "Trying to build luarocks in an unsupported system ${CMAKE_SYSTEM_NAME}/${CMAKE_C_COMPILER_ID}")
  90. endif()
  91. list(APPEND THIRD_PARTY_DEPS luarocks)
  92. if(USE_BUNDLED_LUAJIT)
  93. add_dependencies(luarocks luajit)
  94. if(MINGW AND CMAKE_CROSSCOMPILING)
  95. add_dependencies(luarocks luajit_host)
  96. endif()
  97. elseif(USE_BUNDLED_LUA)
  98. add_dependencies(luarocks lua)
  99. endif()
  100. set(ROCKS_DIR ${HOSTDEPS_LIB_DIR}/luarocks/rocks)
  101. # mpack
  102. add_custom_command(OUTPUT ${ROCKS_DIR}/mpack
  103. COMMAND ${LUAROCKS_BINARY}
  104. ARGS build mpack 1.0.8-0 ${LUAROCKS_BUILDARGS}
  105. DEPENDS luarocks)
  106. add_custom_target(mpack DEPENDS ${ROCKS_DIR}/mpack)
  107. list(APPEND THIRD_PARTY_DEPS mpack)
  108. # lpeg
  109. add_custom_command(OUTPUT ${ROCKS_DIR}/lpeg
  110. COMMAND ${LUAROCKS_BINARY}
  111. ARGS build lpeg 1.0.2-1 ${LUAROCKS_BUILDARGS}
  112. DEPENDS mpack)
  113. add_custom_target(lpeg DEPENDS ${ROCKS_DIR}/lpeg)
  114. list(APPEND THIRD_PARTY_DEPS lpeg)
  115. if((NOT USE_BUNDLED_LUAJIT) AND USE_BUNDLED_LUA)
  116. # luabitop
  117. add_custom_command(OUTPUT ${ROCKS_DIR}/luabitop
  118. COMMAND ${LUAROCKS_BINARY}
  119. ARGS build luabitop 1.0.2-3 ${LUAROCKS_BUILDARGS}
  120. DEPENDS lpeg)
  121. add_custom_target(luabitop DEPENDS ${ROCKS_DIR}/luabitop)
  122. list(APPEND THIRD_PARTY_DEPS luabitop)
  123. endif()
  124. if(USE_BUNDLED_BUSTED)
  125. if((NOT USE_BUNDLED_LUAJIT) AND USE_BUNDLED_LUA)
  126. set(PENLIGHT_DEPENDS luabitop)
  127. else()
  128. set(PENLIGHT_DEPENDS lpeg)
  129. endif()
  130. # penlight
  131. add_custom_command(OUTPUT ${ROCKS_DIR}/penlight
  132. COMMAND ${LUAROCKS_BINARY}
  133. ARGS build penlight 1.5.4-1 ${LUAROCKS_BUILDARGS}
  134. DEPENDS ${PENLIGHT_DEPENDS})
  135. add_custom_target(penlight DEPENDS ${ROCKS_DIR}/penlight)
  136. # busted
  137. if(WIN32)
  138. set(BUSTED_EXE "${HOSTDEPS_BIN_DIR}/busted.bat")
  139. set(LUACHECK_EXE "${HOSTDEPS_BIN_DIR}/luacheck.bat")
  140. else()
  141. set(BUSTED_EXE "${HOSTDEPS_BIN_DIR}/busted")
  142. set(LUACHECK_EXE "${HOSTDEPS_BIN_DIR}/luacheck")
  143. endif()
  144. add_custom_command(OUTPUT ${BUSTED_EXE}
  145. COMMAND ${LUAROCKS_BINARY}
  146. ARGS build busted 2.0.0 ${LUAROCKS_BUILDARGS}
  147. DEPENDS penlight)
  148. add_custom_target(busted DEPENDS ${BUSTED_EXE})
  149. # luacheck
  150. add_custom_command(OUTPUT ${LUACHECK_EXE}
  151. COMMAND ${LUAROCKS_BINARY}
  152. ARGS build luacheck 0.23.0-1 ${LUAROCKS_BUILDARGS}
  153. DEPENDS busted)
  154. add_custom_target(luacheck DEPENDS ${LUACHECK_EXE})
  155. # luv
  156. set(LUV_DEPS luacheck)
  157. if(USE_BUNDLED_LUV)
  158. list(APPEND LUV_DEPS luv-static lua-compat-5.3)
  159. if(MINGW AND CMAKE_CROSSCOMPILING)
  160. list(APPEND LUV_DEPS libuv_host)
  161. endif()
  162. set(LUV_ARGS "CFLAGS=-O0 -g3 -fPIC")
  163. if(USE_BUNDLED_LIBUV)
  164. list(APPEND LUV_ARGS LIBUV_DIR=${HOSTDEPS_INSTALL_DIR})
  165. endif()
  166. SET(LUV_PRIVATE_ARGS LUA_COMPAT53_INCDIR=${DEPS_BUILD_DIR}/src/lua-compat-5.3)
  167. add_custom_command(OUTPUT ${ROCKS_DIR}/luv
  168. COMMAND ${LUAROCKS_BINARY}
  169. ARGS make ${LUAROCKS_BUILDARGS} ${LUV_ARGS} ${LUV_PRIVATE_ARGS}
  170. WORKING_DIRECTORY ${DEPS_BUILD_DIR}/src/luv
  171. DEPENDS ${LUV_DEPS})
  172. else()
  173. add_custom_command(OUTPUT ${ROCKS_DIR}/luv
  174. COMMAND ${LUAROCKS_BINARY}
  175. ARGS build luv ${LUV_VERSION} ${LUAROCKS_BUILDARGS}
  176. DEPENDS ${LUV_DEPS})
  177. endif()
  178. add_custom_target(luv DEPENDS ${ROCKS_DIR}/luv)
  179. # nvim-client
  180. add_custom_command(OUTPUT ${ROCKS_DIR}/nvim-client
  181. COMMAND ${LUAROCKS_BINARY}
  182. ARGS build nvim-client 0.2.0-1 ${LUAROCKS_BUILDARGS}
  183. DEPENDS luv)
  184. add_custom_target(nvim-client DEPENDS ${ROCKS_DIR}/nvim-client)
  185. list(APPEND THIRD_PARTY_DEPS busted luacheck nvim-client)
  186. endif()