600f9293828e8aca1a3f6f49309ee4c051e45b9f
[oonf.git] / CMake.flags
1 include(CheckCCompilerFlag)
2
3 # define a function that checks if a certain compiler flag is available
4 # use it if it is available, display a warning if not
5 function(add_compiler_flag flag)
6     check_c_compiler_flag(${flag} test${flag})
7     if (${test${flag}})
8         ADD_DEFINITIONS(${flag})
9     endif()
10 endfunction(add_compiler_flag)
11
12 # allow to remove parts of the logging/helptext for smaller executable
13 IF (OONF_REMOVE_DEBUG_LOGGING)
14     ADD_DEFINITIONS(-DREMOVE_LOG_DEBUG)
15 ENDIF (OONF_REMOVE_DEBUG_LOGGING)
16 IF (OONF_REMOVE_INFO_LOGGING)
17     ADD_DEFINITIONS(-DREMOVE_LOG_INFO)
18 ENDIF (OONF_REMOVE_INFO_LOGGING)
19 IF (OONF_REMOVE_WARN_LOGGING)
20     ADD_DEFINITIONS(-DREMOVE_LOG_WARN)
21 ENDIF (OONF_REMOVE_WARN_LOGGING)
22
23 IF (OONF_REMOVE_HELPTEXT)
24     ADD_DEFINITIONS(-DREMOVE_HELPTEXT)
25 ENDIF(OONF_REMOVE_HELPTEXT)
26
27 # set preprocessor variables for level of root access the app needs
28 IF (${OONF_NEEDS_ROOT} MATCHES "true")
29     ADD_DEFINITIONS(-DNEED_ROOT=2)
30 ENDIF (${OONF_NEEDS_ROOT} MATCHES "true")
31 IF (${OONF_NEEDS_ROOT} MATCHES "apply")
32     ADD_DEFINITIONS(-DNEED_ROOT=1)
33 ENDIF (${OONF_NEEDS_ROOT} MATCHES "apply")
34
35 # OS-specific settings
36 IF(ANDROID OR WIN32)
37     # Android and windows don't compile well with c99
38     ADD_DEFINITIONS(-std=gnu99)
39 ELSE(ANDROID OR WIN32)
40     # everything else does
41     ADD_DEFINITIONS(-std=c99 -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D__BSD_VISIBLE -D_DARWIN_C_SOURCE -D__KERNEL_STRICT_NAMES)
42 ENDIF (ANDROID OR WIN32)
43
44 # default configuration file
45 IF (NOT EXISTS ${OONF_DEFAULT_CONF})
46   # generate OLSRd default config file
47   IF(WIN32)
48     # windows default config file is in the same directory,
49     # it has the same name as the executable, just replaced the .exe
50     # with .conf 
51     string(REPLACE ".exe" ".conf" OONF_DEFAULT_CONF "${OONF_EXE}")
52   ELSE(WIN32)
53     # unix default config file is /etc/<executable-name>.conf
54     set (OONF_DEFAULT_CONF "/etc/${OONF_APP}.conf")
55   ENDIF(WIN32)
56     STRING(TOLOWER ${OONF_DEFAULT_CONF} OONF_DEFAULT_CONF)
57 ENDIF()
58
59 # add some necessary additions for win32
60 IF (WIN32)
61     ADD_DEFINITIONS(-D_WIN32_WINNT=0x0502)
62     SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-auto-import")
63 ENDIF(WIN32)
64
65 # set compiler flags that are supported
66 add_compiler_flag(-finline-functions-called-once)
67 add_compiler_flag(-funit-at-a-time)
68 add_compiler_flag(-fearly-inlining)
69 add_compiler_flag(-fno-strict-aliasing)
70 add_compiler_flag(-finline-limit=350)
71 add_compiler_flag(-Wstrict-overflow=5)
72 add_compiler_flag(-fvisibility=hidden)
73
74 add_compiler_flag(-Wall)
75 add_compiler_flag(-Wextra)
76 add_compiler_flag(-Wold-style-definition)
77 add_compiler_flag(-Wdeclaration-after-statement)
78 add_compiler_flag(-Wmissing-prototypes)
79 add_compiler_flag(-Wstrict-prototypes)
80 add_compiler_flag(-Wmissing-declarations)
81 add_compiler_flag(-Wsign-compare)
82 add_compiler_flag(-Waggregate-return)
83 add_compiler_flag(-Wmissing-noreturn)
84 add_compiler_flag(-Wmissing-format-attribute)
85 add_compiler_flag(-Wno-multichar)
86 add_compiler_flag(-Wno-deprecated-declarations)
87 add_compiler_flag(-Wendif-labels)
88 add_compiler_flag(-Wwrite-strings)
89 add_compiler_flag(-Wbad-function-cast)
90 add_compiler_flag(-Wpointer-arith)
91 add_compiler_flag(-Wno-cast-qual)
92 add_compiler_flag(-Wshadow)
93 add_compiler_flag(-Wsequence-point)
94 add_compiler_flag(-Wpointer-arith)
95 add_compiler_flag(-Wnested-externs)
96 add_compiler_flag(-Winline)
97 add_compiler_flag(-Wdisabled-optimization)
98 add_compiler_flag(-Wformat)
99 add_compiler_flag(-Wformat-security)