1 # This file contains compile flags and general build configuration for Quassel
3 # (C) 2014 by the Quassel Project <devel@quassel-irc.org>
5 # Redistribution and use is allowed according to the terms of the BSD license.
6 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
8 include(CheckCXXCompilerFlag)
11 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG QT_DEBUG)
12 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUGFULL QT_DEBUG)
13 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE QT_NO_DEBUG NDEBUG)
14 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO QT_NO_DEBUG NDEBUG)
15 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_PROFILE QT_NO_DEBUG NDEBUG)
16 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL QT_NO_DEBUG NDEBUG)
18 if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
19 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_DEBUG NDEBUG)
22 # Enable various flags on gcc
23 if (CMAKE_COMPILER_IS_GNUCXX)
24 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8")
25 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.")
28 # Let's just hope that all gccs support these options and skip the tests...
29 # -fno-strict-aliasing is needed apparently for Qt < 4.6
30 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")
31 # set(CMAKE_CXX_FLAGS_RELEASE "-O2") # use CMake default
32 # set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O2") # use CMake default
33 set(CMAKE_CXX_FLAGS_DEBUG "-g -ggdb -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline")
34 set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3 -ggdb -fno-inline")
35 set(CMAKE_CXX_FLAGS_PROFILE "-g3 -ggdb -fno-inline -ftest-coverage -fprofile-arcs")
37 check_cxx_compiler_flag(-Woverloaded-virtual CXX_W_OVERLOADED_VIRTUAL)
38 if(CXX_W_OVERLOADED_VIRTUAL)
39 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual")
43 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-function -Wno-undef -fno-strict-aliasing")
46 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
47 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.3")
48 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.")
51 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")
52 # set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG -DQT_NO_DEBUG") # Use CMake default
53 # set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG -DQT_NO_DEBUG") # Use CMake default
54 set(CMAKE_CXX_FLAGS_DEBUG "-g -O2 -fno-inline")
55 set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3 -fno-inline")
56 set(CMAKE_CXX_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs")
58 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-function -Wno-undef -fno-strict-aliasing")
60 # For MSVC, at least do a version sanity check...
61 elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
62 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.0")
63 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.")
66 # ... and enable exception handling (required for STL types)
67 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
69 # Unknown/unsupported compiler
71 message(WARNING "Unknown or unsupported compiler. Make sure to enable C++11 support. Good luck.")
76 set(CMAKE_OSX_ARCHITECTURES "x86_64")
77 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.9 -stdlib=libc++")