cmake: Remove custom build types
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 1 Aug 2018 20:12:09 +0000 (22:12 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 18 Nov 2018 10:06:43 +0000 (11:06 +0100)
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).

CMakeLists.txt
cmake/BuildType.cmake [new file with mode: 0644]
cmake/QuasselCompileSettings.cmake

index afb620c..310cf8f 100644 (file)
@@ -8,26 +8,21 @@
 
 cmake_minimum_required(VERSION 3.5)
 
 
 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")
 
 # 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}")
 # 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.
 
 # 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)
 
 set(CMAKE_AUTOMOC ON)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
-# Include various CMake modules
+# Include various CMake modules...
 include(CMakePushCheckState)
 include(CheckFunctionExists)
 include(CheckIncludeFileCXX)
 include(CMakePushCheckState)
 include(CheckFunctionExists)
 include(CheckIncludeFileCXX)
@@ -58,12 +53,10 @@ include(CheckCXXSourceCompiles)
 include(CMakeDependentOption)
 include(FeatureSummary)
 
 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)
 
 include(QuasselCompileSettings)
 include(QuasselMacros)
 
-
 # Options and variables that can be set on the command line
 #####################################################################
 
 # 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 (file)
index 0000000..a1b0a70
--- /dev/null
@@ -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()
index 67cfd64..38ce135 100644 (file)
@@ -9,10 +9,8 @@ include(CheckCXXCompilerFlag)
 
 # Qt debug flags
 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG QT_DEBUG)
 
 # 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_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)
 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_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)
 
     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_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")
 
 
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-function -Wno-undef -fno-strict-aliasing")