diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 18:31:31 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 18:31:31 +0000 |
commit | 9243becbedbb6a1592208051f8fa2b090dcc5e7d (patch) | |
tree | 607c2a862ec3f4399b8766383f6f8e04c4aa43b4 /cmake | |
parent | 9e40b6e9e1bc67f2d856adb837ee64dd0e25b717 (diff) | |
parent | 3c48d3c83fc21dbc0841f9210f04bdb073d73cd1 (diff) | |
download | rneovim-usermarks.tar.gz rneovim-usermarks.tar.bz2 rneovim-usermarks.zip |
Merge remote-tracking branch 'upstream/master' into usermarksusermarks
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/Download.cmake | 18 | ||||
-rw-r--r-- | cmake/FindIconv.cmake | 3 | ||||
-rw-r--r-- | cmake/GenerateVersion.cmake | 42 | ||||
-rw-r--r-- | cmake/GetCompileFlags.cmake | 114 | ||||
-rw-r--r-- | cmake/RunMsgfmt.cmake | 9 | ||||
-rw-r--r-- | cmake/RunMsgmerge.cmake | 11 | ||||
-rw-r--r-- | cmake/RunTests.cmake | 10 | ||||
-rw-r--r-- | cmake/RunXgettext.cmake | 14 | ||||
-rw-r--r-- | cmake/Util.cmake | 58 |
9 files changed, 130 insertions, 149 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 6118d8cba7..c092645140 100644 --- a/cmake/GenerateVersion.cmake +++ b/cmake/GenerateVersion.cmake @@ -1,30 +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 + COMMAND git --git-dir=${NVIM_SOURCE_DIR}/.git --work-tree=${NVIM_SOURCE_DIR} describe --first-parent --dirty --always OUTPUT_VARIABLE GIT_TAG - ERROR_VARIABLE ERR - RESULT_VARIABLE RES -) + OUTPUT_STRIP_TRAILING_WHITESPACE + 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. - 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}) @@ -32,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 49b57f6f75..9b3c053871 100644 --- a/cmake/GetCompileFlags.cmake +++ b/cmake/GetCompileFlags.cmake @@ -1,87 +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}}) - # Get C compiler. - if(CMAKE_C_COMPILER_ARG1) - string(REPLACE - "<CMAKE_C_COMPILER>" - "<CMAKE_C_COMPILER> ${CMAKE_C_COMPILER_ARG1}" - 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() - string(REPLACE - "<CMAKE_C_COMPILER>" - "${CMAKE_C_COMPILER}" - compile_flags - "${compile_flags}") - # 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/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/RunTests.cmake b/cmake/RunTests.cmake index e07c6dd174..c3ac5f208e 100644 --- a/cmake/RunTests.cmake +++ b/cmake/RunTests.cmake @@ -2,7 +2,9 @@ set(ENV{LC_ALL} "en_US.UTF-8") if(POLICY CMP0012) - # Handle CI=true, without dev warnings. + # Avoid policy warning due to CI=true. This is needed even if the main + # project has already set this policy as project settings aren't inherited + # when using cmake script mode (-P). cmake_policy(SET CMP0012 NEW) endif() @@ -13,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/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() diff --git a/cmake/Util.cmake b/cmake/Util.cmake index b485f4606b..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() @@ -143,3 +153,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() |