cmake: Remove custom build types
[quassel.git] / cmake / QuasselCompileSettings.cmake
1 # This file contains compile flags and general build configuration for Quassel
2 #
3 # (C) 2014 by the Quassel Project <devel@quassel-irc.org>
4 #
5 # Redistribution and use is allowed according to the terms of the BSD license.
6 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
7
8 include(CheckCXXCompilerFlag)
9
10 # Qt debug flags
11 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG QT_DEBUG)
12 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE QT_NO_DEBUG NDEBUG)
13 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO QT_NO_DEBUG NDEBUG)
14 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL QT_NO_DEBUG NDEBUG)
15
16 if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
17     set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_DEBUG NDEBUG)
18 endif()
19
20 # Enable various flags on gcc
21 if (CMAKE_COMPILER_IS_GNUCXX)
22     if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8")
23         message(FATAL_ERROR "Your compiler is too old; you need GCC 4.8+, Clang 3.3+, MSVC 19.0+, or any other compiler with full C++11 support.")
24     endif()
25
26     # Let's just hope that all gccs support these options and skip the tests...
27     # -fno-strict-aliasing is needed apparently for Qt < 4.6
28     set(CMAKE_CXX_FLAGS                  "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wnon-virtual-dtor -fno-strict-aliasing -Wundef -Wcast-align -Wpointer-arith -Wformat-security -fno-check-new -fno-common")
29     #  set(CMAKE_CXX_FLAGS_RELEASE          "-O2")   # use CMake default
30     #  set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O2")  # use CMake default
31     set(CMAKE_CXX_FLAGS_DEBUG             "-g -ggdb -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline")
32
33     check_cxx_compiler_flag(-Woverloaded-virtual CXX_W_OVERLOADED_VIRTUAL)
34     if(CXX_W_OVERLOADED_VIRTUAL)
35         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual")
36     endif()
37
38     # Just for miniz
39     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-function -Wno-undef -fno-strict-aliasing")
40
41 # ... and for Clang
42 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
43     if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.3")
44         message(FATAL_ERROR "Your compiler is too old; you need Clang 3.3+, GCC 4.8+, MSVC 19.0+, or any other compiler with full C++11 support.")
45     endif()
46
47     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wnon-virtual-dtor -Wno-long-long -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wextra -Wpointer-arith -Wformat-security -Woverloaded-virtual -fno-common -Wno-deprecated-register")
48     #  set(CMAKE_CXX_FLAGS_RELEASE        "-O2 -DNDEBUG -DQT_NO_DEBUG")     # Use CMake default
49     #  set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG -DQT_NO_DEBUG")  # Use CMake default
50     set(CMAKE_CXX_FLAGS_DEBUG          "-g -O2 -fno-inline")
51
52     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-function -Wno-undef -fno-strict-aliasing")
53
54 # For MSVC, at least do a version sanity check...
55 elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
56     if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.0")
57         message(FATAL_ERROR "Your compiler is too old; you need at least Visual Studio 2015 (MSVC 19.0+), GCC 4.8+, Clang 3.3+, or any other compiler with full C++11 support.")
58     endif()
59
60     # ... and enable exception handling (required for STL types)
61     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
62
63 # Unknown/unsupported compiler
64 else()
65     message(WARNING "Unknown or unsupported compiler. Make sure to enable C++11 support. Good luck.")
66 endif()
67
68 # Mac build stuff
69 if (APPLE AND DEPLOY)
70     set(CMAKE_OSX_ARCHITECTURES "x86_64")
71     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.9 -stdlib=libc++")
72 endif()