From: Manuel Nickschas Date: Wed, 1 Aug 2018 20:12:09 +0000 (+0200) Subject: cmake: Remove custom build types X-Git-Tag: test-travis-01~174 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=48d41896ba35eafc64b4cb00e446d6123b3502cb cmake: Remove custom build types The non-standard build types DebugFull and Profile (which we took from KDE4) are not supported by e.g. Qt, so remove them. Improve build type handling; show the supported values in CMake GUIs and provide a sensible default if none is given (Release unless a .git directory is present, in which case Debug is default). --- diff --git a/CMakeLists.txt b/CMakeLists.txt index afb620cc..310cf8fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,26 +8,21 @@ cmake_minimum_required(VERSION 3.5) +# Tell CMake about or own modules +set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) + # Versions set(QUASSEL_MAJOR 0) set(QUASSEL_MINOR 13) set(QUASSEL_PATCH 50) set(QUASSEL_VERSION_STRING "0.14-pre") -# Build type -if (CMAKE_CONFIGURATION_TYPES) - set(CMAKE_CONFIGURATION_TYPES Release RelWithDebInfo Debug Debugfull Profile) - set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "These are the configuration types we support" FORCE) -endif() - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: Release RelWithDebInfo Debug Debugfull Profile None" FORCE) -endif() - # Output CMake and Quassel versions as well as build type for debug reasons message(STATUS "Building Quassel ${QUASSEL_VERSION_STRING}...") message(STATUS "Using CMake ${CMAKE_VERSION}") -message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}") + +# Set up build type rather early +include(BuildType) # Support ccache if found # This should happen before calling project(), so compiler settings are validated. @@ -50,7 +45,7 @@ project(Quassel CXX) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -# Include various CMake modules +# Include various CMake modules... include(CMakePushCheckState) include(CheckFunctionExists) include(CheckIncludeFileCXX) @@ -58,12 +53,10 @@ include(CheckCXXSourceCompiles) include(CMakeDependentOption) include(FeatureSummary) -# Tell CMake about or own modules -set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) +# ... and our own include(QuasselCompileSettings) include(QuasselMacros) - # Options and variables that can be set on the command line ##################################################################### diff --git a/cmake/BuildType.cmake b/cmake/BuildType.cmake new file mode 100644 index 00000000..a1b0a70e --- /dev/null +++ b/cmake/BuildType.cmake @@ -0,0 +1,21 @@ +# Derived from Marcus D. Hanwell's suggestion +# https://blog.kitware.com/cmake-and-the-default-build-type/ + +# Set a default build type if none was specified +set(default_build_type "Release") + +# For builds from Git, default to Debug +if (EXISTS "${CMAKE_SOURCE_DIR}/.git") + set(default_build_type "Debug") +endif() + +# Multi-config generators (such as the VS one) will set the config types +if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to '${default_build_type}' as none was specified.") + set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE + STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +else() + message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}") +endif() diff --git a/cmake/QuasselCompileSettings.cmake b/cmake/QuasselCompileSettings.cmake index 67cfd643..38ce1358 100644 --- a/cmake/QuasselCompileSettings.cmake +++ b/cmake/QuasselCompileSettings.cmake @@ -9,10 +9,8 @@ include(CheckCXXCompilerFlag) # Qt debug flags set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG QT_DEBUG) -set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUGFULL QT_DEBUG) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE QT_NO_DEBUG NDEBUG) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO QT_NO_DEBUG NDEBUG) -set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_PROFILE QT_NO_DEBUG NDEBUG) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL QT_NO_DEBUG NDEBUG) if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) @@ -31,8 +29,6 @@ if (CMAKE_COMPILER_IS_GNUCXX) # set(CMAKE_CXX_FLAGS_RELEASE "-O2") # use CMake default # set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O2") # use CMake default set(CMAKE_CXX_FLAGS_DEBUG "-g -ggdb -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline") - set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3 -ggdb -fno-inline") - set(CMAKE_CXX_FLAGS_PROFILE "-g3 -ggdb -fno-inline -ftest-coverage -fprofile-arcs") check_cxx_compiler_flag(-Woverloaded-virtual CXX_W_OVERLOADED_VIRTUAL) if(CXX_W_OVERLOADED_VIRTUAL) @@ -52,8 +48,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG -DQT_NO_DEBUG") # Use CMake default # set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG -DQT_NO_DEBUG") # Use CMake default set(CMAKE_CXX_FLAGS_DEBUG "-g -O2 -fno-inline") - set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3 -fno-inline") - set(CMAKE_CXX_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-function -Wno-undef -fno-strict-aliasing")