Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
6a10c8fb9e0a40daf01c30b1cd5c87f939535cba
[simgrid.git] / buildtools / Cmake / Flags.cmake
1 set(warnCFLAGS "")
2 set(optCFLAGS "")
3
4 if(NOT __VISUALC__ AND NOT __BORLANDC__)
5   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-g3")
6   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-g3")
7 else(NOT __VISUALC__ AND NOT __BORLANDC__)
8   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}/Zi")
9   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}/Zi")
10 endif(NOT __VISUALC__ AND NOT __BORLANDC__)
11
12 if(enable_compile_warnings)
13   set(warnCFLAGS "-fno-common -Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wcomment -Wformat -Wwrite-strings -Wclobbered -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing -Wno-format-nonliteral -Werror ")
14   if(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.5")
15     set(warnCFLAGS "${warnCFLAGS}-Wno-error=unused-but-set-variable ")
16   else(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.5")
17     set(warnCFLAGS "${warnCFLAGS}-Wno-error=clobbered ")
18   endif(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.5")
19 endif(enable_compile_warnings)
20
21 if(enable_compile_optimizations)
22   set(optCFLAGS "-O3 -finline-functions -funroll-loops -fno-strict-aliasing ")
23   if(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.5")
24     set(optCFLAGS "${optCFLAGS}-flto ")
25   endif(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.5")
26 else(enable_compile_optimizations)
27   set(optCFLAGS "-O0 ")
28 endif(enable_compile_optimizations)
29
30 if(APPLE AND COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
31   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
32   set(optCFLAGS "-O0 ")
33 endif(APPLE AND COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
34
35 if(NOT enable_debug)
36   set(CMAKE_C_FLAGS "-DNDEBUG ${CMAKE_C_FLAGS}")
37 endif(NOT enable_debug)
38
39 if(enable_msg_deprecated)
40   set(CMAKE_C_FLAGS "-DMSG_USE_DEPRECATED ${CMAKE_C_FLAGS}")
41 endif(enable_msg_deprecated)
42
43 set(CMAKE_C_FLAGS "${optCFLAGS}${warnCFLAGS}${CMAKE_C_FLAGS}")
44
45 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${optCFLAGS}")
46
47 # Try to make Mac a bit more complient to open source standards
48 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
49   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE")
50 endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
51
52 set(TESH_OPTION "")
53 if(enable_coverage)
54   find_program(GCOV_PATH gcov)
55   if(GCOV_PATH)
56     SET(COVERAGE_COMMAND "${GCOV_PATH}" CACHE TYPE FILEPATH FORCE)
57     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
58     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
59     set(TESH_OPTION --enable-coverage)
60     add_definitions(-fprofile-arcs -ftest-coverage)
61   endif(GCOV_PATH)
62 endif(enable_coverage)
63
64 if(NOT $ENV{CFLAGS} STREQUAL "")
65   message(STATUS "Add CFLAGS: \"$ENV{CFLAGS}\" to CMAKE_C_FLAGS")
66   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{CFLAGS}")
67 endif(NOT $ENV{CFLAGS} STREQUAL "")
68
69 if(NOT $ENV{LDFLAGS} STREQUAL "")
70   message(STATUS "Add LDFLAGS: \"$ENV{LDFLAGS}\" to CMAKE_C_LINK_FLAGS")
71   set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} $ENV{LDFLAGS}")
72 endif(NOT $ENV{LDFLAGS} STREQUAL "")
73
74 if(enable_model-checking AND enable_compile_optimizations)
75   message(WARNING "Sorry for now GCC optimizations does not work with model checking.\nPlease turn off optimizations with command:\ncmake -Denable_compile_optimizations=off. ")
76 endif(enable_model-checking AND enable_compile_optimizations)