1include(CheckCXXCompilerFlag)
2
3SET(CB_CLANGXX_DEBUG "-g")
4SET(CB_CLANGXX_WARNINGS "-Qunused-arguments -Wall -pedantic -Wredundant-decls -Wmissing-braces -fno-strict-aliasing")
5SET(CB_CLANGXX_VISIBILITY "-fvisibility=hidden")
6SET(CB_CLANGXX_THREAD "-pthread")
7
8# We want RelWithDebInfo to have the same optimization level as
9# Release, only differing in whether debugging information is enabled.
10SET(CMAKE_CXX_FLAGS_RELEASE        "-O3 -DNDEBUG")
11SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -g")
12
13# Make use of -Og (optimize for debugging) if available (Clang 4.0 upwards)
14check_cxx_compiler_flag(-Og HAVE_OPTIMIZE_FOR_DEBUG)
15if(HAVE_OPTIMIZE_FOR_DEBUG)
16   SET(CMAKE_CXX_FLAGS_DEBUG "-Og -g")
17else()
18   SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
19endif()
20
21SET(CB_CXX_FLAGS_NO_OPTIMIZE       -O0)
22
23IF ("${ENABLE_WERROR}" STREQUAL "YES")
24   SET(CB_CLANGXX_WERROR "-Werror")
25ELSE()
26   # We've fixed all occurrences for the following warnings and don't want
27   # any new ones to appear
28   SET(CB_CLANGXX_WERROR "-Werror=switch")
29ENDIF()
30
31if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.1)
32  SET(CB_CXX_LANG_VER "")
33  MESSAGE(WARNING "The C++ compiler is too old and don't support C++11")
34ELSE ()
35  SET(COMPILER_SUPPORTS_CXX11 true)
36  SET(CB_CXX_LANG_VER "-std=c++11")
37  SET(CB_GNU_CXX11_OPTION "-std=gnu++11")
38  # Increase the template-depth to be the same as the g++ default.
39  SET(CB_CLANGXX_TEMPLATE_DEPTH "-ftemplate-depth=900")
40ENDIF()
41
42INCLUDE(CouchbaseCXXVersion)
43
44FOREACH(dir ${CB_SYSTEM_HEADER_DIRS})
45   SET(CB_CLANGXX_IGNORE_HEADER "${CB_CLANGXX_IGNORE_HEADER} -isystem ${dir}")
46ENDFOREACH(dir ${CB_SYSTEM_HEADER_DIRS})
47
48IF (CB_CODE_COVERAGE)
49    SET(CB_CLANGXX_COVERAGE "--coverage  -fprofile-instr-generate -fcoverage-mapping")
50ENDIF ()
51
52SET(CMAKE_CXX_FLAGS "${CB_CLANGXX_IGNORE_HEADER} ${CMAKE_CXX_FLAGS} ${CB_CXX_LANG_VER} ${CB_CLANGXX_DEBUG} ${CB_CLANGXX_WARNINGS} ${CB_CLANGXX_VISIBILITY} ${CB_CLANGXX_THREAD} ${CB_CLANGXX_WERROR} ${CB_CLANGXX_TEMPLATE_DEPTH} ${CB_CLANGXX_COVERAGE}")
53
54# Enable color diagnostic output when using Ninja build generator
55# (Clang fails to auto-detect it can use color).
56IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_GENERATOR STREQUAL "Ninja")
57   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
58ENDIF()
59