diff options
-rw-r--r-- | CMakeLists.txt | 12 | ||||
-rw-r--r-- | cmake.deps/CMakeLists.txt | 12 | ||||
-rw-r--r-- | cmake.deps/cmake/BuildGettext.cmake | 4 | ||||
-rw-r--r-- | cmake.deps/cmake/BuildLibiconv.cmake | 4 | ||||
-rw-r--r-- | cmake.deps/cmake/BuildLibtermkey.cmake | 4 | ||||
-rw-r--r-- | cmake.deps/cmake/BuildLibvterm.cmake | 5 | ||||
-rw-r--r-- | cmake.deps/cmake/BuildLuv.cmake | 6 | ||||
-rw-r--r-- | cmake.deps/cmake/BuildMsgpack.cmake | 4 | ||||
-rw-r--r-- | cmake.deps/cmake/BuildTreesitter.cmake | 4 | ||||
-rw-r--r-- | cmake.deps/cmake/BuildUnibilium.cmake | 4 | ||||
-rw-r--r-- | cmake/Util.cmake | 40 |
11 files changed, 61 insertions, 38 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index caf9658699..6654cc62b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,22 +127,12 @@ endif() message(STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}") -# Build type. -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) -else() - message(STATUS "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") -endif() +set_default_buildtype() if(CMAKE_BUILD_TYPE MATCHES Debug) set(DEBUG 1) else() set(DEBUG 0) endif() -# Set available build types for CMake GUIs. -# Other build types can still be set by -DCMAKE_BUILD_TYPE=... -set_property(CACHE CMAKE_BUILD_TYPE PROPERTY - STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") # If not in a git repo (e.g., a tarball) these tokens define the complete # version string, else they are combined with the result of `git describe`. diff --git a/cmake.deps/CMakeLists.txt b/cmake.deps/CMakeLists.txt index 2c19aa6e6b..1e99b4c057 100644 --- a/cmake.deps/CMakeLists.txt +++ b/cmake.deps/CMakeLists.txt @@ -2,22 +2,18 @@ cmake_minimum_required (VERSION 3.10) project(NVIM_DEPS C) -# Needed for: check_c_compiler_flag() -include(CheckCCompilerFlag) - # Point CMake at any custom modules we may ship list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${PROJECT_SOURCE_DIR}/../cmake") +include(CheckCCompilerFlag) +include(Util) + get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(NOT isMultiConfig) set(BUILD_TYPE_STRING -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}) endif() -# In Windows/MSVC CMAKE_BUILD_TYPE changes the paths/linking of the build -# recipes (libuv, msgpack), make sure it is set -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) -endif() +set_default_buildtype() set(DEFAULT_MAKE_CFLAGS CFLAGS+=-g) diff --git a/cmake.deps/cmake/BuildGettext.cmake b/cmake.deps/cmake/BuildGettext.cmake index f36c00c559..d903fbc737 100644 --- a/cmake.deps/cmake/BuildGettext.cmake +++ b/cmake.deps/cmake/BuildGettext.cmake @@ -23,8 +23,8 @@ if(MSVC) -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DLIBICONV_INCLUDE_DIRS=${DEPS_INSTALL_DIR}/include -DLIBICONV_LIBRARIES=${DEPS_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}libcharset${CMAKE_STATIC_LIBRARY_SUFFIX}$<SEMICOLON>${DEPS_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}libiconv${CMAKE_STATIC_LIBRARY_SUFFIX} - BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}) + BUILD_COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG> + INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config $<CONFIG>) else() message(FATAL_ERROR "Trying to build gettext in an unsupported system ${CMAKE_SYSTEM_NAME}/${CMAKE_C_COMPILER_ID}") endif() diff --git a/cmake.deps/cmake/BuildLibiconv.cmake b/cmake.deps/cmake/BuildLibiconv.cmake index 434bfd6979..29168340a1 100644 --- a/cmake.deps/cmake/BuildLibiconv.cmake +++ b/cmake.deps/cmake/BuildLibiconv.cmake @@ -21,8 +21,8 @@ if(MSVC) ${BUILD_TYPE_STRING} -DCMAKE_GENERATOR=${CMAKE_GENERATOR} -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} - BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}) + BUILD_COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG> + INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config $<CONFIG>) else() message(FATAL_ERROR "Trying to build libiconv in an unsupported system ${CMAKE_SYSTEM_NAME}/${CMAKE_C_COMPILER_ID}") endif() diff --git a/cmake.deps/cmake/BuildLibtermkey.cmake b/cmake.deps/cmake/BuildLibtermkey.cmake index 66bac57d23..7aa0b3e8c6 100644 --- a/cmake.deps/cmake/BuildLibtermkey.cmake +++ b/cmake.deps/cmake/BuildLibtermkey.cmake @@ -25,8 +25,8 @@ ExternalProject_Add(libtermkey -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DUNIBILIUM_INCLUDE_DIRS=${DEPS_INSTALL_DIR}/include -DUNIBILIUM_LIBRARIES=${DEPS_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}unibilium${CMAKE_STATIC_LIBRARY_SUFFIX} - BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}) + BUILD_COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG> + INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config $<CONFIG>) else() find_package(PkgConfig REQUIRED) diff --git a/cmake.deps/cmake/BuildLibvterm.cmake b/cmake.deps/cmake/BuildLibvterm.cmake index a905733abc..1f7088cdb7 100644 --- a/cmake.deps/cmake/BuildLibvterm.cmake +++ b/cmake.deps/cmake/BuildLibvterm.cmake @@ -49,14 +49,13 @@ if(WIN32) -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_GENERATOR=${CMAKE_GENERATOR}) - if(MSVC) list(APPEND LIBVTERM_CONFIGURE_COMMAND "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_COMPILER_ARG1}") else() list(APPEND LIBVTERM_CONFIGURE_COMMAND "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_COMPILER_ARG1} -fPIC") endif() - set(LIBVTERM_BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE}) - set(LIBVTERM_INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}) + set(LIBVTERM_BUILD_COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG>) + set(LIBVTERM_INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config $<CONFIG>) else() set(LIBVTERM_INSTALL_COMMAND ${MAKE_PRG} CC=${DEPS_C_COMPILER} PREFIX=${DEPS_INSTALL_DIR} diff --git a/cmake.deps/cmake/BuildLuv.cmake b/cmake.deps/cmake/BuildLuv.cmake index f960b24992..9e890642a6 100644 --- a/cmake.deps/cmake/BuildLuv.cmake +++ b/cmake.deps/cmake/BuildLuv.cmake @@ -110,10 +110,8 @@ else() endif() endif() -set(LUV_BUILD_COMMAND - ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE}) -set(LUV_INSTALL_COMMAND - ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}) +set(LUV_BUILD_COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG>) +set(LUV_INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config $<CONFIG>) BuildLuv(PATCH_COMMAND ${LUV_PATCH_COMMAND} CONFIGURE_COMMAND ${LUV_CONFIGURE_COMMAND} diff --git a/cmake.deps/cmake/BuildMsgpack.cmake b/cmake.deps/cmake/BuildMsgpack.cmake index ea3fa84d7b..1ef00ba3ad 100644 --- a/cmake.deps/cmake/BuildMsgpack.cmake +++ b/cmake.deps/cmake/BuildMsgpack.cmake @@ -40,8 +40,8 @@ set(MSGPACK_CONFIGURE_COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/msgpack "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_COMPILER_ARG1} -fPIC" -DCMAKE_GENERATOR=${CMAKE_GENERATOR}) -set(MSGPACK_BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE}) -set(MSGPACK_INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}) +set(MSGPACK_BUILD_COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG>) +set(MSGPACK_INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config $<CONFIG>) if(MSVC) # Same as Unix without fPIC diff --git a/cmake.deps/cmake/BuildTreesitter.cmake b/cmake.deps/cmake/BuildTreesitter.cmake index 6d98f6179c..85dd9ab225 100644 --- a/cmake.deps/cmake/BuildTreesitter.cmake +++ b/cmake.deps/cmake/BuildTreesitter.cmake @@ -45,8 +45,8 @@ if(MSVC) -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} ${BUILD_TYPE_STRING} -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} - BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE} + BUILD_COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG> + INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config $<CONFIG> ) else() set(TS_CFLAGS "-O3 -Wall -Wextra") diff --git a/cmake.deps/cmake/BuildUnibilium.cmake b/cmake.deps/cmake/BuildUnibilium.cmake index fd5d68f9a8..44bd816550 100644 --- a/cmake.deps/cmake/BuildUnibilium.cmake +++ b/cmake.deps/cmake/BuildUnibilium.cmake @@ -21,8 +21,8 @@ if(WIN32) -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} ${BUILD_TYPE_STRING} -DCMAKE_GENERATOR=${CMAKE_GENERATOR} - BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}) + BUILD_COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG> + INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config $<CONFIG>) else() ExternalProject_Add(unibilium PREFIX ${DEPS_BUILD_DIR} 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() |