2017-12-27 11:30:23 -07:00
|
|
|
# CMAKE REFERENCE
|
|
|
|
# intro: https://codingnest.com/basic-cmake/
|
|
|
|
# best practices (3.0+): https://gist.github.com/mbinna/c61dbb39bca0e4fb7d1f73b0d66a4fd1
|
2022-10-09 05:21:52 -07:00
|
|
|
# pitfalls: https://izzys.casa/2019/02/everything-you-never-wanted-to-know-about-cmake/
|
2017-12-27 11:30:23 -07:00
|
|
|
|
2021-10-19 19:19:33 -07:00
|
|
|
# Version should match the tested CMAKE_URL in .github/workflows/ci.yml.
|
|
|
|
cmake_minimum_required(VERSION 3.10)
|
2022-11-12 05:34:14 -07:00
|
|
|
|
|
|
|
# Can be removed once minimum version is at least 3.15
|
|
|
|
if(POLICY CMP0092)
|
|
|
|
cmake_policy(SET CMP0092 NEW)
|
|
|
|
endif()
|
|
|
|
|
2018-06-15 05:33:07 -07:00
|
|
|
project(nvim C)
|
2014-01-31 06:39:15 -07:00
|
|
|
|
2022-03-03 04:20:21 -07:00
|
|
|
if(POLICY CMP0075)
|
|
|
|
cmake_policy(SET CMP0075 NEW)
|
|
|
|
endif()
|
2019-10-01 18:44:57 -07:00
|
|
|
|
2014-02-24 13:54:45 -07:00
|
|
|
# Point CMake at any custom modules we may ship
|
2014-11-10 17:26:01 -07:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
2014-02-24 13:54:45 -07:00
|
|
|
|
2023-01-10 10:49:57 -07:00
|
|
|
include(CheckCCompilerFlag)
|
|
|
|
include(CheckCSourceCompiles)
|
|
|
|
include(InstallHelpers)
|
|
|
|
include(LuaHelpers) # Find Lua interpreter
|
2016-10-11 15:35:02 -07:00
|
|
|
include(PreventInTreeBuilds)
|
2022-06-30 05:10:05 -07:00
|
|
|
include(Util)
|
|
|
|
|
|
|
|
set(TOUCHES_DIR ${PROJECT_BINARY_DIR}/touches)
|
2016-10-11 15:35:02 -07:00
|
|
|
|
2018-06-17 05:54:39 -07:00
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
|
|
|
2023-01-29 09:02:34 -07:00
|
|
|
find_program(CCACHE_PRG ccache)
|
|
|
|
if(CCACHE_PRG)
|
|
|
|
set(CMAKE_C_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E env CCACHE_SLOPPINESS=pch_defines,time_macros ${CCACHE_PRG})
|
|
|
|
endif()
|
|
|
|
|
2014-03-03 08:09:06 -07:00
|
|
|
# Prefer our bundled versions of dependencies.
|
2018-03-11 05:15:42 -07:00
|
|
|
if(DEFINED ENV{DEPS_BUILD_DIR})
|
2021-06-13 11:03:47 -07:00
|
|
|
if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
|
|
|
|
# pkg-config 29.2 has a bug on OpenBSD which causes it to drop any paths that
|
|
|
|
# *contain* system include paths. To avoid this, we prefix what would be
|
|
|
|
# "/usr/include" as "/_usr/include".
|
2022-06-27 03:08:59 -07:00
|
|
|
# This check is also performed in the cmake.deps/CMakeLists.txt and in the
|
2021-06-13 11:03:47 -07:00
|
|
|
# else clause following here.
|
|
|
|
# https://github.com/neovim/neovim/pull/14745#issuecomment-860201794
|
|
|
|
set(DEPS_PREFIX "$ENV{DEPS_BUILD_DIR}/_usr" CACHE PATH "Path prefix for finding dependencies")
|
|
|
|
else()
|
|
|
|
set(DEPS_PREFIX "$ENV{DEPS_BUILD_DIR}/usr" CACHE PATH "Path prefix for finding dependencies")
|
|
|
|
endif()
|
2018-03-11 05:15:42 -07:00
|
|
|
else()
|
2021-06-13 11:03:47 -07:00
|
|
|
if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
|
|
|
|
set(DEPS_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/.deps/_usr" CACHE PATH "Path prefix for finding dependencies")
|
|
|
|
else()
|
|
|
|
set(DEPS_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/.deps/usr" CACHE PATH "Path prefix for finding dependencies")
|
|
|
|
endif()
|
2018-06-10 07:57:12 -07:00
|
|
|
# When running from within CLion or Visual Studio,
|
|
|
|
# build bundled dependencies automatically.
|
|
|
|
if(NOT EXISTS ${DEPS_PREFIX}
|
|
|
|
AND (DEFINED ENV{CLION_IDE}
|
|
|
|
OR DEFINED ENV{VisualStudioEdition}))
|
|
|
|
message(STATUS "Building dependencies...")
|
|
|
|
set(DEPS_BUILD_DIR ${PROJECT_BINARY_DIR}/.deps)
|
|
|
|
file(MAKE_DIRECTORY ${DEPS_BUILD_DIR})
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR}
|
|
|
|
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
|
|
|
|
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
|
|
|
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
|
|
|
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
|
|
|
|
-DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
|
|
|
|
-DCMAKE_C_FLAGS_MINSIZEREL=${CMAKE_C_FLAGS_MINSIZEREL}
|
|
|
|
-DCMAKE_C_FLAGS_RELWITHDEBINFO=${CMAKE_C_FLAGS_RELWITHDEBINFO}
|
|
|
|
-DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}
|
|
|
|
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
|
2022-06-27 03:08:59 -07:00
|
|
|
${PROJECT_SOURCE_DIR}/cmake.deps
|
2018-06-10 07:57:12 -07:00
|
|
|
WORKING_DIRECTORY ${DEPS_BUILD_DIR})
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_COMMAND} --build ${DEPS_BUILD_DIR}
|
|
|
|
--config ${CMAKE_BUILD_TYPE})
|
|
|
|
set(DEPS_PREFIX ${DEPS_BUILD_DIR}/usr)
|
|
|
|
endif()
|
2018-03-11 05:15:42 -07:00
|
|
|
endif()
|
2018-06-10 07:57:12 -07:00
|
|
|
|
2022-06-12 15:11:14 -07:00
|
|
|
list(INSERT CMAKE_PREFIX_PATH 0 ${DEPS_PREFIX})
|
|
|
|
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${DEPS_PREFIX}/lib/pkgconfig")
|
2014-03-03 08:09:06 -07:00
|
|
|
|
2014-11-08 14:16:39 -07:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
2022-07-19 07:10:59 -07:00
|
|
|
# If the macOS deployment target is not set manually (via $MACOSX_DEPLOYMENT_TARGET),
|
|
|
|
# fall back to local system version. Needs to be done both here and in cmake.deps.
|
|
|
|
if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
|
|
|
|
execute_process(COMMAND sw_vers -productVersion
|
|
|
|
OUTPUT_VARIABLE MACOS_VERSION
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "${MACOS_VERSION}")
|
|
|
|
endif()
|
2023-01-10 10:49:57 -07:00
|
|
|
message(STATUS "Using deployment target ${CMAKE_OSX_DEPLOYMENT_TARGET}")
|
2017-01-17 08:32:41 -07:00
|
|
|
endif()
|
2015-03-26 20:30:45 -07:00
|
|
|
|
2017-01-17 08:32:41 -07:00
|
|
|
if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
2021-02-23 21:54:12 -07:00
|
|
|
# Ignore case when comparing filenames on Windows and Mac.
|
|
|
|
set(CASE_INSENSITIVE_FILENAME TRUE)
|
2017-01-17 08:32:41 -07:00
|
|
|
# Enable fixing case-insensitive filenames for Windows and Mac.
|
2015-03-26 20:30:45 -07:00
|
|
|
set(USE_FNAME_CASE TRUE)
|
2014-11-08 14:16:39 -07:00
|
|
|
endif()
|
|
|
|
|
2022-05-17 06:08:24 -07:00
|
|
|
if (MINGW)
|
|
|
|
# Disable LTO by default as it may not compile
|
|
|
|
# See https://github.com/Alexpux/MINGW-packages/issues/3516
|
|
|
|
# and https://github.com/neovim/neovim/pull/8654#issuecomment-402316672
|
|
|
|
option(ENABLE_LTO "enable link time optimization" OFF)
|
|
|
|
else()
|
|
|
|
option(ENABLE_LTO "enable link time optimization" ON)
|
|
|
|
endif()
|
2018-06-01 11:17:24 -07:00
|
|
|
|
2019-02-15 13:18:16 -07:00
|
|
|
message(STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")
|
|
|
|
|
2022-09-06 07:52:39 -07:00
|
|
|
set_default_buildtype()
|
2019-02-15 13:18:16 -07:00
|
|
|
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
|
|
|
set(DEBUG 1)
|
|
|
|
else()
|
|
|
|
set(DEBUG 0)
|
2014-11-09 05:52:15 -07:00
|
|
|
endif()
|
2015-12-19 20:58:47 -07:00
|
|
|
|
2015-12-13 10:29:02 -07:00
|
|
|
# If not in a git repo (e.g., a tarball) these tokens define the complete
|
2016-10-26 06:20:00 -07:00
|
|
|
# version string, else they are combined with the result of `git describe`.
|
2014-10-04 15:32:47 -07:00
|
|
|
set(NVIM_VERSION_MAJOR 0)
|
2022-09-30 08:26:25 -07:00
|
|
|
set(NVIM_VERSION_MINOR 9)
|
2018-12-30 16:44:49 -07:00
|
|
|
set(NVIM_VERSION_PATCH 0)
|
2022-09-30 08:26:25 -07:00
|
|
|
set(NVIM_VERSION_PRERELEASE "-dev") # for package maintainers
|
2015-09-28 03:17:19 -07:00
|
|
|
|
2016-10-26 06:20:00 -07:00
|
|
|
# API level
|
2022-05-02 12:10:01 -07:00
|
|
|
set(NVIM_API_LEVEL 11) # Bump this after any API change.
|
2016-10-26 06:20:00 -07:00
|
|
|
set(NVIM_API_LEVEL_COMPAT 0) # Adjust this after a _breaking_ API change.
|
2022-05-02 12:10:01 -07:00
|
|
|
set(NVIM_API_PRERELEASE true)
|
api: Nvim version, API level #5386
The API level is disconnected from the NVIM version. The API metadata
holds the current API level, and the lowest backwards-compatible level
supported by this instance.
Release 0.1.6 will be the first release reporting the Nvim version and
API level.
metadata['version'] = {
major: 0,
minor: 1,
patch: 6,
prerelease: true,
api_level: 1,
api_compatible: 0,
}
The API level may remain unchanged across Neovim releases if the API has
not changed.
When changing the API the CMake variable NVIM_API_PRERELEASE is set to
true, and NVIM_API_CURRENT/NVIM_API_COMPATIBILITY are incremented
accordingly.
The functional tests check the API table against fixtures of past
versions of Neovim. It compares all the functions in the old table with
the new one, it does ignore some metadata attributes that do not alter
the function signature or were removed since 0.1.5. Currently the only
fixture is 0.mpack, generated from Neovim 0.1.5 with nvim --api-info.
2016-09-25 10:46:37 -07:00
|
|
|
|
2014-11-09 05:52:15 -07:00
|
|
|
set(NVIM_VERSION_BUILD_TYPE "${CMAKE_BUILD_TYPE}")
|
|
|
|
# NVIM_VERSION_CFLAGS set further below.
|
2014-01-31 06:39:15 -07:00
|
|
|
|
2019-02-15 13:18:16 -07:00
|
|
|
# Log level (MIN_LOG_LEVEL in log.h)
|
|
|
|
if("${MIN_LOG_LEVEL}" MATCHES "^$")
|
2019-12-02 09:12:51 -07:00
|
|
|
# Minimize logging for release-type builds.
|
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Release"
|
|
|
|
OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"
|
|
|
|
OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
|
|
|
|
message(STATUS "MIN_LOG_LEVEL not specified, default is 3 (ERROR) for release builds")
|
|
|
|
set(MIN_LOG_LEVEL 3)
|
|
|
|
else()
|
|
|
|
message(STATUS "MIN_LOG_LEVEL not specified, default is 1 (INFO)")
|
|
|
|
set(MIN_LOG_LEVEL 1)
|
|
|
|
endif()
|
2019-02-15 13:18:16 -07:00
|
|
|
else()
|
|
|
|
if(NOT MIN_LOG_LEVEL MATCHES "^[0-3]$")
|
|
|
|
message(FATAL_ERROR "invalid MIN_LOG_LEVEL: " ${MIN_LOG_LEVEL})
|
|
|
|
endif()
|
|
|
|
message(STATUS "MIN_LOG_LEVEL=${MIN_LOG_LEVEL}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Default to -O2 on release builds.
|
|
|
|
if(CMAKE_C_FLAGS_RELEASE MATCHES "-O3")
|
|
|
|
message(STATUS "Replacing -O3 in CMAKE_C_FLAGS_RELEASE with -O2")
|
|
|
|
string(REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
|
|
|
|
endif()
|
|
|
|
|
2022-08-26 05:30:55 -07:00
|
|
|
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
|
2017-06-29 00:29:40 -07:00
|
|
|
check_c_compiler_flag(-Og HAS_OG_FLAG)
|
|
|
|
else()
|
|
|
|
set(HAS_OG_FLAG 0)
|
2015-09-28 03:14:38 -07:00
|
|
|
endif()
|
|
|
|
|
2017-10-20 17:30:21 -07:00
|
|
|
#
|
|
|
|
# Build-type: RelWithDebInfo
|
|
|
|
#
|
2017-06-29 00:29:40 -07:00
|
|
|
if(HAS_OG_FLAG)
|
2017-10-20 17:30:21 -07:00
|
|
|
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -Og -g")
|
|
|
|
endif()
|
|
|
|
# We _want_ assertions in RelWithDebInfo build-type.
|
|
|
|
if(CMAKE_C_FLAGS_RELWITHDEBINFO MATCHES DNDEBUG)
|
2017-06-29 00:29:40 -07:00
|
|
|
string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
|
2015-09-28 03:14:38 -07:00
|
|
|
endif()
|
|
|
|
|
2017-02-11 17:02:54 -07:00
|
|
|
# gcc 4.0+ sets _FORTIFY_SOURCE=2 automatically. This currently
|
2014-11-04 15:06:18 -07:00
|
|
|
# does not work with Neovim due to some uses of dynamically-sized structures.
|
2017-02-11 17:02:54 -07:00
|
|
|
# https://github.com/neovim/neovim/issues/223
|
2014-12-16 04:02:42 -07:00
|
|
|
|
|
|
|
# Include the build type's default flags in the check for _FORTIFY_SOURCE,
|
|
|
|
# otherwise we may incorrectly identify the level as acceptable and find out
|
|
|
|
# later that it was not when optimizations were enabled. CFLAGS is applied
|
|
|
|
# even though you don't see it in CMAKE_REQUIRED_FLAGS.
|
|
|
|
set(INIT_FLAGS_NAME CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE})
|
|
|
|
string(TOUPPER ${INIT_FLAGS_NAME} INIT_FLAGS_NAME)
|
|
|
|
if(${INIT_FLAGS_NAME})
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${${INIT_FLAGS_NAME}}")
|
|
|
|
endif()
|
|
|
|
|
2018-01-02 18:25:42 -07:00
|
|
|
option(LOG_LIST_ACTIONS "Add list actions logging" OFF)
|
|
|
|
|
2015-06-09 01:43:22 -07:00
|
|
|
option(CLANG_ASAN_UBSAN "Enable Clang address & undefined behavior sanitizer for nvim binary." OFF)
|
2015-06-08 09:49:23 -07:00
|
|
|
option(CLANG_MSAN "Enable Clang memory sanitizer for nvim binary." OFF)
|
2015-06-09 01:43:22 -07:00
|
|
|
option(CLANG_TSAN "Enable Clang thread sanitizer for nvim binary." OFF)
|
|
|
|
|
|
|
|
if((CLANG_ASAN_UBSAN AND CLANG_MSAN)
|
|
|
|
OR (CLANG_ASAN_UBSAN AND CLANG_TSAN)
|
|
|
|
OR (CLANG_MSAN AND CLANG_TSAN))
|
2018-10-06 09:45:34 -07:00
|
|
|
message(FATAL_ERROR "Sanitizers cannot be enabled simultaneously")
|
2015-06-08 09:49:23 -07:00
|
|
|
endif()
|
2015-06-09 01:43:22 -07:00
|
|
|
|
|
|
|
if((CLANG_ASAN_UBSAN OR CLANG_MSAN OR CLANG_TSAN) AND NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
|
2018-10-06 09:45:34 -07:00
|
|
|
message(FATAL_ERROR "Sanitizers are only supported for Clang")
|
2015-04-12 07:40:08 -07:00
|
|
|
endif()
|
|
|
|
|
2016-01-08 19:40:57 -07:00
|
|
|
# Place targets in bin/ or lib/ for all build configurations
|
2014-03-03 08:09:06 -07:00
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
2014-11-30 19:22:46 -07:00
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
|
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
2016-01-08 19:40:57 -07:00
|
|
|
foreach(CFGNAME ${CMAKE_CONFIGURATION_TYPES})
|
|
|
|
string(TOUPPER ${CFGNAME} CFGNAME)
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CFGNAME} ${CMAKE_BINARY_DIR}/bin)
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CFGNAME} ${CMAKE_BINARY_DIR}/lib)
|
|
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CFGNAME} ${CMAKE_BINARY_DIR}/lib)
|
|
|
|
endforeach()
|
2014-02-22 08:30:50 -07:00
|
|
|
|
2016-04-13 05:21:32 -07:00
|
|
|
set(LUA_DEPENDENCIES lpeg mpack bit)
|
2014-07-11 04:12:18 -07:00
|
|
|
if(NOT LUA_PRG)
|
2016-06-03 09:21:29 -07:00
|
|
|
foreach(CURRENT_LUA_PRG luajit lua5.1 lua5.2 lua)
|
2019-10-07 08:42:40 -07:00
|
|
|
unset(_CHECK_LUA_PRG CACHE)
|
2014-07-11 04:12:18 -07:00
|
|
|
unset(LUA_PRG_WORKS)
|
2019-10-07 08:42:40 -07:00
|
|
|
find_program(_CHECK_LUA_PRG ${CURRENT_LUA_PRG})
|
2014-07-11 04:12:18 -07:00
|
|
|
|
2019-10-07 08:42:40 -07:00
|
|
|
if(_CHECK_LUA_PRG)
|
|
|
|
check_lua_deps(${_CHECK_LUA_PRG} "${LUA_DEPENDENCIES}" LUA_PRG_WORKS)
|
2014-07-11 04:12:18 -07:00
|
|
|
if(LUA_PRG_WORKS)
|
2019-10-07 08:42:40 -07:00
|
|
|
set(LUA_PRG "${_CHECK_LUA_PRG}" CACHE FILEPATH "Path to a program.")
|
2014-07-11 04:12:18 -07:00
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-10-07 08:42:40 -07:00
|
|
|
unset(_CHECK_LUA_PRG CACHE)
|
2014-07-11 04:12:18 -07:00
|
|
|
else()
|
|
|
|
check_lua_deps(${LUA_PRG} "${LUA_DEPENDENCIES}" LUA_PRG_WORKS)
|
|
|
|
endif()
|
2014-04-13 03:06:35 -07:00
|
|
|
|
2014-07-11 04:12:10 -07:00
|
|
|
if(NOT LUA_PRG_WORKS)
|
2018-10-06 09:45:34 -07:00
|
|
|
message(FATAL_ERROR "Failed to find a Lua 5.1-compatible interpreter")
|
2014-04-13 03:06:35 -07:00
|
|
|
endif()
|
|
|
|
|
2018-10-06 09:45:34 -07:00
|
|
|
message(STATUS "Using Lua interpreter: ${LUA_PRG}")
|
2014-04-13 03:06:35 -07:00
|
|
|
|
2023-01-23 02:26:46 -07:00
|
|
|
# Some of the code generation still relies on stable table ordering in order to
|
|
|
|
# produce reproducible output - specifically the msgpack'ed data in
|
|
|
|
# funcs_metadata.generated.h and ui_events_metadata.generated.h. This should
|
|
|
|
# ideally be fixed in the generators, but until then as a workaround you may provide
|
|
|
|
# a specific lua implementation that provides the needed stability by setting LUA_GEN_PRG:
|
|
|
|
if(NOT LUA_GEN_PRG)
|
|
|
|
set(LUA_GEN_PRG "${LUA_PRG}" CACHE FILEPATH "Path to the lua used for code generation.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
message(STATUS "Using Lua interpreter for code generation: ${LUA_GEN_PRG}")
|
|
|
|
|
2022-06-25 10:24:48 -07:00
|
|
|
option(COMPILE_LUA "Pre-compile Lua sources into bytecode (for sources that are included in the binary)" ON)
|
2021-12-19 14:00:53 -07:00
|
|
|
|
|
|
|
if(COMPILE_LUA AND NOT WIN32)
|
2021-12-16 09:27:39 -07:00
|
|
|
if(PREFER_LUA)
|
|
|
|
foreach(CURRENT_LUAC_PRG luac5.1 luac)
|
|
|
|
find_program(_CHECK_LUAC_PRG ${CURRENT_LUAC_PRG})
|
|
|
|
if(_CHECK_LUAC_PRG)
|
|
|
|
set(LUAC_PRG "${_CHECK_LUAC_PRG} -s -o - %s" CACHE STRING "Format for compiling to Lua bytecode")
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
elseif(LUA_PRG MATCHES "luajit")
|
2021-12-18 20:59:02 -07:00
|
|
|
check_lua_module(${LUA_PRG} "jit.bcsave" LUAJIT_HAS_JIT_BCSAVE)
|
|
|
|
if(LUAJIT_HAS_JIT_BCSAVE)
|
|
|
|
set(LUAC_PRG "${LUA_PRG} -b -s %s -" CACHE STRING "Format for compiling to Lua bytecode")
|
|
|
|
endif()
|
2021-12-16 09:27:39 -07:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(LUAC_PRG)
|
|
|
|
message(STATUS "Using Lua compiler: ${LUAC_PRG}")
|
|
|
|
endif()
|
|
|
|
|
2022-06-12 15:08:01 -07:00
|
|
|
#
|
|
|
|
# Lint
|
|
|
|
#
|
|
|
|
find_program(LUACHECK_PRG luacheck)
|
|
|
|
find_program(STYLUA_PRG stylua)
|
|
|
|
find_program(UNCRUSTIFY_PRG uncrustify)
|
|
|
|
find_program(SHELLCHECK_PRG shellcheck)
|
2022-06-30 05:10:05 -07:00
|
|
|
|
2022-11-01 06:29:17 -07:00
|
|
|
add_glob_target(
|
2022-06-30 05:10:05 -07:00
|
|
|
REQUIRED
|
|
|
|
TARGET lintlua-luacheck
|
|
|
|
COMMAND ${LUACHECK_PRG}
|
|
|
|
FLAGS -q
|
|
|
|
GLOB_DIRS runtime/ scripts/ src/ test/
|
|
|
|
GLOB_PAT *.lua
|
2023-01-13 16:48:10 -07:00
|
|
|
TOUCH_STRATEGY SINGLE)
|
2022-06-30 05:10:05 -07:00
|
|
|
|
2022-11-01 06:29:17 -07:00
|
|
|
add_glob_target(
|
2022-06-30 05:10:05 -07:00
|
|
|
TARGET lintlua-stylua
|
|
|
|
COMMAND ${STYLUA_PRG}
|
|
|
|
FLAGS --color=always --check
|
|
|
|
GLOB_DIRS runtime/
|
|
|
|
GLOB_PAT *.lua
|
2023-01-13 16:48:10 -07:00
|
|
|
TOUCH_STRATEGY SINGLE)
|
2022-06-30 05:10:05 -07:00
|
|
|
|
|
|
|
add_custom_target(lintlua)
|
|
|
|
add_dependencies(lintlua lintlua-luacheck lintlua-stylua)
|
2022-06-12 15:08:01 -07:00
|
|
|
|
2022-11-01 06:29:17 -07:00
|
|
|
add_glob_target(
|
2022-06-30 05:10:05 -07:00
|
|
|
TARGET lintsh
|
|
|
|
COMMAND ${SHELLCHECK_PRG}
|
2022-10-30 05:50:41 -07:00
|
|
|
FLAGS -x -a
|
|
|
|
GLOB_DIRS scripts ci
|
|
|
|
GLOB_PAT *.sh
|
|
|
|
EXCLUDE
|
|
|
|
scripts/pvscheck.sh
|
|
|
|
ci/common
|
|
|
|
ci/snap
|
2023-01-13 16:48:10 -07:00
|
|
|
TOUCH_STRATEGY SINGLE)
|
build: install with the correct permissions
The install() command will create the parent directories, but it does so
with the user's umask. We want to do our best to make sure the correct
permissions are being set, without clobbering existing permissions.
To do this, this commit introduces an install_helper(), which is similar
in signature to the install() command, to help ensure that directories
are created ahead of the actual install() command. This will attempt to
use 0644 permissions for files and 0755 permissions for directories by
default--though they can be overridden.
To make this work correctly, without trying to introduce some mechanism
with setting the umask, it meant that there's a small portion that makes
use of an "internal" version of the file() command. It has been tested
on CMake 2.8.11, 2.8.12, and 3.0.2, and works correctly on all versions.
This fixes #1201 and #1086.
2014-09-19 04:37:22 -07:00
|
|
|
|
2022-07-01 09:15:04 -07:00
|
|
|
add_custom_target(lintcommit
|
|
|
|
COMMAND ${PROJECT_BINARY_DIR}/bin/nvim -u NONE -es -c [[lua require('scripts.lintcommit').main({trace=false})]]
|
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
VERBATIM)
|
|
|
|
add_dependencies(lintcommit nvim)
|
|
|
|
|
|
|
|
add_custom_target(lint)
|
2023-01-13 16:48:10 -07:00
|
|
|
add_dependencies(lint check-single-includes lintc lintlua lintsh lintcommit)
|
2022-07-01 09:15:04 -07:00
|
|
|
|
2022-08-02 03:32:57 -07:00
|
|
|
#
|
|
|
|
# Format
|
|
|
|
#
|
|
|
|
add_custom_target(formatlua
|
|
|
|
COMMAND ${CMAKE_COMMAND}
|
|
|
|
-D FORMAT_PRG=${STYLUA_PRG}
|
|
|
|
-D LANG=lua
|
|
|
|
-P ${PROJECT_SOURCE_DIR}/cmake/Format.cmake
|
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
|
|
|
|
|
|
|
add_custom_target(format)
|
|
|
|
add_dependencies(format formatc formatlua)
|
|
|
|
|
2015-05-17 11:45:30 -07:00
|
|
|
install_helper(
|
2022-06-27 01:02:02 -07:00
|
|
|
FILES ${CMAKE_SOURCE_DIR}/src/man/nvim.1
|
2015-05-17 11:45:30 -07:00
|
|
|
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
|
|
|
|
|
2019-02-15 13:18:16 -07:00
|
|
|
#
|
build: install with the correct permissions
The install() command will create the parent directories, but it does so
with the user's umask. We want to do our best to make sure the correct
permissions are being set, without clobbering existing permissions.
To do this, this commit introduces an install_helper(), which is similar
in signature to the install() command, to help ensure that directories
are created ahead of the actual install() command. This will attempt to
use 0644 permissions for files and 0755 permissions for directories by
default--though they can be overridden.
To make this work correctly, without trying to introduce some mechanism
with setting the umask, it meant that there's a small portion that makes
use of an "internal" version of the file() command. It has been tested
on CMake 2.8.11, 2.8.12, and 3.0.2, and works correctly on all versions.
This fixes #1201 and #1086.
2014-09-19 04:37:22 -07:00
|
|
|
# Go down the tree.
|
2019-02-15 13:18:16 -07:00
|
|
|
#
|
2014-03-03 08:09:06 -07:00
|
|
|
|
build: install with the correct permissions
The install() command will create the parent directories, but it does so
with the user's umask. We want to do our best to make sure the correct
permissions are being set, without clobbering existing permissions.
To do this, this commit introduces an install_helper(), which is similar
in signature to the install() command, to help ensure that directories
are created ahead of the actual install() command. This will attempt to
use 0644 permissions for files and 0755 permissions for directories by
default--though they can be overridden.
To make this work correctly, without trying to introduce some mechanism
with setting the umask, it meant that there's a small portion that makes
use of an "internal" version of the file() command. It has been tested
on CMake 2.8.11, 2.8.12, and 3.0.2, and works correctly on all versions.
This fixes #1201 and #1086.
2014-09-19 04:37:22 -07:00
|
|
|
add_subdirectory(src/nvim)
|
2019-09-06 11:36:05 -07:00
|
|
|
get_directory_property(NVIM_VERSION_CFLAGS DIRECTORY src/nvim DEFINITION NVIM_VERSION_CFLAGS)
|
2022-06-27 03:08:59 -07:00
|
|
|
add_subdirectory(cmake.config)
|
2017-02-11 17:02:54 -07:00
|
|
|
add_subdirectory(test/functional/fixtures) # compile test programs
|
2015-04-02 09:45:34 -07:00
|
|
|
add_subdirectory(runtime)
|
2019-08-28 13:47:54 -07:00
|
|
|
get_directory_property(GENERATED_HELP_TAGS DIRECTORY runtime DEFINITION GENERATED_HELP_TAGS)
|
2018-05-19 23:27:52 -07:00
|
|
|
if(WIN32)
|
|
|
|
install_helper(
|
|
|
|
FILES ${DEPS_PREFIX}/share/nvim-qt/runtime/plugin/nvim_gui_shim.vim
|
|
|
|
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/nvim-qt/runtime/plugin)
|
|
|
|
endif()
|
2015-02-23 08:34:20 -07:00
|
|
|
|
2023-01-10 10:49:57 -07:00
|
|
|
# Setup busted.
|
|
|
|
find_program(BUSTED_PRG NAMES busted busted.bat)
|
|
|
|
find_program(BUSTED_LUA_PRG busted-lua)
|
|
|
|
if(NOT BUSTED_OUTPUT_TYPE)
|
|
|
|
set(BUSTED_OUTPUT_TYPE "nvim")
|
|
|
|
endif()
|
|
|
|
|
build: install with the correct permissions
The install() command will create the parent directories, but it does so
with the user's umask. We want to do our best to make sure the correct
permissions are being set, without clobbering existing permissions.
To do this, this commit introduces an install_helper(), which is similar
in signature to the install() command, to help ensure that directories
are created ahead of the actual install() command. This will attempt to
use 0644 permissions for files and 0755 permissions for directories by
default--though they can be overridden.
To make this work correctly, without trying to introduce some mechanism
with setting the umask, it meant that there's a small portion that makes
use of an "internal" version of the file() command. It has been tested
on CMake 2.8.11, 2.8.12, and 3.0.2, and works correctly on all versions.
This fixes #1201 and #1086.
2014-09-19 04:37:22 -07:00
|
|
|
# Setup some test-related bits. We do this after going down the tree because we
|
|
|
|
# need some of the targets.
|
2014-03-22 04:14:55 -07:00
|
|
|
if(BUSTED_PRG)
|
2023-01-10 10:49:57 -07:00
|
|
|
get_target_property(TEST_INCLUDE_DIRS main_lib INTERFACE_INCLUDE_DIRECTORIES)
|
2016-05-16 03:49:32 -07:00
|
|
|
|
2023-01-23 16:03:25 -07:00
|
|
|
set(UNITTEST_PREREQS nvim-test)
|
2022-06-22 05:51:52 -07:00
|
|
|
set(FUNCTIONALTEST_PREREQS nvim printenv-test printargs-test shell-test pwsh-test streams-test tty-test ${GENERATED_HELP_TAGS})
|
2015-05-08 03:07:56 -07:00
|
|
|
set(BENCHMARK_PREREQS nvim tty-test)
|
|
|
|
|
2016-05-07 19:06:46 -07:00
|
|
|
check_lua_module(${LUA_PRG} "ffi" LUA_HAS_FFI)
|
|
|
|
if(LUA_HAS_FFI)
|
|
|
|
add_custom_target(unittest
|
|
|
|
COMMAND ${CMAKE_COMMAND}
|
|
|
|
-DBUSTED_PRG=${BUSTED_PRG}
|
|
|
|
-DLUA_PRG=${LUA_PRG}
|
|
|
|
-DWORKING_DIR=${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
-DBUSTED_OUTPUT_TYPE=${BUSTED_OUTPUT_TYPE}
|
|
|
|
-DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test
|
|
|
|
-DBUILD_DIR=${CMAKE_BINARY_DIR}
|
|
|
|
-DTEST_TYPE=unit
|
2022-10-17 08:16:31 -07:00
|
|
|
-DCIRRUS_CI=$ENV{CIRRUS_CI}
|
2016-05-07 19:06:46 -07:00
|
|
|
-P ${PROJECT_SOURCE_DIR}/cmake/RunTests.cmake
|
|
|
|
DEPENDS ${UNITTEST_PREREQS}
|
2023-01-10 10:49:57 -07:00
|
|
|
USES_TERMINAL)
|
2018-06-17 05:54:39 -07:00
|
|
|
set_target_properties(unittest PROPERTIES FOLDER test)
|
2016-05-07 19:06:46 -07:00
|
|
|
else()
|
2017-02-11 17:02:54 -07:00
|
|
|
message(WARNING "disabling unit tests: no Luajit FFI in ${LUA_PRG}")
|
2016-05-07 19:06:46 -07:00
|
|
|
endif()
|
2014-09-29 05:43:52 -07:00
|
|
|
|
2018-06-16 07:20:25 -07:00
|
|
|
if(LUA_HAS_FFI)
|
|
|
|
set(TEST_LIBNVIM_PATH $<TARGET_FILE:nvim-test>)
|
2018-02-01 11:12:49 -07:00
|
|
|
else()
|
2018-06-16 07:20:25 -07:00
|
|
|
set(TEST_LIBNVIM_PATH "")
|
2018-02-01 11:12:49 -07:00
|
|
|
endif()
|
2018-06-16 07:20:25 -07:00
|
|
|
configure_file(
|
2022-06-27 03:08:59 -07:00
|
|
|
${CMAKE_SOURCE_DIR}/test/cmakeconfig/paths.lua.in
|
|
|
|
${CMAKE_BINARY_DIR}/test/cmakeconfig/paths.lua.gen)
|
2018-06-16 07:20:25 -07:00
|
|
|
file(GENERATE
|
2022-06-27 03:08:59 -07:00
|
|
|
OUTPUT ${CMAKE_BINARY_DIR}/test/cmakeconfig/paths.lua
|
|
|
|
INPUT ${CMAKE_BINARY_DIR}/test/cmakeconfig/paths.lua.gen)
|
2018-02-01 11:12:49 -07:00
|
|
|
|
2014-11-05 03:54:20 -07:00
|
|
|
add_custom_target(functionaltest
|
2014-09-29 05:43:52 -07:00
|
|
|
COMMAND ${CMAKE_COMMAND}
|
2014-10-08 08:56:28 -07:00
|
|
|
-DBUSTED_PRG=${BUSTED_PRG}
|
2016-07-13 00:37:50 -07:00
|
|
|
-DLUA_PRG=${LUA_PRG}
|
2014-11-05 05:26:35 -07:00
|
|
|
-DNVIM_PRG=$<TARGET_FILE:nvim>
|
2014-09-29 05:43:52 -07:00
|
|
|
-DWORKING_DIR=${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
-DBUSTED_OUTPUT_TYPE=${BUSTED_OUTPUT_TYPE}
|
|
|
|
-DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test
|
|
|
|
-DBUILD_DIR=${CMAKE_BINARY_DIR}
|
|
|
|
-DTEST_TYPE=functional
|
2022-10-17 08:16:31 -07:00
|
|
|
-DCIRRUS_CI=$ENV{CIRRUS_CI}
|
2014-11-10 17:26:01 -07:00
|
|
|
-P ${PROJECT_SOURCE_DIR}/cmake/RunTests.cmake
|
2016-05-16 03:49:32 -07:00
|
|
|
DEPENDS ${FUNCTIONALTEST_PREREQS}
|
2023-01-10 10:49:57 -07:00
|
|
|
USES_TERMINAL)
|
2022-06-17 00:58:48 -07:00
|
|
|
set_target_properties(functionaltest PROPERTIES FOLDER test)
|
2015-03-28 14:28:37 -07:00
|
|
|
|
|
|
|
add_custom_target(benchmark
|
|
|
|
COMMAND ${CMAKE_COMMAND}
|
|
|
|
-DBUSTED_PRG=${BUSTED_PRG}
|
2016-07-13 00:37:50 -07:00
|
|
|
-DLUA_PRG=${LUA_PRG}
|
2015-03-28 14:28:37 -07:00
|
|
|
-DNVIM_PRG=$<TARGET_FILE:nvim>
|
|
|
|
-DWORKING_DIR=${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
-DBUSTED_OUTPUT_TYPE=${BUSTED_OUTPUT_TYPE}
|
|
|
|
-DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test
|
|
|
|
-DBUILD_DIR=${CMAKE_BINARY_DIR}
|
|
|
|
-DTEST_TYPE=benchmark
|
2022-10-17 08:16:31 -07:00
|
|
|
-DCIRRUS_CI=$ENV{CIRRUS_CI}
|
2015-03-28 14:28:37 -07:00
|
|
|
-P ${PROJECT_SOURCE_DIR}/cmake/RunTests.cmake
|
2016-05-16 03:49:32 -07:00
|
|
|
DEPENDS ${BENCHMARK_PREREQS}
|
2023-01-10 10:49:57 -07:00
|
|
|
USES_TERMINAL)
|
2022-06-17 00:58:48 -07:00
|
|
|
set_target_properties(benchmark PROPERTIES FOLDER test)
|
2014-03-22 04:14:55 -07:00
|
|
|
endif()
|
2015-11-17 05:16:33 -07:00
|
|
|
|
2016-03-06 20:42:49 -07:00
|
|
|
if(BUSTED_LUA_PRG)
|
|
|
|
add_custom_target(functionaltest-lua
|
|
|
|
COMMAND ${CMAKE_COMMAND}
|
|
|
|
-DBUSTED_PRG=${BUSTED_LUA_PRG}
|
2016-07-13 00:37:50 -07:00
|
|
|
-DLUA_PRG=${LUA_PRG}
|
2016-03-06 20:42:49 -07:00
|
|
|
-DNVIM_PRG=$<TARGET_FILE:nvim>
|
|
|
|
-DWORKING_DIR=${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
-DBUSTED_OUTPUT_TYPE=${BUSTED_OUTPUT_TYPE}
|
|
|
|
-DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test
|
|
|
|
-DBUILD_DIR=${CMAKE_BINARY_DIR}
|
|
|
|
-DTEST_TYPE=functional
|
2022-10-17 08:16:31 -07:00
|
|
|
-DCIRRUS_CI=$ENV{CIRRUS_CI}
|
2016-03-06 20:42:49 -07:00
|
|
|
-P ${PROJECT_SOURCE_DIR}/cmake/RunTests.cmake
|
2016-05-16 03:49:32 -07:00
|
|
|
DEPENDS ${FUNCTIONALTEST_PREREQS}
|
2023-01-10 10:49:57 -07:00
|
|
|
USES_TERMINAL)
|
2018-06-17 05:54:39 -07:00
|
|
|
set_target_properties(functionaltest-lua PROPERTIES FOLDER test)
|
2016-03-06 20:42:49 -07:00
|
|
|
endif()
|
|
|
|
|
2022-06-17 05:11:08 -07:00
|
|
|
add_custom_target(uninstall
|
|
|
|
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/UninstallHelper.cmake)
|
2022-02-07 13:49:09 -07:00
|
|
|
|
|
|
|
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
2022-06-27 03:08:59 -07:00
|
|
|
add_subdirectory(cmake.packaging)
|
2022-02-07 13:49:09 -07:00
|
|
|
endif()
|