File: DefineCompilerFlags.cmake

package info (click to toggle)
cgreen 1.6.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,588 kB
  • sloc: ansic: 12,276; sh: 558; makefile: 474; cpp: 403; python: 181; xml: 33; sed: 13
file content (70 lines) | stat: -rw-r--r-- 2,444 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# define system dependent compiler flags

include(CheckCCompilerFlag)

set (COMPILER_IS_CLANG FALSE)
if (${CMAKE_C_COMPILER_ID} MATCHES "Clang")
  set (COMPILER_IS_CLANG TRUE)
endif (${CMAKE_C_COMPILER_ID} MATCHES "Clang")

if (CGREEN_WITH_XML)
  add_definitions(-DHAVE_XML_REPORTER=1)
endif (CGREEN_WITH_XML)

if (CGREEN_WITH_LIBXML2)
  add_definitions(-DHAVE_LIBXML2_REPORTER=1)
endif (CGREEN_WITH_LIBXML2)

if (UNIX)
  if (CMAKE_COMPILER_IS_GNUCC OR COMPILER_IS_CLANG)
    # add_compile_options(-Wall -Wextra -Wunused) # only since CMake 2.8.12, so...
    add_definitions(-Wall -Wextra -Wunused)

    if (CGREEN_WITH_LIBXML2)
      # libxml2 headers depend on ICU library for Unicode support,
      # but ICU headers do not even compile with C++ 98.
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    else ()
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98")
    endif (CGREEN_WITH_LIBXML2)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wstrict-prototypes")

    if (CGREEN_INTERNAL_WITH_GCOV)
      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs")
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs")
      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs")
    endif (CGREEN_INTERNAL_WITH_GCOV)

    add_definitions(-D_REENTRANT)           # for gmtime_r()
    if (NOT ${CMAKE_SYSTEM_NAME} MATCHES ".*OpenBSD.*")
      add_definitions(-D_XOPEN_SOURCE)        # for popen() and pclose()
      add_definitions(-D_XOPEN_SOURCE_EXTENDED) # for strdup(), which isn't part of C99
    endif()
    add_definitions(-D__STDC_FORMAT_MACROS) # for PRI*PTR format macros, required by C99

    if (NOT CYGWIN)
        # with -fPIC
        check_c_compiler_flag("-fPIC" WITH_FPIC)
        if (WITH_FPIC)
            # add_compile_options(-fPIC) # Only since CMake 2.8.12, so...
            add_definitions(-fPIC)
        endif (WITH_FPIC)
    endif (NOT CYGWIN)

    check_c_compiler_flag("-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
    if (WITH_FORTIFY_SOURCE)
      add_definitions(-D_FORTIFY_SOURCE=2)
    endif (WITH_FORTIFY_SOURCE)

    if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
      add_definitions(-O)
    endif ()
  endif (CMAKE_COMPILER_IS_GNUCC OR COMPILER_IS_CLANG)
endif (UNIX)

if (WIN32)
    if (MSVC)
        add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
    endif (MSVC)
endif (WIN32)