diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dedbfd714..81f245e7de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -228,7 +228,7 @@ endif() find_program(SHELLCHECK_PRG shellcheck ${LINT_REQUIRED}) find_program(STYLUA_PRG stylua ${LINT_REQUIRED}) -set(STYLUA_DIRS runtime scripts src test) +set(STYLUA_DIRS runtime scripts src test contrib) add_glob_target( TARGET lintlua-luacheck diff --git a/Makefile b/Makefile index 5c33cdbfa9..bc24c15d78 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ filter-true = $(strip $(filter-out 1 on ON true TRUE,$1)) all: nvim -CMAKE_PRG ?= $(shell (command -v cmake3 || echo cmake)) +CMAKE ?= $(shell (command -v cmake3 || echo cmake)) CMAKE_BUILD_TYPE ?= Debug CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) # Extra CMake flags which extend the default set @@ -28,7 +28,7 @@ override CMAKE_EXTRA_FLAGS += -DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX) checkprefix: @if [ -f build/.ran-cmake ]; then \ - cached_prefix=$(shell $(CMAKE_PRG) -L -N build | 2>/dev/null grep 'CMAKE_INSTALL_PREFIX' | cut -d '=' -f2); \ + cached_prefix=$(shell $(CMAKE) -L -N build | 2>/dev/null grep 'CMAKE_INSTALL_PREFIX' | cut -d '=' -f2); \ if ! [ "$(CMAKE_INSTALL_PREFIX)" = "$$cached_prefix" ]; then \ printf "Re-running CMake: CMAKE_INSTALL_PREFIX '$(CMAKE_INSTALL_PREFIX)' does not match cached value '%s'.\n" "$$cached_prefix"; \ $(RM) build/.ran-cmake; \ @@ -53,17 +53,6 @@ ifeq (,$(BUILD_TOOL)) endif endif -# Only need to handle Ninja here. Make will inherit the VERBOSE variable, and the -j, -l, and -n flags. -ifeq ($(CMAKE_GENERATOR),Ninja) - ifneq ($(VERBOSE),) - BUILD_TOOL += -v - endif - BUILD_TOOL += $(shell printf '%s' '$(MAKEFLAGS)' | grep -o -- ' *-[jl][0-9]\+ *') - ifeq (n,$(findstring n,$(firstword -$(MAKEFLAGS)))) - BUILD_TOOL += -n - endif -endif - DEPS_CMAKE_FLAGS ?= USE_BUNDLED ?= @@ -81,49 +70,48 @@ endif SINGLE_MAKE = export MAKEFLAGS= ; $(MAKE) nvim: build/.ran-cmake deps - +$(BUILD_TOOL) -C build + $(BUILD_TOOL) -C build libnvim: build/.ran-cmake deps - +$(BUILD_TOOL) -C build libnvim + $(BUILD_TOOL) -C build libnvim cmake: touch CMakeLists.txt $(MAKE) build/.ran-cmake build/.ran-cmake: | deps - cd build && $(CMAKE_PRG) -G '$(CMAKE_GENERATOR)' $(CMAKE_FLAGS) $(CMAKE_EXTRA_FLAGS) $(MAKEFILE_DIR) + $(CMAKE) -B build -G '$(CMAKE_GENERATOR)' $(CMAKE_FLAGS) $(CMAKE_EXTRA_FLAGS) $(MAKEFILE_DIR) touch $@ deps: | build/.ran-deps-cmake ifeq ($(call filter-true,$(USE_BUNDLED)),) - +$(BUILD_TOOL) -C $(DEPS_BUILD_DIR) + $(BUILD_TOOL) -C $(DEPS_BUILD_DIR) endif ifeq ($(call filter-true,$(USE_BUNDLED)),) $(DEPS_BUILD_DIR): mkdir -p "$@" build/.ran-deps-cmake:: $(DEPS_BUILD_DIR) - cd $(DEPS_BUILD_DIR) && \ - $(CMAKE_PRG) -G '$(CMAKE_GENERATOR)' $(BUNDLED_CMAKE_FLAG) $(BUNDLED_LUA_CMAKE_FLAG) \ - $(DEPS_CMAKE_FLAGS) $(MAKEFILE_DIR)/cmake.deps + $(CMAKE) -S $(MAKEFILE_DIR)/cmake.deps -B $(DEPS_BUILD_DIR) -G '$(CMAKE_GENERATOR)' \ + $(BUNDLED_CMAKE_FLAG) $(BUNDLED_LUA_CMAKE_FLAG) $(DEPS_CMAKE_FLAGS) endif build/.ran-deps-cmake:: mkdir -p build touch $@ # TODO: cmake 3.2+ add_custom_target() has a USES_TERMINAL flag. -oldtest: | nvim build/runtime/doc/tags - +$(SINGLE_MAKE) -C test/old/testdir clean +oldtest: | nvim + $(SINGLE_MAKE) -C test/old/testdir clean ifeq ($(strip $(TEST_FILE)),) - +$(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) $(MAKEOVERRIDES) + $(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) $(MAKEOVERRIDES) else @# Handle TEST_FILE=test_foo{,.res,.vim}. - +$(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) SCRIPTS= $(MAKEOVERRIDES) $(patsubst %.vim,%,$(patsubst %.res,%,$(TEST_FILE))) + $(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) SCRIPTS= $(MAKEOVERRIDES) $(patsubst %.vim,%,$(patsubst %.res,%,$(TEST_FILE))) endif # Build oldtest by specifying the relative .vim filename. .PHONY: phony_force test/old/testdir/%.vim: phony_force nvim - +$(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) SCRIPTS= $(MAKEOVERRIDES) $(patsubst test/old/testdir/%.vim,%,$@) + $(SINGLE_MAKE) -C test/old/testdir NVIM_PRG=$(NVIM_PRG) SCRIPTS= $(MAKEOVERRIDES) $(patsubst test/old/testdir/%.vim,%,$@) functionaltest-lua: | nvim $(BUILD_TOOL) -C build functionaltest @@ -132,23 +120,23 @@ FORMAT=formatc formatlua format LINT=lintlua lintsh lintc clang-analyzer lintcommit lint TEST=functionaltest unittest generated-sources benchmark $(FORMAT) $(LINT) $(TEST) doc: | build/.ran-cmake - $(CMAKE_PRG) --build build --target $@ + $(CMAKE) --build build --target $@ test: $(TEST) iwyu: build/.ran-cmake - cmake --preset iwyu - cmake --build build > build/iwyu.log + $(CMAKE) --preset iwyu + $(CMAKE) --build build > build/iwyu.log iwyu-fix-includes --only_re="src/nvim" --ignore_re="(src/nvim/eval/encode.c\ |src/nvim/auto/\ |src/nvim/os/lang.c\ |src/nvim/map.c\ )" --nosafe_headers < build/iwyu.log - cmake -B build -U ENABLE_IWYU - cmake --build build + $(CMAKE) -B build -U ENABLE_IWYU + $(CMAKE) --build build clean: - +test -d build && $(BUILD_TOOL) -C build clean || true + test -d build && $(BUILD_TOOL) -C build clean || true $(MAKE) -C test/old/testdir clean $(MAKE) -C runtime/indent clean @@ -157,7 +145,7 @@ distclean: $(MAKE) clean install: checkprefix nvim - +$(BUILD_TOOL) -C build install + $(BUILD_TOOL) -C build install appimage: bash scripts/genappimage.sh diff --git a/cmake.deps/CMakeLists.txt b/cmake.deps/CMakeLists.txt index afc4da8def..e63b964885 100644 --- a/cmake.deps/CMakeLists.txt +++ b/cmake.deps/CMakeLists.txt @@ -87,6 +87,24 @@ foreach(dep ${DEPENDENCIES}) endif() endforeach() +if(USE_BUNDLED_LUAJIT) + set(LUA_ENGINE LuaJit) +elseif(USE_BUNDLED_LUA) + set(LUA_ENGINE Lua) +else() + find_package(Luajit) + find_package(Lua 5.1 EXACT) + if(LUAJIT_FOUND) + set(LUA_ENGINE LuaJit) + string(APPEND DEPS_INCLUDE_FLAGS " -I${LUAJIT_INCLUDE_DIR}") + elseif(LUA_FOUND) + set(LUA_ENGINE Lua) + string(APPEND DEPS_INCLUDE_FLAGS " -I${LUA_INCLUDE_DIR}") + else() + message(FATAL_ERROR "Could not find system lua or luajit") + endif() +endif() + if(USE_BUNDLED_UNIBILIUM) include(BuildUnibilium) endif() diff --git a/cmake.deps/cmake/BuildLpeg.cmake b/cmake.deps/cmake/BuildLpeg.cmake index bba23fe42b..b65baf4c0f 100644 --- a/cmake.deps/cmake/BuildLpeg.cmake +++ b/cmake.deps/cmake/BuildLpeg.cmake @@ -1,19 +1,3 @@ -set(LPEG_INCLUDE_FLAGS ${DEPS_INCLUDE_FLAGS}) - -if(NOT USE_BUNDLED_LUAJIT AND NOT USE_BUNDLED_LUA) - find_package(Luajit) - if(LUAJIT_FOUND) - string(CONCAT LPEG_INCLUDE_FLAGS ${DEPS_INCLUDE_FLAGS} " -I${LUAJIT_INCLUDE_DIR}") - else() - find_package(Lua 5.1 EXACT) - if(LUA_FOUND) - string(CONCAT LPEG_INCLUDE_FLAGS ${DEPS_INCLUDE_FLAGS} " -I${LUA_INCLUDE_DIR}") - endif() - endif() -endif() - -list(APPEND LPEG_CMAKE_ARGS -DCMAKE_C_FLAGS=${LPEG_INCLUDE_FLAGS}) - ExternalProject_Add(lpeg URL ${LPEG_URL} URL_HASH SHA256=${LPEG_SHA256} @@ -21,7 +5,7 @@ ExternalProject_Add(lpeg PATCH_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/cmake/LpegCMakeLists.txt ${DEPS_BUILD_DIR}/src/lpeg/CMakeLists.txt - CMAKE_ARGS ${DEPS_CMAKE_ARGS} ${LPEG_CMAKE_ARGS} + CMAKE_ARGS ${DEPS_CMAKE_ARGS} -DCMAKE_C_FLAGS=${DEPS_INCLUDE_FLAGS} CMAKE_CACHE_ARGS ${DEPS_CMAKE_CACHE_ARGS} ${EXTERNALPROJECT_OPTIONS}) diff --git a/cmake.deps/cmake/BuildLuv.cmake b/cmake.deps/cmake/BuildLuv.cmake index 004fea7790..9830ea717a 100644 --- a/cmake.deps/cmake/BuildLuv.cmake +++ b/cmake.deps/cmake/BuildLuv.cmake @@ -5,18 +5,7 @@ set(LUV_CMAKE_ARGS -D BUILD_STATIC_LIBS=ON -D BUILD_MODULE=OFF) -if(USE_BUNDLED_LUAJIT) - list(APPEND LUV_CMAKE_ARGS -D WITH_LUA_ENGINE=LuaJit) -elseif(USE_BUNDLED_LUA) - list(APPEND LUV_CMAKE_ARGS -D WITH_LUA_ENGINE=Lua) -else() - find_package(Luajit) - if(LUAJIT_FOUND) - list(APPEND LUV_CMAKE_ARGS -D WITH_LUA_ENGINE=LuaJit) - else() - list(APPEND LUV_CMAKE_ARGS -D WITH_LUA_ENGINE=Lua) - endif() -endif() +list(APPEND LUV_CMAKE_ARGS -D WITH_LUA_ENGINE=${LUA_ENGINE}) if(USE_BUNDLED_LIBUV) list(APPEND LUV_CMAKE_ARGS -D CMAKE_PREFIX_PATH=${DEPS_INSTALL_DIR}) diff --git a/cmake/Util.cmake b/cmake/Util.cmake index 4723ad7e08..f44f6cac76 100644 --- a/cmake/Util.cmake +++ b/cmake/Util.cmake @@ -89,7 +89,7 @@ function(add_glob_target) endif() if(ARG_TOUCH_STRATEGY STREQUAL SINGLE) - set(touch_file ${TOUCHES_DIR}/ran-${ARG_TARGET}) + set(touch_file ${TOUCHES_DIR}/${ARG_TARGET}) add_custom_command( OUTPUT ${touch_file} COMMAND ${CMAKE_COMMAND} -E touch ${touch_file} @@ -103,7 +103,7 @@ function(add_glob_target) foreach(f ${ARG_FILES}) string(REGEX REPLACE "^${PROJECT_SOURCE_DIR}/" "" tf ${f}) string(REGEX REPLACE "[/.]" "-" tf ${tf}) - set(touch_file ${touch_dir}/ran-${tf}) + set(touch_file ${touch_dir}/${tf}) add_custom_command( OUTPUT ${touch_file} COMMAND ${CMAKE_COMMAND} -E touch ${touch_file} @@ -133,7 +133,7 @@ function(add_glob_target) file(MAKE_DIRECTORY ${td}) string(REGEX REPLACE "^${PROJECT_SOURCE_DIR}/" "" tf ${touch_dir}) string(REGEX REPLACE "[/.]" "-" tf ${tf}) - set(touch_file ${td}/ran-${tf}) + set(touch_file ${td}/${tf}) add_custom_command( OUTPUT ${touch_file} diff --git a/contrib/minimal.lua b/contrib/minimal.lua index a395b9dcaf..2391e12f68 100644 --- a/contrib/minimal.lua +++ b/contrib/minimal.lua @@ -1,10 +1,10 @@ -- Run this file as `nvim --clean -u minimal.lua` -for name, url in pairs{ +for name, url in pairs { -- ADD PLUGINS _NECESSARY_ TO REPRODUCE THE ISSUE, e.g: -- some_plugin = 'https://github.com/author/plugin.nvim' } do - local install_path = vim.fn.fnamemodify('nvim_issue/'..name, ':p') + local install_path = vim.fn.fnamemodify('nvim_issue/' .. name, ':p') if vim.fn.isdirectory(install_path) == 0 then vim.fn.system { 'git', 'clone', '--depth=1', url, install_path } end diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index c9655ad9b9..0dbf646702 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -33,7 +33,7 @@ foreach(PACKAGE ${PACKAGES}) add_custom_command(OUTPUT "${GENERATED_PACKAGE_DIR}/${PACKNAME}/doc/tags" COMMAND ${CMAKE_COMMAND} -E copy_directory ${PACKAGE} ${GENERATED_PACKAGE_DIR}/${PACKNAME} - COMMAND "${PROJECT_BINARY_DIR}/bin/nvim" + COMMAND $ -u NONE -i NONE -e --headless -c "helptags doc" -c quit DEPENDS nvim_bin @@ -67,7 +67,7 @@ add_custom_command(OUTPUT ${GENERATED_HELP_TAGS} COMMAND ${CMAKE_COMMAND} -E remove_directory doc COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/runtime/doc doc - COMMAND "${PROJECT_BINARY_DIR}/bin/nvim" + COMMAND $ -u NONE -i NONE -e --headless -c "helptags ++t doc" -c quit DEPENDS nvim_bin @@ -77,7 +77,7 @@ add_custom_command(OUTPUT ${GENERATED_HELP_TAGS} # TODO: This doesn't work. wait for "nvim -l" to land? add_custom_target(doc_html - COMMAND "${PROJECT_BINARY_DIR}/bin/nvim" + COMMAND $ -V1 -es --clean -c "lua require('scripts.gen_help_html').gen('./build/runtime/doc', './build/doc_html', nil, 'todo_commit_id')" -c "0cq" DEPENDS ${GENERATED_HELP_TAGS} diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 4f9edad6a8..b1ee3d93db 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -3,12 +3,12 @@ add_library(main_lib INTERFACE) # Internally we need to make a distinction between "nvim without runtime files" # (nvim_bin) and "nvim with runtime files" (nvim). add_executable(nvim_bin EXCLUDE_FROM_ALL) -set_target_properties(nvim_bin PROPERTIES OUTPUT_NAME nvim) set_target_properties(nvim_bin PROPERTIES EXPORT_COMPILE_COMMANDS ON - ENABLE_EXPORTS TRUE) + ENABLE_EXPORTS TRUE + OUTPUT_NAME nvim) #------------------------------------------------------------------------------- # Dependencies diff --git a/src/nvim/po/CMakeLists.txt b/src/nvim/po/CMakeLists.txt index a4c95df3f1..6c2008926a 100644 --- a/src/nvim/po/CMakeLists.txt +++ b/src/nvim/po/CMakeLists.txt @@ -182,6 +182,7 @@ if(HAVE_WORKING_LIBINTL AND GETTEXT_FOUND AND XGETTEXT_PRG AND ICONV_PRG) BuildMo(${LANGUAGE}) endforeach() - add_custom_target(nvim_translations ALL DEPENDS ${LANGUAGE_MO_FILES}) + add_custom_target(nvim_translations DEPENDS ${LANGUAGE_MO_FILES}) add_custom_target(update-po DEPENDS ${UPDATE_PO_TARGETS}) + add_dependencies(nvim nvim_translations) endif()