From 6e3a69b4cf5c526443b96cf857847d6c3b0586d8 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 6 Sep 2022 16:52:39 +0200 Subject: build: consistently set build type regardless of generator or platform #19760 Change the default build type to always be Debug, and allow only four predefined build types: Debug, Release, RelWithDebInfo and MinRelSize. Furthermore, flags meant for single-configuration generator (make, ninja) will not be used for multi-configuration generators (visual studio, Xcode), and flags meant for multi-configuration generators will not be used for single-configuration generators. This will allow Debug builds to be built with MSVC which requires that all dependencies are also built with the Debug build type to avoid runtime library mismatch. The correct way to specify build type (for example Release) for single-configuration generators (Make and Ninja) is to run cmake -B build -D CMAKE_BUILD_TYPE=Release cmake --build build while for multi-configuration generators (Visual Studio, Xcode and Ninja Multi-Config) is to run cmake -B build cmake --build build --config Release Passing CMAKE_BUILD_TYPE for multi-config generators will now not only not be used, but also generate a warning for the user. Co-authored-by: dundargoc --- cmake/Util.cmake | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'cmake') diff --git a/cmake/Util.cmake b/cmake/Util.cmake index b485f4606b..343a729305 100644 --- a/cmake/Util.cmake +++ b/cmake/Util.cmake @@ -143,3 +143,43 @@ function(add_glob_targets) add_custom_target(${ARG_TARGET} DEPENDS ${touch_list}) endfunction() + +# Set default build type to Debug. Also limit the list of allowable build types +# to the ones defined in variable allowableBuildTypes. +# +# The correct way to specify build type (for example Release) for +# single-configuration generators (Make and Ninja) is to run +# +# cmake -B build -D CMAKE_BUILD_TYPE=Release +# cmake --build build +# +# while for multi-configuration generators (Visual Studio, Xcode and Ninja +# Multi-Config) is to run +# +# cmake -B build +# cmake --build build --config Release +# +# Passing CMAKE_BUILD_TYPE for multi-config generators will now not only +# not be used, but also generate a warning for the user. +function(set_default_buildtype) + set(allowableBuildTypes Debug Release MinSizeRel RelWithDebInfo) + + get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(isMultiConfig) + set(CMAKE_CONFIGURATION_TYPES ${allowableBuildTypes} PARENT_SCOPE) + if(CMAKE_BUILD_TYPE) + message(WARNING "CMAKE_BUILD_TYPE specified which is ignored on \ + multi-configuration generators. Defaulting to Debug build type.") + endif() + else() + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowableBuildTypes}") + if(NOT CMAKE_BUILD_TYPE) + message(STATUS "CMAKE_BUILD_TYPE not specified, default is 'Debug'") + set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build" FORCE) + elseif(NOT CMAKE_BUILD_TYPE IN_LIST allowableBuildTypes) + message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}") + else() + message(STATUS "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") + endif() + endif() +endfunction() -- cgit From 42aeb5c5b18af1362362a2e6bdf10a2a4ec70f0f Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 9 Aug 2022 17:02:51 +0200 Subject: build: remove unnecessary policy related code Having cmake version 3.10 as the required minimum version ensures these are set to new by default. --- cmake/RunTests.cmake | 5 ----- 1 file changed, 5 deletions(-) (limited to 'cmake') diff --git a/cmake/RunTests.cmake b/cmake/RunTests.cmake index e07c6dd174..86ce22de72 100644 --- a/cmake/RunTests.cmake +++ b/cmake/RunTests.cmake @@ -1,11 +1,6 @@ # Set LC_ALL to meet expectations of some locale-sensitive tests. set(ENV{LC_ALL} "en_US.UTF-8") -if(POLICY CMP0012) - # Handle CI=true, without dev warnings. - cmake_policy(SET CMP0012 NEW) -endif() - set(ENV{VIMRUNTIME} ${WORKING_DIR}/runtime) set(ENV{NVIM_RPLUGIN_MANIFEST} ${BUILD_DIR}/Xtest_rplugin_manifest) set(ENV{XDG_CONFIG_HOME} ${BUILD_DIR}/Xtest_xdg/config) -- cgit From 2a1c65b330c1cf65207cdd992529ad3bb1a197a4 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 10 Sep 2022 14:37:11 +0200 Subject: build: ensure version generation always succeeds (#19515) Add --always flag to `git describe` so version generation succeeds if current directory is in a git repo. If not in git repo, fall back to a default version in the format vx.y.z-dev --- cmake/GenerateVersion.cmake | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'cmake') diff --git a/cmake/GenerateVersion.cmake b/cmake/GenerateVersion.cmake index 6118d8cba7..a7a72fe0bb 100644 --- a/cmake/GenerateVersion.cmake +++ b/cmake/GenerateVersion.cmake @@ -7,15 +7,11 @@ set(NVIM_VERSION_MEDIUM "v${NVIM_VERSION_MAJOR}.${NVIM_VERSION_MINOR}.${NVIM_VERSION_PATCH}${NVIM_VERSION_PRERELEASE}") execute_process( - COMMAND git describe --first-parent --dirty + COMMAND git describe --first-parent --dirty --always OUTPUT_VARIABLE GIT_TAG - ERROR_VARIABLE ERR - RESULT_VARIABLE RES -) + RESULT_VARIABLE RES) -if(NOT RES EQUAL 0) - message(STATUS "Git tag extraction failed:\n" " ${GIT_TAG}${ERR}" ) - # This will only be executed once since the file will get generated afterwards. +if(RES AND NOT RES EQUAL 0) message(STATUS "Using NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}") file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}") return() -- cgit From 600136cfb641be450900f8b7a1bfdc4fbcb69856 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 23 Sep 2022 16:16:17 +0200 Subject: revert: "build: remove unnecessary policy related code" #20289 This partially reverts commit 42aeb5c5b18af1362362a2e6bdf10a2a4ec70f0f. Setting cmake policies is normally not required as cmake_minimum_required automatically sets these. One exception is cmake script mode (-P) since it automatically resets all policy changes. Closes: https://github.com/neovim/neovim/issues/20286 --- cmake/RunTests.cmake | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'cmake') diff --git a/cmake/RunTests.cmake b/cmake/RunTests.cmake index 86ce22de72..2abe29b54b 100644 --- a/cmake/RunTests.cmake +++ b/cmake/RunTests.cmake @@ -1,6 +1,13 @@ # Set LC_ALL to meet expectations of some locale-sensitive tests. set(ENV{LC_ALL} "en_US.UTF-8") +if(POLICY CMP0012) + # Avoid policy warning due to CI=true. This is needed even if the main + # project has already set this policy as policy settings are reset when using + # the cmake script mode (-P). + cmake_policy(SET CMP0012 NEW) +endif() + set(ENV{VIMRUNTIME} ${WORKING_DIR}/runtime) set(ENV{NVIM_RPLUGIN_MANIFEST} ${BUILD_DIR}/Xtest_rplugin_manifest) set(ENV{XDG_CONFIG_HOME} ${BUILD_DIR}/Xtest_xdg/config) -- cgit From 06addcfaa956d5cffeba10ff9e41c4e8e2a33d1d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 11 Sep 2022 13:39:49 +0200 Subject: build: remove unused variable CMAKE_C_COMPILER_ARG1 It was set in file cmake/i386-linux-gnu.toolchain.cmake which has been removed since we don't use Travis anymore. --- cmake/GetCompileFlags.cmake | 8 -------- 1 file changed, 8 deletions(-) (limited to 'cmake') diff --git a/cmake/GetCompileFlags.cmake b/cmake/GetCompileFlags.cmake index 49b57f6f75..3b027690f8 100644 --- a/cmake/GetCompileFlags.cmake +++ b/cmake/GetCompileFlags.cmake @@ -2,14 +2,6 @@ function(get_compile_flags _compile_flags) # Create template akin to CMAKE_C_COMPILE_OBJECT. set(compile_flags " ") - # Get C compiler. - if(CMAKE_C_COMPILER_ARG1) - string(REPLACE - "" - " ${CMAKE_C_COMPILER_ARG1}" - compile_flags - "${compile_flags}") - endif() string(REPLACE "" "${CMAKE_C_COMPILER}" -- cgit From 913651d1f102eed11db9046fdec72e84958a7c6a Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 26 Sep 2022 11:39:31 +0200 Subject: build: remove unnecessary translation-related code The commands run in cmake script mode (-P) can simply be run in the main cmake run instead. --- cmake/RunMsgfmt.cmake | 9 --------- cmake/RunMsgmerge.cmake | 11 ----------- cmake/RunXgettext.cmake | 14 -------------- 3 files changed, 34 deletions(-) delete mode 100644 cmake/RunMsgfmt.cmake delete mode 100644 cmake/RunMsgmerge.cmake delete mode 100644 cmake/RunXgettext.cmake (limited to 'cmake') diff --git a/cmake/RunMsgfmt.cmake b/cmake/RunMsgfmt.cmake deleted file mode 100644 index 51606338e0..0000000000 --- a/cmake/RunMsgfmt.cmake +++ /dev/null @@ -1,9 +0,0 @@ -set(ENV{OLD_PO_FILE_INPUT} yes) - -execute_process( - COMMAND ${MSGFMT_PRG} -o ${MO_FILE} ${PO_FILE} - ERROR_VARIABLE err - RESULT_VARIABLE res) -if(NOT res EQUAL 0) - message(FATAL_ERROR "msgfmt failed to run correctly: ${err}") -endif() diff --git a/cmake/RunMsgmerge.cmake b/cmake/RunMsgmerge.cmake deleted file mode 100644 index 69e5c7276d..0000000000 --- a/cmake/RunMsgmerge.cmake +++ /dev/null @@ -1,11 +0,0 @@ -set(ENV{OLD_PO_FILE_INPUT} yes) -set(ENV{OLD_PO_FILE_OUTPUT} yes) - -execute_process( - COMMAND ${MSGMERGE_PRG} -q --update --backup=none --sort-by-file - ${PO_FILE} ${POT_FILE} - ERROR_VARIABLE err - RESULT_VARIABLE res) -if(NOT res EQUAL 0) - message(FATAL_ERROR "msgmerge failed to run correctly: ${err}") -endif() diff --git a/cmake/RunXgettext.cmake b/cmake/RunXgettext.cmake deleted file mode 100644 index c9328b151d..0000000000 --- a/cmake/RunXgettext.cmake +++ /dev/null @@ -1,14 +0,0 @@ -set(ENV{OLD_PO_FILE_INPUT} yes) -set(ENV{OLD_PO_FILE_OUTPUT} yes) - -list(SORT SOURCES) - -execute_process( - COMMAND ${XGETTEXT_PRG} -o ${POT_FILE} --default-domain=nvim - --add-comments --keyword=_ --keyword=N_ -D ${SEARCH_DIR} - ${SOURCES} - ERROR_VARIABLE err - RESULT_VARIABLE res) -if(NOT res EQUAL 0) - message(FATAL_ERROR "xgettext failed to run correctly: ${err}") -endif() -- cgit From 5046b4b4adb154bbdb50a5e96e29f777b5f807ac Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 17 Oct 2022 17:16:31 +0200 Subject: ci: add cirrus to isCI function to skip tests (#20526) The environment variable CIRRUS_CI is manually passed to RunTests.cmake as it doesn't get passed when using cmake script mode. --- cmake/RunTests.cmake | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'cmake') diff --git a/cmake/RunTests.cmake b/cmake/RunTests.cmake index 2abe29b54b..c3ac5f208e 100644 --- a/cmake/RunTests.cmake +++ b/cmake/RunTests.cmake @@ -3,8 +3,8 @@ set(ENV{LC_ALL} "en_US.UTF-8") if(POLICY CMP0012) # Avoid policy warning due to CI=true. This is needed even if the main - # project has already set this policy as policy settings are reset when using - # the cmake script mode (-P). + # project has already set this policy as project settings aren't inherited + # when using cmake script mode (-P). cmake_policy(SET CMP0012 NEW) endif() @@ -15,6 +15,12 @@ set(ENV{XDG_DATA_HOME} ${BUILD_DIR}/Xtest_xdg/share) unset(ENV{XDG_DATA_DIRS}) unset(ENV{NVIM}) # Clear $NVIM in case tests are running from Nvim. #11009 +# TODO(dundargoc): The CIRRUS_CI environment variable isn't passed to here from +# the main CMakeLists.txt, so we have to manually pass it to this script and +# re-set the environment variable. Investigate if we can avoid manually setting +# it like with the GITHUB_CI environment variable. +set(ENV{CIRRUS_CI} ${CIRRUS_CI}) + if(NOT DEFINED ENV{NVIM_LOG_FILE}) set(ENV{NVIM_LOG_FILE} ${BUILD_DIR}/.nvimlog) endif() -- cgit From e33995e936c57064bf5629f6b527bfc1b77f77f8 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Thu, 20 Oct 2022 13:03:41 +0200 Subject: fix(build): duplicate version string "v0.8.0-v0.8.0" #20578 - Prevent duplicate version strings such as v0.8.0-v0.8.0. - Change the format for git releases from v0.9.0-dev-67-g625ba79be to v0.9.0-dev-67+g625ba79be. Nvim versions are now: release : v0.9.0 prerelease without git info: v0.9.0-dev prerelease with git info : v0.9.0-dev-67+g625ba79be --- cmake/GenerateVersion.cmake | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'cmake') diff --git a/cmake/GenerateVersion.cmake b/cmake/GenerateVersion.cmake index a7a72fe0bb..d2a711fdf9 100644 --- a/cmake/GenerateVersion.cmake +++ b/cmake/GenerateVersion.cmake @@ -1,26 +1,27 @@ -if(NVIM_VERSION_MEDIUM) - message(STATUS "USING NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}") - return() -endif() - -set(NVIM_VERSION_MEDIUM +set(NVIM_VERSION "v${NVIM_VERSION_MAJOR}.${NVIM_VERSION_MINOR}.${NVIM_VERSION_PATCH}${NVIM_VERSION_PRERELEASE}") execute_process( COMMAND git describe --first-parent --dirty --always OUTPUT_VARIABLE GIT_TAG + OUTPUT_STRIP_TRAILING_WHITESPACE RESULT_VARIABLE RES) if(RES AND NOT RES EQUAL 0) - message(STATUS "Using NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}") - file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}") + message(STATUS "Using NVIM_VERSION: ${NVIM_VERSION}") + file(WRITE "${OUTPUT}" "") return() endif() -string(STRIP "${GIT_TAG}" GIT_TAG) -string(REGEX REPLACE "^v[0-9]+.[0-9]+.[0-9]+-" "" NVIM_VERSION_GIT "${GIT_TAG}") -set(NVIM_VERSION_MEDIUM "${NVIM_VERSION_MEDIUM}-${NVIM_VERSION_GIT}") -set(NVIM_VERSION_STRING "#define NVIM_VERSION_MEDIUM \"${NVIM_VERSION_MEDIUM}\"\n") +# `git describe` annotates the most recent tagged release; for pre-release +# builds we append that to the dev version. +if(NVIM_VERSION_PRERELEASE) + string(REGEX REPLACE "^v[0-9]+.[0-9]+.[0-9]+-" "" NVIM_VERSION_GIT "${GIT_TAG}") + string(REGEX REPLACE "^([0-9]+)-([a-z0-9]+)" "\\1+\\2" NVIM_VERSION_GIT "${NVIM_VERSION_GIT}") + set(NVIM_VERSION "${NVIM_VERSION}-${NVIM_VERSION_GIT}") +endif() + +set(NVIM_VERSION_STRING "#define NVIM_VERSION_MEDIUM \"${NVIM_VERSION}\"\n") string(SHA1 CURRENT_VERSION_HASH "${NVIM_VERSION_STRING}") if(EXISTS ${OUTPUT}) @@ -28,6 +29,6 @@ if(EXISTS ${OUTPUT}) endif() if(NOT "${NVIM_VERSION_HASH}" STREQUAL "${CURRENT_VERSION_HASH}") - message(STATUS "Using NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}") + message(STATUS "Using NVIM_VERSION: ${NVIM_VERSION}") file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}") endif() -- cgit From 45c8679493c628353f6672e940c9ae4fd27dfe84 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 21 Oct 2022 11:57:10 +0200 Subject: build: give example on complex regexes This is just to allow the reader to get a quick understanding without necessarily needing to know all the regex intricasies. --- cmake/GenerateVersion.cmake | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cmake') diff --git a/cmake/GenerateVersion.cmake b/cmake/GenerateVersion.cmake index d2a711fdf9..7ce6ee430e 100644 --- a/cmake/GenerateVersion.cmake +++ b/cmake/GenerateVersion.cmake @@ -16,7 +16,9 @@ endif() # `git describe` annotates the most recent tagged release; for pre-release # builds we append that to the dev version. if(NVIM_VERSION_PRERELEASE) + # Extract pre-release info: "v0.8.0-145-g0f9113907" => "145-g0f9113907" string(REGEX REPLACE "^v[0-9]+.[0-9]+.[0-9]+-" "" NVIM_VERSION_GIT "${GIT_TAG}") + # Replace "-" with "+": "145-g0f9113907" => "145+g0f9113907" string(REGEX REPLACE "^([0-9]+)-([a-z0-9]+)" "\\1+\\2" NVIM_VERSION_GIT "${NVIM_VERSION_GIT}") set(NVIM_VERSION "${NVIM_VERSION}-${NVIM_VERSION_GIT}") endif() -- cgit From aeb87f8b4a87e99c392e7ec11b29b715e1f31ac3 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 1 Nov 2022 14:29:17 +0100 Subject: build: add EXCLUDE option to add_glob_target EXCLUDE filters out all elements containing regex, meaning it works on both files and directories. Also rename add_glob_targets to add_glob_target since only one target is being created. --- cmake/Util.cmake | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'cmake') diff --git a/cmake/Util.cmake b/cmake/Util.cmake index 343a729305..a86ced89d6 100644 --- a/cmake/Util.cmake +++ b/cmake/Util.cmake @@ -49,12 +49,13 @@ # simple be added to FILES # GLOB_DIRS - The directories to recursively search for files with extension # GLOB_PAT -# -function(add_glob_targets) +# EXCLUDE - List of paths to skip (regex). Works on both directories and +# files. +function(add_glob_target) cmake_parse_arguments(ARG "REQUIRED" "TARGET;COMMAND;GLOB_PAT;TOUCH_STRATEGY" - "FLAGS;FILES;GLOB_DIRS" + "FLAGS;FILES;GLOB_DIRS;EXCLUDE" ${ARGN} ) @@ -72,7 +73,15 @@ function(add_glob_targets) endif() foreach(gd ${ARG_GLOB_DIRS}) - file(GLOB_RECURSE globfiles ${PROJECT_SOURCE_DIR}/${gd}/${ARG_GLOB_PAT}) + file(GLOB_RECURSE globfiles_unnormalized ${PROJECT_SOURCE_DIR}/${gd}/${ARG_GLOB_PAT}) + set(globfiles) + foreach(f ${globfiles_unnormalized}) + file(TO_CMAKE_PATH "${f}" f) + list(APPEND globfiles ${f}) + endforeach() + foreach(exclude_pattern ${ARG_EXCLUDE}) + list(FILTER globfiles EXCLUDE REGEX ${exclude_pattern}) + endforeach() list(APPEND ARG_FILES ${globfiles}) endforeach() -- cgit From a3f01d32cba903b58e3ab5a353b4dba8c5431f9c Mon Sep 17 00:00:00 2001 From: Jan Palus Date: Fri, 2 Dec 2022 13:45:37 +0100 Subject: build: restrict `git describe` to top level source directory (#20993) fix version determination when building neovim from release tarball extracted within another git repository --- cmake/GenerateVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmake') diff --git a/cmake/GenerateVersion.cmake b/cmake/GenerateVersion.cmake index 7ce6ee430e..8cea39e4de 100644 --- a/cmake/GenerateVersion.cmake +++ b/cmake/GenerateVersion.cmake @@ -2,7 +2,7 @@ set(NVIM_VERSION "v${NVIM_VERSION_MAJOR}.${NVIM_VERSION_MINOR}.${NVIM_VERSION_PATCH}${NVIM_VERSION_PRERELEASE}") execute_process( - COMMAND git describe --first-parent --dirty --always + COMMAND git --git-dir=${NVIM_SOURCE_DIR}/.git --work-tree=${NVIM_SOURCE_DIR} describe --first-parent --dirty --always OUTPUT_VARIABLE GIT_TAG OUTPUT_STRIP_TRAILING_WHITESPACE RESULT_VARIABLE RES) -- cgit From 438b4361cc761a2950689668f008cfe06c1510f7 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 10 Jan 2023 18:49:57 +0100 Subject: build: use modern cmake (#21589) Replace old-school cmake with the so-called "Modern CMake", meaning preferring using targets and properties over directory settings and variables. This allows greater flexibility, robustness and clarity over how the code works. The following deprecated commands will be replaced with their modern alternatives that operates on a specific target, rather than all targets in the current directory: - add_compile_options -> target_compile_options - include_directories -> target_include_directories - link_libraries -> target_link_libraries - add_definitions -> target_compile_definitions There are mainly four main targets that we currently use: nvim, libnvim, nvim-test (used by unittests) and ${texe} (used by check-single-includes). The goal is to explicitly define the dependencies of each target fully, rather than having everything be dependent on everything else. --- cmake/FindIconv.cmake | 3 ++ cmake/GetCompileFlags.cmake | 108 ++++++++++++++++++-------------------------- 2 files changed, 46 insertions(+), 65 deletions(-) (limited to 'cmake') diff --git a/cmake/FindIconv.cmake b/cmake/FindIconv.cmake index 1d0164dae9..63290fe889 100644 --- a/cmake/FindIconv.cmake +++ b/cmake/FindIconv.cmake @@ -1,3 +1,6 @@ +# TODO(dundargoc): FindIconv is shipped by default on cmake version 3.11+. This +# file can be removed once we decide to upgrade minimum cmake version. + # - Try to find iconv # Once done, this will define # diff --git a/cmake/GetCompileFlags.cmake b/cmake/GetCompileFlags.cmake index 3b027690f8..9b3c053871 100644 --- a/cmake/GetCompileFlags.cmake +++ b/cmake/GetCompileFlags.cmake @@ -1,79 +1,57 @@ function(get_compile_flags _compile_flags) - # Create template akin to CMAKE_C_COMPILE_OBJECT. - set(compile_flags " ") + string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type) + set(compile_flags ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${build_type}}) - string(REPLACE - "" - "${CMAKE_C_COMPILER}" - compile_flags - "${compile_flags}") + # Get flags set by target_compile_options(). + get_target_property(opt main_lib INTERFACE_COMPILE_OPTIONS) + if(opt) + list(APPEND compile_flags ${opt}) + endif() - # Get flags set by add_definitions(). - get_property(compile_definitions DIRECTORY PROPERTY COMPILE_DEFINITIONS) - get_target_property(compile_definitions_target nvim COMPILE_DEFINITIONS) - if(compile_definitions_target) - list(APPEND compile_definitions ${compile_definitions_target}) - list(REMOVE_DUPLICATES compile_definitions) + get_target_property(opt nvim COMPILE_OPTIONS) + if(opt) + list(APPEND compile_flags ${opt}) endif() - # NOTE: list(JOIN) requires CMake 3.12, string(CONCAT) requires CMake 3. - string(REPLACE ";" " -D" compile_definitions "${compile_definitions}") - if(compile_definitions) - set(compile_definitions " -D${compile_definitions}") + + # Get flags set by target_compile_definitions(). + get_target_property(defs main_lib INTERFACE_COMPILE_DEFINITIONS) + if(defs) + foreach(def ${defs}) + list(APPEND compile_flags "-D${def}") + endforeach() endif() - string(REPLACE - "" - "${compile_definitions}" - compile_flags - "${compile_flags}") - # Get flags set by add_compile_options(). - get_property(compile_options DIRECTORY PROPERTY COMPILE_OPTIONS) - get_target_property(compile_options_target nvim COMPILE_OPTIONS) - if(compile_options_target) - list(APPEND compile_options ${compile_options_target}) - list(REMOVE_DUPLICATES compile_options) + get_target_property(defs nvim COMPILE_DEFINITIONS) + if(defs) + foreach(def ${defs}) + list(APPEND compile_flags "-D${def}") + endforeach() endif() - # NOTE: list(JOIN) requires CMake 3.12. - string(REPLACE ";" " " compile_options "${compile_options}") - string(REPLACE - "" - "${compile_options}" - compile_flags - "${compile_flags}") - # Get general C flags. - string(REPLACE - "" - "${CMAKE_C_FLAGS}" - compile_flags - "${compile_flags}") + # Get include directories. + get_target_property(dirs main_lib INTERFACE_INCLUDE_DIRECTORIES) + if(dirs) + foreach(dir ${dirs}) + list(APPEND compile_flags "-I${dir}") + endforeach() + endif() - # Get C flags specific to build type. - string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type) - string(REPLACE - "" - "${CMAKE_C_FLAGS_${build_type}}" - compile_flags - "${compile_flags}") + get_target_property(dirs main_lib INTERFACE_SYSTEM_INCLUDE_DIRECTORIES) + if(dirs) + foreach(dir ${dirs}) + list(APPEND compile_flags "-I${dir}") + endforeach() + endif() - # Get include directories. - get_property(include_directories_list DIRECTORY PROPERTY INCLUDE_DIRECTORIES) - list(REMOVE_DUPLICATES include_directories_list) - foreach(include_directory ${include_directories_list}) - set(include_directories "${include_directories} -I${include_directory}") - endforeach() - string(REPLACE - "" - "${include_directories}" - compile_flags - "${compile_flags}") + get_target_property(dirs nvim INCLUDE_DIRECTORIES) + if(dirs) + foreach(dir ${dirs}) + list(APPEND compile_flags "-I${dir}") + endforeach() + endif() - # Clean duplicate whitespace. - string(REPLACE - " " - " " - compile_flags - "${compile_flags}") + list(REMOVE_DUPLICATES compile_flags) + string(REPLACE ";" " " compile_flags "${compile_flags}") set(${_compile_flags} "${compile_flags}" PARENT_SCOPE) endfunction() -- cgit From 9220755302317e8030c5bbf334357c0d64df9fa4 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 14 Jan 2023 00:48:10 +0100 Subject: build: remove clint error suppression #21782 Fix remaining clint errors and remove error suppression completely. Rename the lint targets to align with the established naming convention: - lintc-clint lints with clint.py. - lintc-uncrustify lints with uncrustify. - lintc runs both targets. lintc is also provided as a make target for convenience. After this change we can remove these files: https://github.com/neovim/doc/tree/gh-pages/reports/clint https://github.com/neovim/doc/blob/main/ci/clint-errors.sh --- cmake/Download.cmake | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 cmake/Download.cmake (limited to 'cmake') diff --git a/cmake/Download.cmake b/cmake/Download.cmake deleted file mode 100644 index 50a77816bc..0000000000 --- a/cmake/Download.cmake +++ /dev/null @@ -1,18 +0,0 @@ -file( - DOWNLOAD "${URL}" "${FILE}" - STATUS status - LOG log -) - -list(GET status 0 status_code) -list(GET status 1 status_string) - -if(NOT status_code EQUAL 0) - if(NOT ALLOW_FAILURE) - message(FATAL_ERROR "error: downloading '${URL}' failed - status_code: ${status_code} - status_string: ${status_string} - log: ${log} - ") - endif() -endif() -- cgit From 69c71c4ab44d0bf9fe5f6b6066ad5c269d1507b8 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 15 Jan 2023 19:30:17 +0100 Subject: build: exclude tui/terminfo_defs.h from lintc-clint (#21822) clint takes around 5-10 seconds to lint tui/terminfo_defs.h. For CI this is negligible, but it's annoying for local development as touching terminfo_defs.h will skyrocket lint times. Furthermore, we have no reason to touch or modify terminfo_defs.h as it's a generated file, so linting it shouldn't be necessary. This should speed up "make lint" by the same amount, so around 5-10 seconds. --- cmake/Util.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'cmake') diff --git a/cmake/Util.cmake b/cmake/Util.cmake index a86ced89d6..e15b44d29a 100644 --- a/cmake/Util.cmake +++ b/cmake/Util.cmake @@ -79,12 +79,13 @@ function(add_glob_target) file(TO_CMAKE_PATH "${f}" f) list(APPEND globfiles ${f}) endforeach() - foreach(exclude_pattern ${ARG_EXCLUDE}) - list(FILTER globfiles EXCLUDE REGEX ${exclude_pattern}) - endforeach() list(APPEND ARG_FILES ${globfiles}) endforeach() + foreach(exclude_pattern ${ARG_EXCLUDE}) + list(FILTER ARG_FILES EXCLUDE REGEX ${exclude_pattern}) + endforeach() + if(NOT ARG_TOUCH_STRATEGY) set(ARG_TOUCH_STRATEGY PER_FILE) endif() -- cgit From 7f7b83baef87b049b8779061065046ee161e2d7c Mon Sep 17 00:00:00 2001 From: Enan Ajmain <3nan.ajmain@gmail.com> Date: Wed, 18 Jan 2023 16:48:01 +0600 Subject: build(Windows): fix redoing version generation (#21880) Problem: On Windows, neovim's version is generated every time nvim is built, even if code hasn't been changed. That is because version generation is done based on a hash matching of a file and the content of the file. And in Windows they don't match, because of the DOS line-endings. Solution: Write the file containing nvim version with UNIX line-endings. --- cmake/GenerateVersion.cmake | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cmake') diff --git a/cmake/GenerateVersion.cmake b/cmake/GenerateVersion.cmake index 8cea39e4de..34993d9552 100644 --- a/cmake/GenerateVersion.cmake +++ b/cmake/GenerateVersion.cmake @@ -33,4 +33,7 @@ endif() if(NOT "${NVIM_VERSION_HASH}" STREQUAL "${CURRENT_VERSION_HASH}") message(STATUS "Using NVIM_VERSION: ${NVIM_VERSION}") file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}") + if(WIN32) + configure_file("${OUTPUT}" "${OUTPUT}" NEWLINE_STYLE UNIX) + endif() endif() -- cgit From 4c5c6ca8009dd68a68bc31caef509cb15ebef7ca Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 20 Jan 2023 23:48:46 +0100 Subject: build: various cmake fixes (#21902) * build: various cmake refactors and simplifications - Add STATUS keyword to message to ensure messages are shown in the correct order. - Remove DEPS_CXX_COMPILER as we don't rely on C++ for any of our dependencies. - Simplify how msgpack and luv configure options are constructed. - Rely on the default installation for luv instead of manually passing configure, build and install commands. - Simplify return code conditional. * build: remove CMAKE_OSX_ARCHITECTURES_ALT_SEP workaround CMAKE_OSX_ARCHITECTURES_ALT_SEP was defined as a workaround to prevent the shell from interpreting `;`, which CMake uses as a list separator. However, the same thing can be achieved by instead passing CMAKE_OSX_ARCHITECTURES as a cache variable instead, which is a more idiomatic way of achieving the same thing. * build: define CMAKE_BUILD_TYPE before adding it to BUILD_TYPE_STRING The problem with the current setup is that CMAKE_BUILD_TYPE is defined after BUILD_TYPE_STRING. BUILD_TYPE_STRING will then be empty on the first run, meaning that dependencies are built without a build type. However, since CMAKE_BUILD_TYPE is a cache variable its value will persist in subsequent runs. On the second run BUILD_TYPE_STRING will have the correct value, but it's a different value from the ones the dependencies were built with. This will force some dependencies to be built again. Fixes https://github.com/neovim/neovim/issues/21672. --- cmake/GenerateVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmake') diff --git a/cmake/GenerateVersion.cmake b/cmake/GenerateVersion.cmake index 34993d9552..c092645140 100644 --- a/cmake/GenerateVersion.cmake +++ b/cmake/GenerateVersion.cmake @@ -7,7 +7,7 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE RESULT_VARIABLE RES) -if(RES AND NOT RES EQUAL 0) +if(RES) message(STATUS "Using NVIM_VERSION: ${NVIM_VERSION}") file(WRITE "${OUTPUT}" "") return() -- cgit