Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot//simgrid/simgrid
[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}-std=gnu99 -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     if(COMPILER_C_VERSION_MAJOR_MINOR STREQUAL "4.6")
21     #some old compilers emit bogus warnings here, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45978 . Avoid failing the build in this case
22       set(warnCFLAGS "${warnCFLAGS}-Wno-error=array-bounds")
23     endif()
24   endif()
25
26   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra  -Wunused -Wpointer-arith -Wchar-subscripts -Wcomment -Wno-unknown-warning-option -Wformat -Wwrite-strings -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing -Wclobbered -Wno-error=clobbered -Wno-format-nonliteral -Werror")
27
28   set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wall") # FIXME: Q&D hack
29
30   set(CMAKE_JAVA_COMPILE_FLAGS "-Xlint")
31 endif()
32
33 if(enable_compile_optimizations)
34   set(optCFLAGS "-O3 -funroll-loops -fno-strict-aliasing ")
35   if(CMAKE_COMPILER_IS_GNUCC AND (NOT enable_model-checking))
36     set(optCFLAGS "${optCFLAGS} -finline-functions ")
37     if(WIN32)
38       if (COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.7")
39       # On windows, we need 4.8 or higher to enable lto because of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50293
40         set(optCFLAGS "${optCFLAGS} -flto ")
41       endif()
42     else()    
43       # On non-windows, 4.6 is enough for that
44       if(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.5" AND LINKER_VERSION STRGREATER "2.22")
45         set(optCFLAGS "${optCFLAGS} -flto ")
46       endif()
47     endif()
48   endif()
49 else()
50   set(optCFLAGS "-O0 ")
51 endif()
52
53 if(enable_sdt)
54   add_definitions(-DUSE_SDT)
55 endif()
56
57 if(enable_ust)
58   add_definitions(-DUSE_UST)
59 endif()
60
61 if(enable_model-checking AND enable_compile_optimizations)
62   # Forget it, do not optimize the code (because it confuses the MC):
63   set(optCFLAGS "-O0 ")
64   # But you can still optimize this:
65   foreach(s
66       # src/xbt/mmalloc/mm.c
67       # src/xbt/snprintf.c src/xbt/log.c
68       # src/xbt/dynar.c
69       # src/xbt/set.c src/xbt/setset.c
70       # src/xbt/backtrace_linux.c
71       src/mc/mc_dwarf_expression.c src/mc/mc_dwarf.c src/mc/mc_member.c
72       src/mc/mc_snapshot.c src/mc/mc_page_store.cpp src/mc/mc_page_snapshot.cpp
73       src/mc/mc_compare.cpp src/mc/mc_diff.c
74       src/mc/mc_dwarf.c src/mc/mc_dwarf_attrnames.h src/mc/mc_dwarf_expression.c src/mc/mc_dwarf_tagnames.h
75       src/mc/mc_set.cpp)
76       set (mcCFLAGS "-O3  -funroll-loops -fno-strict-aliasing")
77        if(CMAKE_COMPILER_IS_GNUCC)
78          set (mcCFLAGS "${mcCFLAGS} -finline-functions")
79       endif()
80       set_source_files_properties(${s} PROPERTIES COMPILE_FLAGS ${mcCFLAGS})
81   endforeach()
82 endif()
83
84 if(enable_mc_content_adressable_pages)
85   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMC_PAGE_STORE_MD4")
86   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMC_PAGE_STORE_MD4")
87 endif()
88
89 if(APPLE AND COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
90   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
91   set(optCFLAGS "-O0 ")
92 endif()
93
94 if(NOT enable_debug)
95   set(CMAKE_C_FLAGS "-DNDEBUG ${CMAKE_C_FLAGS}")
96   set(CMAKE_CXX_FLAGS "-DNDEBUG ${CMAKE_CXX_FLAGS}")
97 endif()
98
99 if(enable_msg_deprecated)
100   set(CMAKE_C_FLAGS "-DMSG_USE_DEPRECATED ${CMAKE_C_FLAGS}")
101 endif()
102
103 set(CMAKE_C_FLAGS "${optCFLAGS} ${warnCFLAGS} ${CMAKE_C_FLAGS}")
104
105 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${optCFLAGS}")
106
107 # Try to make Mac a bit more complient to open source standards
108 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
109   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE")
110 endif()
111
112 set(TESH_OPTION "")
113 if(enable_coverage)
114   find_program(GCOV_PATH gcov)
115   if(GCOV_PATH)
116     set(COVERAGE_COMMAND "${GCOV_PATH}" CACHE TYPE FILEPATH FORCE)
117     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOVERAGE")
118     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
119     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
120     set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fprofile-arcs -ftest-coverage")
121     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
122     set(TESH_OPTION --enable-coverage)
123     add_definitions(-fprofile-arcs -ftest-coverage)
124   endif()
125 endif()
126
127 if(NOT $ENV{CFLAGS} STREQUAL "")
128   message(STATUS "Add CFLAGS: \"$ENV{CFLAGS}\" to CMAKE_C_FLAGS")
129   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{CFLAGS}")
130 endif()
131
132 if(NOT $ENV{CXXFLAGS} STREQUAL "")
133   message(STATUS "Add CXXFLAGS: \"$ENV{CXXFLAGS}\" to CMAKE_CXX_FLAGS")
134   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXXFLAGS}")
135 endif()
136
137 if(NOT $ENV{LDFLAGS} STREQUAL "")
138   message(STATUS "Add LDFLAGS: \"$ENV{LDFLAGS}\" to CMAKE_C_LINK_FLAGS")
139   set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} $ENV{LDFLAGS}")
140 endif()