From 176930fa56bff3668d434779972ceb29d41d9bc7 Mon Sep 17 00:00:00 2001 From: Florian Walch Date: Sun, 9 Nov 2014 13:52:15 +0100 Subject: [PATCH] version: Add compilation info. --- CMakeLists.txt | 20 ++++++++++++- cmake/GetCompileFlags.cmake | 58 +++++++++++++++++++++++++++++++++++++ config/config.h.in | 2 ++ src/nvim/CMakeLists.txt | 4 +-- src/nvim/version.c | 8 ++--- src/nvim/version_defs.h | 12 ++++++-- 6 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 cmake/GetCompileFlags.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b74785cc2b..223c28f348 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,17 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") endif() endif() +# Set available build types for CMake GUIs. +# A different build type can still be set by -DCMAKE_BUILD_TYPE=... +set_property(CACHE CMAKE_BUILD_TYPE PROPERTY + STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") + +# Set default build type. +if(NOT CMAKE_BUILD_TYPE) + message(STATUS "CMAKE_BUILD_TYPE not given; setting to 'RelWithDebInfo'.") + set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build." FORCE) +endif() + # Version tokens include(GetGitRevisionDescription) get_git_head_revision(GIT_REFSPEC NVIM_VERSION_COMMIT) @@ -48,6 +59,8 @@ git_timestamp(GIT_TIMESTAMP) if(GIT_TIMESTAMP) set(NVIM_VERSION_BUILD "+${GIT_TIMESTAMP}") endif() +set(NVIM_VERSION_BUILD_TYPE "${CMAKE_BUILD_TYPE}") +# NVIM_VERSION_CFLAGS set further below. set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -249,9 +262,14 @@ install(SCRIPT ${CMAKE_MODULE_PATH}/GenerateHelptags.cmake) # Go down the tree. -add_subdirectory(config) add_subdirectory(src/nvim) +# Read compilation flags from src/nvim, +# used in config subdirectory below. +include(GetCompileFlags) +get_compile_flags(NVIM_VERSION_CFLAGS) + add_subdirectory(test/includes) +add_subdirectory(config) # Setup some test-related bits. We do this after going down the tree because we # need some of the targets. diff --git a/cmake/GetCompileFlags.cmake b/cmake/GetCompileFlags.cmake new file mode 100644 index 0000000000..e0994b67bc --- /dev/null +++ b/cmake/GetCompileFlags.cmake @@ -0,0 +1,58 @@ +function(get_compile_flags _compile_flags) + # Create template akin to CMAKE_C_COMPILE_OBJECT. + set(compile_flags " ") + + # Get C compiler. + string(REPLACE + "" + "${CMAKE_C_COMPILER}" + compile_flags + "${compile_flags}") + + # Get flags set by add_definition(). + get_directory_property(definitions + DIRECTORY "src/nvim" + DEFINITIONS) + string(REPLACE + "" + "${definitions}" + compile_flags + "${compile_flags}") + + # Get general C flags. + string(REPLACE + "" + "${CMAKE_C_FLAGS}" + compile_flags + "${compile_flags}") + + # 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 include directories. + get_directory_property(include_directories_list + DIRECTORY "src/nvim" + INCLUDE_DIRECTORIES) + foreach(include_directory ${include_directories_list}) + set(include_directories "${include_directories} -I${include_directory}") + endforeach() + string(REPLACE + "" + "${include_directories}" + compile_flags + "${compile_flags}") + + # Clean duplicate whitespace. + string(REPLACE + " " + " " + compile_flags + "${compile_flags}") + + set(${_compile_flags} "${compile_flags}" PARENT_SCOPE) +endfunction() diff --git a/config/config.h.in b/config/config.h.in index 7a04837c92..8143b18ecb 100644 --- a/config/config.h.in +++ b/config/config.h.in @@ -4,6 +4,8 @@ #define NVIM_VERSION_PRERELEASE "@NVIM_VERSION_PRERELEASE@" #define NVIM_VERSION_BUILD "@NVIM_VERSION_BUILD@" #define NVIM_VERSION_COMMIT "@NVIM_VERSION_COMMIT@" +#define NVIM_VERSION_CFLAGS "@NVIM_VERSION_CFLAGS@" +#define NVIM_VERSION_BUILD_TYPE "@NVIM_VERSION_BUILD_TYPE@" #cmakedefine DEBUG diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 4e0819cc0e..b06b4fa547 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -89,8 +89,8 @@ get_directory_property(gen_includes INCLUDE_DIRECTORIES) foreach(gen_include ${gen_includes}) set(gen_cflags "${gen_cflags} -I${gen_include}") endforeach() -string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type) -set(gen_cflags "${gen_cflags} ${CMAKE_C_FLAGS_${_build_type}} ${CMAKE_C_FLAGS}") +string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type) +set(gen_cflags "${gen_cflags} ${CMAKE_C_FLAGS_${build_type}} ${CMAKE_C_FLAGS}") foreach(sfile ${NEOVIM_SOURCES} "${PROJECT_SOURCE_DIR}/src/nvim/regexp_nfa.c") diff --git a/src/nvim/version.c b/src/nvim/version.c index 4d81cc86bf..137f85bb2b 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -21,6 +21,8 @@ char *Version = VIM_VERSION_SHORT; char *longVersion = NVIM_VERSION_LONG " (compiled " __DATE__ " " __TIME__ ")"; char *version_commit = "Commit: " NVIM_VERSION_COMMIT; +char *version_buildtype = "Build type: " NVIM_VERSION_BUILD_TYPE; +char *version_cflags = "Compilation: " NVIM_VERSION_CFLAGS; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "version.c.generated.h" @@ -778,6 +780,8 @@ void list_version(void) // internal variables in eval.c! MSG(longVersion); MSG(version_commit); + MSG(version_buildtype); + MSG(version_cflags); // Print the list of extra patch descriptions if there is at least one. char *s = ""; @@ -857,10 +861,6 @@ void list_version(void) version_msg("\"\n"); } #endif // ifdef HAVE_PATHDEF -#ifdef DEBUG - version_msg("\n"); - version_msg(_(" DEBUG BUILD")); -#endif // ifdef DEBUG } /// Output a string for the version message. If it's going to wrap, output a diff --git a/src/nvim/version_defs.h b/src/nvim/version_defs.h index d8e1b4ea82..0ba6143632 100644 --- a/src/nvim/version_defs.h +++ b/src/nvim/version_defs.h @@ -22,13 +22,19 @@ #define NVIM_VERSION_PATCH 0 #endif #ifndef NVIM_VERSION_PRERELEASE -#define NVIM_VERSION_PRERELEASE +#define NVIM_VERSION_PRERELEASE "?" #endif #ifndef NVIM_VERSION_BUILD -#define NVIM_VERSION_BUILD +#define NVIM_VERSION_BUILD "?" #endif #ifndef NVIM_VERSION_COMMIT -#define NVIM_VERSION_COMMIT +#define NVIM_VERSION_COMMIT "?" +#endif +#ifndef NVIM_VERSION_CFLAGS +#define NVIM_VERSION_CFLAGS "?" +#endif +#ifndef NVIM_VERSION_BUILD_TYPE +#define NVIM_VERSION_BUILD_TYPE "?" #endif // for the startup-screen #define NVIM_VERSION_MEDIUM STR(NVIM_VERSION_MAJOR) "." STR(NVIM_VERSION_MINOR)