diff options
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 100 |
1 files changed, 70 insertions, 30 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3db32f1966..70be0be6d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,31 +38,36 @@ 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") + STRINGS "Debug" "Dev" "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) + message(STATUS "CMAKE_BUILD_TYPE not given, defaulting to 'Dev'.") + set(CMAKE_BUILD_TYPE "Dev" CACHE STRING "Choose the type of build." FORCE) endif() # Version tokens -include(GetGitRevisionDescription) -file(TO_NATIVE_PATH ${CMAKE_CURRENT_LIST_DIR}/.git GIT_DIR) -get_git_head_revision(GIT_REFSPEC NVIM_VERSION_COMMIT) -if(NOT NVIM_VERSION_COMMIT) - set(NVIM_VERSION_COMMIT "?") -endif() set(NVIM_VERSION_MAJOR 0) set(NVIM_VERSION_MINOR 0) set(NVIM_VERSION_PATCH 0) set(NVIM_VERSION_PRERELEASE "-alpha") -# TODO(justinmk): UTC time would be nice here #1071 -git_timestamp(GIT_TIMESTAMP) -# TODO(justinmk): do not set this for "release" builds #1071 -if(GIT_TIMESTAMP) - set(NVIM_VERSION_BUILD "+${GIT_TIMESTAMP}") + +file(TO_CMAKE_PATH ${CMAKE_CURRENT_LIST_DIR}/.git FORCED_GIT_DIR) +include(GetGitRevisionDescription) +if(NVIM_VERSION_PRERELEASE) + get_git_head_revision(GIT_REFSPEC NVIM_VERSION_COMMIT) + + # TODO(justinmk): UTC time would be nice here #1071 + git_timestamp(GIT_TIMESTAMP) + if(GIT_TIMESTAMP) + set(NVIM_VERSION_BUILD "+${GIT_TIMESTAMP}") + endif() +else() + # If possible, get the Git tag for the current revision. + git_get_exact_tag(NVIM_VERSION_COMMIT) + set(NVIM_VERSION_BUILD "") endif() + set(NVIM_VERSION_BUILD_TYPE "${CMAKE_BUILD_TYPE}") # NVIM_VERSION_CFLAGS set further below. @@ -74,6 +79,57 @@ if(CMAKE_C_FLAGS_RELEASE MATCHES "-O3") string(REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") endif() +# Disable logging for release-type builds. +if(NOT CMAKE_C_FLAGS_RELEASE MATCHES DDISABLE_LOG) + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DDISABLE_LOG") +endif() +if(NOT CMAKE_C_FLAGS_MINSIZEREL MATCHES DDISABLE_LOG) + set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DDISABLE_LOG") +endif() +if(NOT CMAKE_C_FLAGS_RELWITHDEBINFO MATCHES DDISABLE_LOG) + set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DDISABLE_LOG") +endif() + +# Enable assertions for RelWithDebInfo. +if(CMAKE_C_FLAGS_RELWITHDEBINFO MATCHES DNDEBUG) + string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}") +endif() + +# Set build flags for custom Dev build type. +# -DNDEBUG purposely omitted because we want assertions. +if(MSVC) + SET(CMAKE_C_FLAGS_DEV "" + CACHE STRING "Flags used by the compiler during development (optimized, but with debug info and logging) builds." + FORCE) +else() + if(CMAKE_COMPILER_IS_GNUCC) + check_c_compiler_flag(-Og HAS_OG_FLAG) + else() + set(HAS_OG_FLAG 0) + endif() + + if(HAS_OG_FLAG) + set(CMAKE_C_FLAGS_DEV "-Og -g" + CACHE STRING "Flags used by the compiler during development (optimized, but with debug info and logging) builds." + FORCE) + else() + set(CMAKE_C_FLAGS_DEV "-O2 -g" + CACHE STRING "Flags used by the compiler during development (optimized, but with debug info and logging) builds." + FORCE) + endif() +endif() +SET(CMAKE_EXE_LINKER_FLAGS_DEV "" + CACHE STRING "Flags used for linking binaries during development (optimized, but with debug info and logging) builds." + FORCE) +SET(CMAKE_SHARED_LINKER_FLAGS_DEV "" + CACHE STRING "Flags used by the shared libraries linker during development (optimized, but with debug info and logging) builds." + FORCE) + +MARK_AS_ADVANCED( + CMAKE_C_FLAGS_DEV + CMAKE_EXE_LINKER_FLAGS_DEV + CMAKE_SHARED_LINKER_FLAGS_DEV) + # Enable -Wconversion. if(NOT MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion") @@ -177,22 +233,6 @@ if(TRAVIS_CI_BUILD) add_definitions(-Werror) endif() -if(CMAKE_COMPILER_IS_GNUCC) - check_c_compiler_flag(-Og HAS_OG_FLAG) -else() - set(HAS_OG_FLAG 0) -endif() - -# Set custom build flags for RelWithDebInfo. -# -DNDEBUG purposely omitted because we want assertions. -if(HAS_OG_FLAG) - set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Og -g" - CACHE STRING "Flags used by the compiler during release builds with debug info." FORCE) -elseif(NOT MSVC) - set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g" - CACHE STRING "Flags used by the compiler during release builds with debug info." FORCE) -endif() - if(CMAKE_BUILD_TYPE MATCHES Debug) set(DEBUG 1) else() |