diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 18:23:01 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 18:23:01 +0000 |
commit | 142d9041391780ac15b89886a54015fdc5c73995 (patch) | |
tree | 0f6b5cac1a60810a03f52826c9e67c9e2780b033 /cmake | |
parent | ad86b5db74922285699ab2a1dbb2ff20e6268a33 (diff) | |
parent | 3c48d3c83fc21dbc0841f9210f04bdb073d73cd1 (diff) | |
download | rneovim-142d9041391780ac15b89886a54015fdc5c73995.tar.gz rneovim-142d9041391780ac15b89886a54015fdc5c73995.tar.bz2 rneovim-142d9041391780ac15b89886a54015fdc5c73995.zip |
Merge remote-tracking branch 'upstream/master' into userreg
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/Download.cmake | 18 | ||||
-rw-r--r-- | cmake/FindIconv.cmake | 3 | ||||
-rw-r--r-- | cmake/GenerateVersion.cmake | 36 | ||||
-rw-r--r-- | cmake/GetCompileFlags.cmake | 108 | ||||
-rw-r--r-- | cmake/RunTests.cmake | 10 | ||||
-rw-r--r-- | cmake/Util.cmake | 18 |
6 files changed, 89 insertions, 104 deletions
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() 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/GenerateVersion.cmake b/cmake/GenerateVersion.cmake index a7a72fe0bb..c092645140 100644 --- a/cmake/GenerateVersion.cmake +++ b/cmake/GenerateVersion.cmake @@ -1,26 +1,29 @@ -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 + 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) -if(RES AND NOT RES EQUAL 0) - message(STATUS "Using NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}") - file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}") +if(RES) + 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) + # 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() + +set(NVIM_VERSION_STRING "#define NVIM_VERSION_MEDIUM \"${NVIM_VERSION}\"\n") string(SHA1 CURRENT_VERSION_HASH "${NVIM_VERSION_STRING}") if(EXISTS ${OUTPUT}) @@ -28,6 +31,9 @@ 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}") + if(WIN32) + configure_file("${OUTPUT}" "${OUTPUT}" NEWLINE_STYLE UNIX) + endif() endif() 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 "<CMAKE_C_COMPILER> <CFLAGS> <BUILD_TYPE_CFLAGS> <COMPILE_OPTIONS><COMPILE_DEFINITIONS> <INCLUDES>") + 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>" - "${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_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_options}" - compile_flags - "${compile_flags}") - # Get general C flags. - string(REPLACE - "<CFLAGS>" - "${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 - "<BUILD_TYPE_CFLAGS>" - "${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 - "<INCLUDES>" - "${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() 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() diff --git a/cmake/Util.cmake b/cmake/Util.cmake index 343a729305..e15b44d29a 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,10 +73,19 @@ 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() 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() |