CMakeLists.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # This is not meant to be included by the top-level.
  2. cmake_minimum_required(VERSION 3.16)
  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(ExternalProject)
  11. include(FindPackageHandleStandardArgs)
  12. include(Deps)
  13. include(Find)
  14. include(Util)
  15. #-------------------------------------------------------------------------------
  16. # User settings
  17. #-------------------------------------------------------------------------------
  18. set(DEPS_IGNORE_SHA FALSE)
  19. # Options
  20. option(USE_BUNDLED "Use bundled dependencies." ON)
  21. option(USE_BUNDLED_LIBUV "Use the bundled libuv." ${USE_BUNDLED})
  22. option(USE_BUNDLED_LPEG "Use the bundled lpeg." ${USE_BUNDLED})
  23. # PUC Lua is only used for tests, unless explicitly requested.
  24. option(USE_BUNDLED_LUA "Use the bundled version of lua." OFF)
  25. option(USE_BUNDLED_LUAJIT "Use the bundled version of luajit." ${USE_BUNDLED})
  26. option(USE_BUNDLED_LUV "Use the bundled version of luv." ${USE_BUNDLED})
  27. option(USE_BUNDLED_TS "Use the bundled treesitter runtime." ${USE_BUNDLED})
  28. option(USE_BUNDLED_TS_PARSERS "Use the bundled treesitter parsers." ${USE_BUNDLED})
  29. option(USE_BUNDLED_UNIBILIUM "Use the bundled unibilium." ${USE_BUNDLED})
  30. option(USE_BUNDLED_UTF8PROC "Use the bundled utf8proc library." ${USE_BUNDLED})
  31. if(USE_BUNDLED AND MSVC)
  32. option(USE_BUNDLED_GETTEXT "Use the bundled version of gettext." ON)
  33. option(USE_BUNDLED_LIBICONV "Use the bundled version of libiconv." ON)
  34. else()
  35. option(USE_BUNDLED_GETTEXT "Use the bundled version of gettext." OFF)
  36. option(USE_BUNDLED_LIBICONV "Use the bundled version of libiconv." OFF)
  37. endif()
  38. option(ENABLE_WASMTIME "Use treesitter with wasmtime support." OFF)
  39. if(ENABLE_WASMTIME)
  40. if(USE_BUNDLED)
  41. option(USE_BUNDLED_WASMTIME "Use the bundled wasmtime." ON)
  42. else()
  43. option(USE_BUNDLED_WASMTIME "Use the bundled wasmtime." OFF)
  44. endif()
  45. endif()
  46. if(NOT ENABLE_WASMTIME AND USE_BUNDLED_WASMTIME)
  47. message(FATAL_ERROR "ENABLE_WASMTIME is set to OFF while USE_BUNDLED_WASMTIME is set to ON.\
  48. You need set ENABLE_WASMTIME to ON if you want to use wasmtime.")
  49. endif()
  50. option(USE_EXISTING_SRC_DIR "Skip download of deps sources in case of existing source directory." OFF)
  51. set_default_buildtype(Release)
  52. get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  53. if(NOT isMultiConfig)
  54. list(APPEND DEPS_CMAKE_ARGS -D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
  55. endif()
  56. set(DEFAULT_MAKE_CFLAGS CFLAGS+=-g)
  57. check_c_compiler_flag(-Og HAS_OG_FLAG)
  58. if(HAS_OG_FLAG)
  59. set(DEFAULT_MAKE_CFLAGS CFLAGS+=-Og ${DEFAULT_MAKE_CFLAGS})
  60. endif()
  61. set(DEPS_INCLUDE_FLAGS "-I${DEPS_INSTALL_DIR}/include -I${DEPS_INSTALL_DIR}/include/luajit-2.1")
  62. # If the macOS deployment target is not set manually (via $MACOSX_DEPLOYMENT_TARGET),
  63. # fall back to local system version. Needs to be done here and in top-level CMakeLists.txt.
  64. if(APPLE)
  65. if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
  66. execute_process(COMMAND sw_vers -productVersion
  67. OUTPUT_VARIABLE MACOS_VERSION
  68. OUTPUT_STRIP_TRAILING_WHITESPACE)
  69. set(CMAKE_OSX_DEPLOYMENT_TARGET "${MACOS_VERSION}")
  70. endif()
  71. message(STATUS "Using deployment target ${CMAKE_OSX_DEPLOYMENT_TARGET}")
  72. endif()
  73. if(USE_BUNDLED_LUAJIT)
  74. set(LUA_ENGINE LuaJit)
  75. elseif(USE_BUNDLED_LUA)
  76. set(LUA_ENGINE Lua)
  77. else()
  78. find_package(Luajit)
  79. find_package(Lua 5.1 EXACT)
  80. if(LUAJIT_FOUND)
  81. set(LUA_ENGINE LuaJit)
  82. string(APPEND DEPS_INCLUDE_FLAGS " -I${LUAJIT_INCLUDE_DIR}")
  83. elseif(LUA_FOUND)
  84. set(LUA_ENGINE Lua)
  85. string(APPEND DEPS_INCLUDE_FLAGS " -I${LUA_INCLUDE_DIR}")
  86. else()
  87. message(FATAL_ERROR "Could not find system lua or luajit")
  88. endif()
  89. endif()
  90. if(USE_BUNDLED_UNIBILIUM)
  91. include(BuildUnibilium)
  92. endif()
  93. if(USE_BUNDLED_LIBUV)
  94. include(BuildLibuv)
  95. endif()
  96. if(USE_BUNDLED_LUAJIT)
  97. include(BuildLuajit)
  98. endif()
  99. if(USE_BUNDLED_LUA)
  100. include(BuildLua)
  101. endif()
  102. if(USE_BUNDLED_LUV)
  103. include(BuildLuv)
  104. endif()
  105. if(USE_BUNDLED_LPEG)
  106. include(BuildLpeg)
  107. endif()
  108. if(USE_BUNDLED_GETTEXT)
  109. include(BuildGettext)
  110. endif()
  111. if(USE_BUNDLED_LIBICONV)
  112. include(BuildLibiconv)
  113. endif()
  114. if(USE_BUNDLED_TS_PARSERS)
  115. include(BuildTreesitterParsers)
  116. endif()
  117. if(USE_BUNDLED_WASMTIME)
  118. include(BuildWasmtime)
  119. endif()
  120. if(USE_BUNDLED_TS)
  121. include(BuildTreesitter)
  122. endif()
  123. if(USE_BUNDLED_UTF8PROC)
  124. include(BuildUTF8proc)
  125. endif()
  126. if(WIN32)
  127. include(GetBinaryDeps)
  128. GetExecutable(TARGET cat)
  129. GetExecutable(TARGET tee)
  130. GetExecutable(TARGET xxd)
  131. GetBinaryDep(TARGET win32yank_X86_64
  132. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy win32yank.exe ${DEPS_BIN_DIR})
  133. endif()