Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge commit '045db1657e870c721be490b411868f4181a12ced' into surf++
[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 -Wclobbered -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing -Wno-format-nonliteral -Werror -Wno-error=clobbered ")
15   if(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.5")
16     set(warnCFLAGS "${warnCFLAGS}-Wno-error=unused-but-set-variable ")
17   endif()
18   if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
19     string(REPLACE "-Wclobbered " "" warnCFLAGS "${warnCFLAGS}")
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(WIN32)
30     if (COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.7")
31     # On windows, we need 4.8 or higher to enable lto because of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50293
32       set(optCFLAGS "${optCFLAGS} -flto ")
33     endif()
34   else()    
35     # On non-windows, 4.6 is enough for that
36     if(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.5")
37       set(optCFLAGS "${optCFLAGS} -flto ")
38     endif()
39   endif()
40 else()
41   set(optCFLAGS "-O0 ")
42 endif()
43
44 if(APPLE AND COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
45   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
46   set(optCFLAGS "-O0 ")
47 endif()
48
49 if(NOT enable_debug)
50   set(CMAKE_C_FLAGS "-DNDEBUG ${CMAKE_C_FLAGS}")
51 endif()
52
53 if(enable_msg_deprecated)
54   set(CMAKE_C_FLAGS "-DMSG_USE_DEPRECATED ${CMAKE_C_FLAGS}")
55 endif()
56
57 set(CMAKE_C_FLAGS "${optCFLAGS}${warnCFLAGS}${CMAKE_C_FLAGS}")
58
59 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${optCFLAGS}")
60
61 # Try to make Mac a bit more complient to open source standards
62 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
63   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE")
64 endif()
65
66 set(TESH_OPTION "")
67 if(enable_coverage)
68   find_program(GCOV_PATH gcov)
69   if(GCOV_PATH)
70     SET(COVERAGE_COMMAND "${GCOV_PATH}" CACHE TYPE FILEPATH FORCE)
71     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOVERAGE")
72     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
73     set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fprofile-arcs -ftest-coverage")
74     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
75     set(TESH_OPTION --enable-coverage)
76     add_definitions(-fprofile-arcs -ftest-coverage)
77   endif()
78 endif()
79
80 if(NOT $ENV{CFLAGS} STREQUAL "")
81   message(STATUS "Add CFLAGS: \"$ENV{CFLAGS}\" to CMAKE_C_FLAGS")
82   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{CFLAGS}")
83 endif()
84
85 if(NOT $ENV{LDFLAGS} STREQUAL "")
86   message(STATUS "Add LDFLAGS: \"$ENV{LDFLAGS}\" to CMAKE_C_LINK_FLAGS")
87   set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} $ENV{LDFLAGS}")
88 endif()
89
90 if(enable_model-checking AND enable_compile_optimizations)
91   message(WARNING "Sorry for now GCC optimizations does not work with model checking.\nPlease turn off optimizations with command:\ncmake -Denable_compile_optimizations=off .")
92 endif()