robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 9a29622b3b00ddb601

master
4.7 KiB170 linesraw
1# This is not meant to be included by the top-level.
2cmake_minimum_required(VERSION 3.16)
3project(NVIM_DEPS C)
4
5if(POLICY CMP0135)
6  cmake_policy(SET CMP0135 NEW)
7endif()
8
9# Point CMake at any custom modules we may ship
10list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${PROJECT_SOURCE_DIR}/../cmake")
11
12include(CheckCCompilerFlag)
13include(ExternalProject)
14include(FindPackageHandleStandardArgs)
15
16include(Deps)
17include(Find)
18include(Util)
19
20#-------------------------------------------------------------------------------
21# User settings
22#-------------------------------------------------------------------------------
23
24if(NOT DEPS_IGNORE_SHA)
25  set(DEPS_IGNORE_SHA FALSE)
26endif()
27
28# Options
29option(USE_BUNDLED "Use bundled dependencies." ON)
30
31option(USE_BUNDLED_LIBUV "Use the bundled libuv." ${USE_BUNDLED})
32# PUC Lua is only used for tests, unless explicitly requested.
33option(USE_BUNDLED_LUA "Use the bundled version of lua." OFF)
34option(USE_BUNDLED_LUAJIT "Use the bundled version of luajit." ${USE_BUNDLED})
35option(USE_BUNDLED_LUV "Use the bundled version of luv." ${USE_BUNDLED})
36option(USE_BUNDLED_TS "Use the bundled treesitter runtime." ${USE_BUNDLED})
37option(USE_BUNDLED_TS_PARSERS "Use the bundled treesitter parsers." ${USE_BUNDLED})
38option(USE_BUNDLED_UNIBILIUM "Use the bundled unibilium." ${USE_BUNDLED})
39option(USE_BUNDLED_UTF8PROC "Use the bundled utf8proc library." ${USE_BUNDLED})
40
41if(USE_BUNDLED AND MSVC)
42  option(USE_BUNDLED_GETTEXT "Use the bundled version of gettext." ON)
43  option(USE_BUNDLED_LIBICONV "Use the bundled version of libiconv." ON)
44else()
45  option(USE_BUNDLED_GETTEXT "Use the bundled version of gettext." OFF)
46  option(USE_BUNDLED_LIBICONV "Use the bundled version of libiconv." OFF)
47endif()
48
49option(ENABLE_WASMTIME "Use treesitter with wasmtime support." OFF)
50if(ENABLE_WASMTIME)
51  if(USE_BUNDLED)
52    option(USE_BUNDLED_WASMTIME "Use the bundled wasmtime." ON)
53  else()
54    option(USE_BUNDLED_WASMTIME "Use the bundled wasmtime." OFF)
55  endif()
56endif()
57if(NOT ENABLE_WASMTIME AND USE_BUNDLED_WASMTIME)
58  message(FATAL_ERROR "ENABLE_WASMTIME is set to OFF while USE_BUNDLED_WASMTIME is set to ON.\
59  You need set ENABLE_WASMTIME to ON if you want to use wasmtime.")
60endif()
61
62option(USE_EXISTING_SRC_DIR "Skip download of deps sources in case of existing source directory." OFF)
63
64set_default_buildtype(Release)
65get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
66
67if (NOT DEFINED DEPS_CMAKE_ARGS)
68  set(DEPS_CMAKE_ARGS)
69endif()
70
71if(NOT isMultiConfig)
72  list(APPEND DEPS_CMAKE_ARGS -D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
73endif()
74
75set(DEFAULT_MAKE_CFLAGS CFLAGS+=-g)
76
77check_c_compiler_flag(-Og HAS_OG_FLAG)
78if(HAS_OG_FLAG)
79  set(DEFAULT_MAKE_CFLAGS CFLAGS+=-Og ${DEFAULT_MAKE_CFLAGS})
80endif()
81
82# Always pass the toolchain if it exists
83if(CMAKE_TOOLCHAIN_FILE)
84  list(APPEND DEPS_CMAKE_ARGS
85    -D CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
86  )
87endif()
88
89set(DEPS_INCLUDE_FLAGS "-I\"${DEPS_INSTALL_DIR}/include\" -I\"${DEPS_INSTALL_DIR}/include/luajit-2.1\"")
90
91# If the macOS deployment target is not set manually (via $MACOSX_DEPLOYMENT_TARGET),
92# fall back to local system version. Needs to be done here and in top-level CMakeLists.txt.
93if(APPLE)
94  if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
95    execute_process(COMMAND sw_vers -productVersion
96                    OUTPUT_VARIABLE MACOS_VERSION
97                    OUTPUT_STRIP_TRAILING_WHITESPACE)
98    set(CMAKE_OSX_DEPLOYMENT_TARGET "${MACOS_VERSION}")
99  endif()
100  message(STATUS "Using deployment target ${CMAKE_OSX_DEPLOYMENT_TARGET}")
101endif()
102
103if(USE_BUNDLED_LUAJIT)
104  set(LUA_ENGINE LuaJit)
105elseif(USE_BUNDLED_LUA)
106  set(LUA_ENGINE Lua)
107else()
108  find_package(Luajit)
109  find_package(Lua 5.1 EXACT)
110  if(LUAJIT_FOUND)
111    set(LUA_ENGINE LuaJit)
112    string(APPEND DEPS_INCLUDE_FLAGS " -I\"${LUAJIT_INCLUDE_DIR}\"")
113  elseif(LUA_FOUND)
114    set(LUA_ENGINE Lua)
115    string(APPEND DEPS_INCLUDE_FLAGS " -I\"${LUA_INCLUDE_DIR}\"")
116  else()
117    message(FATAL_ERROR "Could not find system lua or luajit")
118  endif()
119endif()
120
121if(USE_BUNDLED_UNIBILIUM)
122  include(BuildUnibilium)
123endif()
124
125if(USE_BUNDLED_LIBUV)
126  include(BuildLibuv)
127endif()
128
129if(USE_BUNDLED_LUAJIT)
130  include(BuildLuajit)
131endif()
132
133if(USE_BUNDLED_LUA)
134  include(BuildLua)
135endif()
136
137if(USE_BUNDLED_LUV)
138  include(BuildLuv)
139endif()
140
141if(USE_BUNDLED_GETTEXT)
142  include(BuildGettext)
143endif()
144
145if(USE_BUNDLED_LIBICONV)
146  include(BuildLibiconv)
147endif()
148
149if(USE_BUNDLED_TS_PARSERS)
150  include(BuildTreesitterParsers)
151endif()
152
153if(USE_BUNDLED_WASMTIME)
154  include(BuildWasmtime)
155endif()
156
157if(USE_BUNDLED_TS)
158  include(BuildTreesitter)
159endif()
160
161if(USE_BUNDLED_UTF8PROC)
162  include(BuildUTF8proc)
163endif()
164
165if(WIN32)
166  include(GetBinaryDeps)
167
168  GetBinaryDep(TARGET win32yank_X86_64
169    INSTALL_COMMAND ${CMAKE_COMMAND} -E copy win32yank.exe ${DEPS_BIN_DIR})
170endif()