Home Explore Blog CI



neovim

5th chunk of `CMakeLists.txt`
cf707966f15bbf7d205acc103764c65e3579bd67b0d3995d0000000100000d29
 lintlua-luacheck lintlua-stylua)

add_glob_target(
  TARGET lintsh
  COMMAND ${SHELLCHECK_PRG}
  FLAGS -x -a
  GLOB_DIRS scripts
  GLOB_PAT *.sh
  TOUCH_STRATEGY PER_DIR)

add_custom_target(lintcommit
  COMMAND $<TARGET_FILE:nvim_bin> -u NONE -l ${PROJECT_SOURCE_DIR}/scripts/lintcommit.lua main)
add_dependencies(lintcommit nvim_bin)

add_custom_target(lint)
add_dependencies(lint lintc lintlua lintsh)

# Format
add_glob_target(
  TARGET formatlua
  COMMAND ${STYLUA_PRG}
  FLAGS --respect-ignores
  GLOB_DIRS ${STYLUA_DIRS}
  GLOB_PAT *.lua
  TOUCH_STRATEGY PER_DIR)
# Special handling of some files (which are ignored in .styluaignore).
# Workaround because stylua doesn't(?) support file-specific settings.
add_custom_target(formatlua2
  COMMAND ${STYLUA_PRG} --config-path "${PROJECT_SOURCE_DIR}/.stylua2.toml"
    "${PROJECT_SOURCE_DIR}/test/functional/ui/decorations_spec.lua"
    "${PROJECT_SOURCE_DIR}/test/functional/ui/float_spec.lua"
    "${PROJECT_SOURCE_DIR}/test/functional/ui/multigrid_spec.lua"
)
add_dependencies(formatlua formatlua2)
add_custom_target(format)
add_dependencies(format formatc formatlua)

install_helper(
  FILES ${CMAKE_SOURCE_DIR}/src/man/nvim.1
  DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)

add_custom_target(nvim ALL)
add_dependencies(nvim nvim_bin nvim_runtime_deps nvim_runtime)

add_subdirectory(src/nvim)
add_subdirectory(cmake.config)
add_subdirectory(runtime)
add_subdirectory(test)

add_custom_target(uninstall
  COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/UninstallHelper.cmake)

if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
  add_subdirectory(cmake.packaging)
endif()

get_externalproject_options(uncrustify ${DEPS_IGNORE_SHA})
ExternalProject_Add(uncrustify
  DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/uncrustify
  CMAKE_ARGS ${DEPS_CMAKE_ARGS}
    -D CMAKE_RUNTIME_OUTPUT_DIRECTORY=${DEPS_BIN_DIR}
    -D CMAKE_SKIP_RPATH=true
  EXCLUDE_FROM_ALL TRUE
  ${EXTERNALPROJECT_OPTIONS})

option(USE_BUNDLED_BUSTED "Use bundled busted" ON)
if(USE_BUNDLED_BUSTED)
  get_externalproject_options(lua_dev_deps ${DEPS_IGNORE_SHA})
  ExternalProject_Add(lua_dev_deps
    DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/lua_dev_deps
    SOURCE_DIR ${DEPS_SHARE_DIR}
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ""
    INSTALL_COMMAND ""
    EXCLUDE_FROM_ALL TRUE
    ${EXTERNALPROJECT_OPTIONS})
else()
  add_custom_target(lua_dev_deps)
endif()

if (CMAKE_SYSTEM_PROCESSOR MATCHES arm64)
  set(LUALS_ARCH arm64)
else()
  set(LUALS_ARCH x64)
endif()

set(LUALS_VERSION 3.14.0)
set(LUALS "lua-language-server-${LUALS_VERSION}-${CMAKE_SYSTEM_NAME}-${LUALS_ARCH}")
set(LUALS_TARBALL ${LUALS}.tar.gz)
set(LUALS_URL https://github.com/LuaLS/lua-language-server/releases/download/${LUALS_VERSION}/${LUALS_TARBALL})

ExternalProject_Add(download_luals
  URL ${LUALS_URL}
  DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/luals
  SOURCE_DIR ${DEPS_BIN_DIR}/luals
  CONFIGURE_COMMAND ""
  BUILD_COMMAND ""
  INSTALL_COMMAND ""
  EXCLUDE_FROM_ALL TRUE
  DOWNLOAD_NO_PROGRESS TRUE
  CMAKE_CACHE_ARGS ${DEPS_CMAKE_CACHE_ARGS})

file(GLOB_RECURSE LUAFILES runtime/*.lua)
add_target(luals
  COMMAND ${DEPS_BIN_DIR}/luals/bin/lua-language-server
    --configpath=${PROJECT_SOURCE_DIR}/.luarc.json
    --check=${PROJECT_SOURCE_DIR}/runtime
    --checklevel=Hint
  DEPENDS ${LUAFILES}
  CUSTOM_COMMAND_ARGS USES_TERMINAL)

add_dependencies(luals download_luals)

Title: CMake Configuration - Linting, Formatting, Installation, and External Projects
Summary
This section of the CMake configuration adds targets for shell script linting (`lintsh`) using ShellCheck, commit message linting (`lintcommit`), and a combined `lint` target. It defines targets to format Lua code (`formatlua`, `formatlua2`) using stylua and creates a combined `format` target. It sets up installation of the `nvim.1` man page. It defines `nvim` target which depends on binary, runtime dependencies and runtime. It adds subdirectories for source code, CMake configuration, runtime files, and tests. It creates an uninstall target and adds an optional packaging subdirectory. It configures and adds external projects, including Uncrustify and optionally a set of Lua development dependencies (busted). Finally, it configures and downloads Lua Language Server (Luals) as an external project and adds dependencies.