Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9c37da30466febde04f62c5644e154439f5da848
[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   set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g")
8 else()
9   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}/Zi")
10   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}/Zi")
11 endif()
12
13 if(enable_compile_warnings)
14   set(warnCFLAGS "-fno-common -Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wcomment -Wformat -Wwrite-strings -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing -Wno-format-nonliteral -Werror ")
15   if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
16     set(warnCFLAGS "${warnCFLAGS}-Wclobbered -Wno-error=clobbered ")
17     if(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.5")
18       set(warnCFLAGS "${warnCFLAGS}-Wno-error=unused-but-set-variable ")
19     endif()
20   endif()
21
22   set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wall") # FIXME: Q&D hack
23
24   set(CMAKE_JAVA_COMPILE_FLAGS "-Xlint")
25 endif()
26
27 if(enable_compile_optimizations)
28   set(optCFLAGS "-O3 -finline-functions -funroll-loops -fno-strict-aliasing ")
29   if(CMAKE_COMPILER_IS_GNUCC)
30     if(WIN32)
31       if (COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.7")
32       # On windows, we need 4.8 or higher to enable lto because of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50293
33         set(optCFLAGS "${optCFLAGS} -flto ")
34       endif()
35     else()    
36       # On non-windows, 4.6 is enough for that
37       if(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.5")
38         set(optCFLAGS "${optCFLAGS} -flto ")
39       endif()
40     endif()
41   endif()
42 else()
43   set(optCFLAGS "-O0 ")
44 endif()
45
46 if(APPLE AND COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
47   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
48   set(optCFLAGS "-O0 ")
49 endif()
50
51 if(NOT enable_debug)
52   set(CMAKE_C_FLAGS "-DNDEBUG ${CMAKE_C_FLAGS}")
53 endif()
54
55 if(enable_msg_deprecated)
56   set(CMAKE_C_FLAGS "-DMSG_USE_DEPRECATED ${CMAKE_C_FLAGS}")
57 endif()
58
59 set(CMAKE_C_FLAGS "${optCFLAGS}${warnCFLAGS}${CMAKE_C_FLAGS}")
60
61 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${optCFLAGS}")
62
63 # Try to make Mac a bit more complient to open source standards
64 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
65   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE")
66 endif()
67
68 set(TESH_OPTION "")
69 if(enable_coverage)
70   find_program(GCOV_PATH gcov)
71   if(GCOV_PATH)
72     set(COVERAGE_COMMAND "${GCOV_PATH}" CACHE TYPE FILEPATH FORCE)
73     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOVERAGE")
74     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
75     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
76     set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fprofile-arcs -ftest-coverage")
77     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
78     set(TESH_OPTION --enable-coverage)
79     add_definitions(-fprofile-arcs -ftest-coverage)
80   endif()
81 endif()
82
83 if(NOT $ENV{CFLAGS} STREQUAL "")
84   message(STATUS "Add CFLAGS: \"$ENV{CFLAGS}\" to CMAKE_C_FLAGS")
85   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{CFLAGS}")
86 endif()
87
88 if(NOT $ENV{LDFLAGS} STREQUAL "")
89   message(STATUS "Add LDFLAGS: \"$ENV{LDFLAGS}\" to CMAKE_C_LINK_FLAGS")
90   set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} $ENV{LDFLAGS}")
91 endif()
92
93 if(enable_model-checking AND enable_compile_optimizations)
94   message(WARNING "Sorry for now GCC optimizations does not work with model checking.\nPlease turn off optimizations with command:\ncmake -Denable_compile_optimizations=off .")
95 endif()