modernize: Remove custom Quassel-specific log macros
[quassel.git] / cmake / QuasselCompileSettings.cmake
1 # This file contains compile flags and general build configuration for Quassel
2 #
3 # (C) 2014-2018 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 # Helper function to check for linker flag support
9 include(CheckCXXCompilerFlag)
10 function(check_and_set_linker_flag flag name outvar)
11     cmake_push_check_state(RESET)
12     set(CMAKE_REQUIRED_FLAGS "${flag}")
13     check_cxx_compiler_flag("" LINKER_SUPPORTS_${name})
14     if (LINKER_SUPPORTS_${name})
15         set(${outvar} "${${outvar}} ${flag}" PARENT_SCOPE)
16     endif()
17     cmake_pop_check_state()
18 endfunction()
19
20 # General compile settings
21 set(CMAKE_CXX_STANDARD 14)
22 set(CMAKE_CXX_STANDARD_REQUIRED OFF)    # Rely on compile features if standard is not supported
23 set(CMAKE_CXX_EXTENSIONS OFF)           # We like to be standard conform
24
25 set(CMAKE_CXX_VISIBILITY_PRESET hidden)
26 set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
27 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
28
29 # For GCC and Clang, enable a whole bunch of warnings
30 if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
31     add_compile_options(
32         -Wall
33         -Wcast-align
34         -Wextra
35         -Wformat-security
36         -Wno-unknown-pragmas
37         -Wnon-virtual-dtor
38         -Wpedantic
39         -Wundef
40         -fno-common
41         -fstack-protector-strong
42         "$<$<NOT:$<CONFIG:Debug>>:-U_FORTIFY_SOURCE;-D_FORTIFY_SOURCE=2>"
43     )
44
45     # Check for and set linker flags
46     check_and_set_linker_flag("-Wl,-z,relro"    RELRO     LINKER_FLAGS)
47     check_and_set_linker_flag("-Wl,-z,now"      NOW       LINKER_FLAGS)
48     check_and_set_linker_flag("-Wl,--as-needed" AS_NEEDED LINKER_FLAGS)
49
50     set(CMAKE_EXE_LINKER_FLAGS    "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
51     set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")
52     set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
53 else()
54     # For other compilers, we rely on default settings (unless someone provides a good set of options; patches welcome!)
55 endif()
56
57 # Mac build stuff
58 if (APPLE AND DEPLOY)
59     set(CMAKE_OSX_ARCHITECTURES "x86_64")
60     add_compile_options(
61         -mmacosx-version-min=10.9
62         -stdlib=libc++
63     )
64 endif()