diff options
-rw-r--r-- | CMakeLists.txt | 23 | ||||
-rw-r--r-- | cmake.config/CMakeLists.txt | 18 | ||||
-rw-r--r-- | cmake.config/versiondef-old.h.in | 21 | ||||
-rw-r--r-- | cmake.config/versiondef.h.in | 4 | ||||
-rw-r--r-- | cmake/GetCompileFlags.cmake | 57 | ||||
-rwxr-xr-x | src/nvim/CMakeLists.txt | 31 |
6 files changed, 54 insertions, 100 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c9d7f339f..8df9eb19f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,28 +130,6 @@ set(NVIM_API_LEVEL 11) # Bump this after any API change. set(NVIM_API_LEVEL_COMPAT 0) # Adjust this after a _breaking_ API change. set(NVIM_API_PRERELEASE true) -set(NVIM_VERSION_BUILD_TYPE "${CMAKE_BUILD_TYPE}") -# NVIM_VERSION_CFLAGS set further below. - -# Log level (MIN_LOG_LEVEL in log.h) -if("${MIN_LOG_LEVEL}" MATCHES "^$") - # Minimize logging for release-type builds. - if(CMAKE_BUILD_TYPE STREQUAL "Release" - OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" - OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel") - message(STATUS "MIN_LOG_LEVEL not specified, default is 3 (ERROR) for release builds") - set(MIN_LOG_LEVEL 3) - else() - message(STATUS "MIN_LOG_LEVEL not specified, default is 1 (INFO)") - set(MIN_LOG_LEVEL 1) - endif() -else() - if(NOT MIN_LOG_LEVEL MATCHES "^[0-3]$") - message(FATAL_ERROR "invalid MIN_LOG_LEVEL: " ${MIN_LOG_LEVEL}) - endif() - message(STATUS "MIN_LOG_LEVEL=${MIN_LOG_LEVEL}") -endif() - # Default to -O2 on release builds. if(CMAKE_C_FLAGS_RELEASE MATCHES "-O3") message(STATUS "Replacing -O3 in CMAKE_C_FLAGS_RELEASE with -O2") @@ -333,7 +311,6 @@ install_helper( # add_subdirectory(src/nvim) -get_directory_property(NVIM_VERSION_CFLAGS DIRECTORY src/nvim DEFINITION NVIM_VERSION_CFLAGS) add_subdirectory(cmake.config) add_subdirectory(test/functional/fixtures) # compile test programs add_subdirectory(runtime) diff --git a/cmake.config/CMakeLists.txt b/cmake.config/CMakeLists.txt index 6de86cbaf2..872d6a9c62 100644 --- a/cmake.config/CMakeLists.txt +++ b/cmake.config/CMakeLists.txt @@ -162,11 +162,19 @@ configure_file ( "${PROJECT_BINARY_DIR}/cmake.config/auto/config.h" ) -# generate version definitions -configure_file ( - "${PROJECT_SOURCE_DIR}/cmake.config/versiondef.h.in" - "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef.h" - ) +# Improved :version output on newer cmake versions +if(${CMAKE_VERSION} VERSION_LESS 3.14) + configure_file( + "${PROJECT_SOURCE_DIR}/cmake.config/versiondef-old.h.in" + "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef.h.gen") +else() + configure_file( + "${PROJECT_SOURCE_DIR}/cmake.config/versiondef.h.in" + "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef.h.gen") +endif() +file(GENERATE + OUTPUT "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef.h" + INPUT "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef.h.gen") # generate pathdef.c find_program(WHOAMI_PROG whoami) diff --git a/cmake.config/versiondef-old.h.in b/cmake.config/versiondef-old.h.in new file mode 100644 index 0000000000..2bfd4e0b53 --- /dev/null +++ b/cmake.config/versiondef-old.h.in @@ -0,0 +1,21 @@ +#ifndef AUTO_VERSIONDEF_H +#define AUTO_VERSIONDEF_H + +#define NVIM_VERSION_MAJOR @NVIM_VERSION_MAJOR@ +#define NVIM_VERSION_MINOR @NVIM_VERSION_MINOR@ +#define NVIM_VERSION_PATCH @NVIM_VERSION_PATCH@ +#define NVIM_VERSION_PRERELEASE "@NVIM_VERSION_PRERELEASE@" + +#cmakedefine NVIM_VERSION_MEDIUM "@NVIM_VERSION_MEDIUM@" +#ifndef NVIM_VERSION_MEDIUM +# include "auto/versiondef_git.h" +#endif + +#define NVIM_API_LEVEL @NVIM_API_LEVEL@ +#define NVIM_API_LEVEL_COMPAT @NVIM_API_LEVEL_COMPAT@ +#define NVIM_API_PRERELEASE @NVIM_API_PRERELEASE@ + +#define NVIM_VERSION_CFLAGS "${CMAKE_C_COMPILER} $<JOIN:$<TARGET_PROPERTY:nvim,COMPILE_OPTIONS>, > -D$<JOIN:$<TARGET_PROPERTY:nvim,COMPILE_DEFINITIONS>, -D> -I$<JOIN:$<TARGET_PROPERTY:nvim,INCLUDE_DIRECTORIES>, -I>" +#define NVIM_VERSION_BUILD_TYPE "$<CONFIG>" + +#endif // AUTO_VERSIONDEF_H diff --git a/cmake.config/versiondef.h.in b/cmake.config/versiondef.h.in index 22cad87249..480399142b 100644 --- a/cmake.config/versiondef.h.in +++ b/cmake.config/versiondef.h.in @@ -15,7 +15,7 @@ #define NVIM_API_LEVEL_COMPAT @NVIM_API_LEVEL_COMPAT@ #define NVIM_API_PRERELEASE @NVIM_API_PRERELEASE@ -#define NVIM_VERSION_CFLAGS "@NVIM_VERSION_CFLAGS@" -#define NVIM_VERSION_BUILD_TYPE "@NVIM_VERSION_BUILD_TYPE@" +#define NVIM_VERSION_CFLAGS "${CMAKE_C_COMPILER} $<JOIN:$<TARGET_PROPERTY:nvim,COMPILE_OPTIONS>, > -D$<JOIN:$<TARGET_PROPERTY:nvim,COMPILE_DEFINITIONS>, -D> -I$<JOIN:$<REMOVE_DUPLICATES:$<TARGET_PROPERTY:nvim,INCLUDE_DIRECTORIES>>, -I>" +#define NVIM_VERSION_BUILD_TYPE "$<CONFIG>" #endif // AUTO_VERSIONDEF_H diff --git a/cmake/GetCompileFlags.cmake b/cmake/GetCompileFlags.cmake deleted file mode 100644 index 9b3c053871..0000000000 --- a/cmake/GetCompileFlags.cmake +++ /dev/null @@ -1,57 +0,0 @@ -function(get_compile_flags _compile_flags) - string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type) - set(compile_flags ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${build_type}}) - - # 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_target_property(opt nvim COMPILE_OPTIONS) - if(opt) - list(APPEND compile_flags ${opt}) - endif() - - # 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() - - get_target_property(defs nvim COMPILE_DEFINITIONS) - if(defs) - foreach(def ${defs}) - list(APPEND compile_flags "-D${def}") - endforeach() - endif() - - # 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_target_property(dirs main_lib INTERFACE_SYSTEM_INCLUDE_DIRECTORIES) - if(dirs) - foreach(dir ${dirs}) - list(APPEND compile_flags "-I${dir}") - endforeach() - endif() - - get_target_property(dirs nvim INCLUDE_DIRECTORIES) - if(dirs) - foreach(dir ${dirs}) - list(APPEND compile_flags "-I${dir}") - endforeach() - endif() - - list(REMOVE_DUPLICATES compile_flags) - string(REPLACE ";" " " compile_flags "${compile_flags}") - - set(${_compile_flags} "${compile_flags}" PARENT_SCOPE) -endfunction() diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 62b661dc2d..fd34a30619 100755 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -412,7 +412,15 @@ else() ${EXTERNAL_SOURCES} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-conversion -Wno-missing-noreturn -Wno-missing-format-attribute -Wno-double-promotion -Wno-strict-prototypes") endif() -if(NOT "${MIN_LOG_LEVEL}" MATCHES "^$") +# Log level (MIN_LOG_LEVEL in log.h) +if("${MIN_LOG_LEVEL}" MATCHES "^$") + # Minimize logging for release-type builds. + target_compile_definitions(main_lib INTERFACE MIN_LOG_LEVEL=$<IF:$<CONFIG:Debug>,1,3>) +else() + if(NOT MIN_LOG_LEVEL MATCHES "^[0-3]$") + message(FATAL_ERROR "invalid MIN_LOG_LEVEL: " ${MIN_LOG_LEVEL}) + endif() + message(STATUS "MIN_LOG_LEVEL=${MIN_LOG_LEVEL}") target_compile_definitions(main_lib INTERFACE MIN_LOG_LEVEL=${MIN_LOG_LEVEL}) endif() @@ -435,10 +443,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_SYSROOT) list(APPEND gen_cflags "-isysroot") list(APPEND gen_cflags "${CMAKE_OSX_SYSROOT}") endif() -string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type) -separate_arguments(C_FLAGS_ARRAY UNIX_COMMAND ${CMAKE_C_FLAGS}) -separate_arguments(C_FLAGS_${build_type}_ARRAY UNIX_COMMAND ${CMAKE_C_FLAGS_${build_type}}) -set(gen_cflags ${gen_cflags} ${C_FLAGS_${build_type}_ARRAY} ${C_FLAGS_ARRAY}) +set(gen_cflags ${gen_cflags} -O2) set(NVIM_VERSION_GIT_H ${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef_git.h) add_custom_target(update_version_stamp @@ -653,10 +658,10 @@ endif() if(NOT LUAJIT_FOUND) message(STATUS "luajit not found, skipping unit tests") -elseif(CMAKE_BUILD_TYPE MATCHES Debug) +else() glob_wrapper(UNIT_TEST_FIXTURES ${PROJECT_SOURCE_DIR}/test/unit/fixtures/*.c) - list(APPEND NVIM_SOURCES ${UNIT_TEST_FIXTURES}) - target_compile_definitions(main_lib INTERFACE UNIT_TESTING) + target_sources(nvim PRIVATE $<$<CONFIG:Debug>:${UNIT_TEST_FIXTURES}>) + target_compile_definitions(nvim PRIVATE $<$<CONFIG:Debug>:UNIT_TESTING>) endif() target_sources(nvim PRIVATE ${NVIM_GENERATED_FOR_SOURCES} ${NVIM_GENERATED_FOR_HEADERS} @@ -681,8 +686,11 @@ endif() if(ENABLE_LTO) include(CheckIPOSupported) check_ipo_supported(RESULT IPO_SUPPORTED) - if(IPO_SUPPORTED AND (NOT CMAKE_BUILD_TYPE MATCHES Debug)) - set_target_properties(nvim PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE) + if(IPO_SUPPORTED) + set_target_properties(nvim PROPERTIES + INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE + INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE + INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL TRUE) endif() endif() @@ -942,6 +950,3 @@ add_custom_target(generated-sources DEPENDS ) add_subdirectory(po) - -include(GetCompileFlags) -get_compile_flags(NVIM_VERSION_CFLAGS) |