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.
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(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
#####################################################################
--- /dev/null
+# 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()
# 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)
# 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)
# 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")