cmake: Modernize build system
[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 # Enable various flags on gcc
11 if (CMAKE_COMPILER_IS_GNUCXX)
12     if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8")
13         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.")
14     endif()
15
16     # Let's just hope that all gccs support these options and skip the tests...
17     # -fno-strict-aliasing is needed apparently for Qt < 4.6
18     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")
19     #  set(CMAKE_CXX_FLAGS_RELEASE          "-O2")   # use CMake default
20     #  set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O2")  # use CMake default
21     set(CMAKE_CXX_FLAGS_DEBUG             "-g -ggdb -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline")
22
23     check_cxx_compiler_flag(-Woverloaded-virtual CXX_W_OVERLOADED_VIRTUAL)
24     if(CXX_W_OVERLOADED_VIRTUAL)
25         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual")
26     endif()
27
28     # Just for miniz
29     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-function -Wno-undef -fno-strict-aliasing")
30
31 # ... and for Clang
32 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
33     if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.3")
34         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.")
35     endif()
36
37     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")
38     #  set(CMAKE_CXX_FLAGS_RELEASE        "-O2 -DNDEBUG -DQT_NO_DEBUG")     # Use CMake default
39     #  set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG -DQT_NO_DEBUG")  # Use CMake default
40     set(CMAKE_CXX_FLAGS_DEBUG          "-g -O2 -fno-inline")
41
42     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-function -Wno-undef -fno-strict-aliasing")
43
44 # For MSVC, at least do a version sanity check...
45 elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
46     if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.0")
47         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.")
48     endif()
49
50     # ... and enable exception handling (required for STL types)
51     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
52
53 # Unknown/unsupported compiler
54 else()
55     message(WARNING "Unknown or unsupported compiler. Make sure to enable C++11 support. Good luck.")
56 endif()
57
58 # Mac build stuff
59 if (APPLE AND DEPLOY)
60     set(CMAKE_OSX_ARCHITECTURES "x86_64")
61     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.9 -stdlib=libc++")
62 endif()