-
- # Let's just hope that all gccs support these options and skip the tests...
- # -fno-strict-aliasing is needed apparently for Qt < 4.6
- 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")
- # 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 "${CMAKE_CXX_FLAGS} -Woverloaded-virtual")
- endif()
-
- # Just for miniz
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-function -Wno-undef -fno-strict-aliasing")
-
-# ... and for Clang
-elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
- if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.1")
- message(WARNING "Your compiler is too old; we expect at least Clang 3.1. Your build will likely fail.")
- endif()
-
- 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")
- # 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")
-
-# For MSVC, at least do a version sanity check
-elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
- if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "18.0")
- message(WARNING "Your compiler is too old; we expect at least Visual Studio Nov 2013 CTP (MSVC 18). Your build will likely fail.")
- endif()
-
-# Unknown/unsupported compiler
+ cmake_pop_check_state()
+endfunction()
+
+# General compile settings
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED OFF) # Rely on compile features if standard is not supported
+set(CMAKE_CXX_EXTENSIONS OFF) # We like to be standard conform
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+
+# For GCC and Clang, enable a whole bunch of warnings
+if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
+ add_compile_options(
+ -Wall
+ -Wcast-align
+ -Wextra
+ -Wformat-security
+ -Wno-unknown-pragmas
+ -Wnon-virtual-dtor
+ -Wpedantic
+ -Wundef
+ -fno-common
+ -fstack-protector-strong
+ -fvisibility=default
+ -fvisibility-inlines-hidden
+ "$<$<NOT:$<CONFIG:Debug>>:-U_FORTIFY_SOURCE;-D_FORTIFY_SOURCE=2>"
+ )
+
+ # Check for and set linker flags
+ check_and_set_linker_flag("-Wl,-z,relro" RELRO LINKER_FLAGS)
+ check_and_set_linker_flag("-Wl,-z,now" NOW LINKER_FLAGS)
+ check_and_set_linker_flag("-Wl,--as-needed" AS_NEEDED LINKER_FLAGS)
+
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
+ set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")