Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Do not optimize src/xbt/dynar.c
[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   endif()
21
22   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing -Wno-format-nonliteral -Werror")
23
24   set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wall") # FIXME: Q&D hack
25
26   set(CMAKE_JAVA_COMPILE_FLAGS "-Xlint")
27 endif()
28
29 if(enable_compile_optimizations)
30   set(optCFLAGS "-O3 -finline-functions -funroll-loops -fno-strict-aliasing ")
31   if(CMAKE_COMPILER_IS_GNUCC AND (NOT enable_model-checking))
32     if(WIN32)
33       if (COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.7")
34       # On windows, we need 4.8 or higher to enable lto because of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50293
35         set(optCFLAGS "${optCFLAGS} -flto ")
36       endif()
37     else()    
38       # On non-windows, 4.6 is enough for that
39       if(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.5" AND LINKER_VERSION STRGREATER "2.22")
40         set(optCFLAGS "${optCFLAGS} -flto ")
41       endif()
42     endif()
43   endif()
44 else()
45   set(optCFLAGS "-O0 ")
46 endif()
47
48 if(enable_model-checking AND enable_compile_optimizations)
49   # Forget it, do not optimize the code (because it confuses the MC):
50   set(optCFLAGS "-O0 ")
51   # But you can still optimize this:
52   foreach(s
53       src/xbt/mmalloc/mm.c
54       src/xbt/snprintf.c src/xbt/log.c
55       # For some reason, this fails to work when optimizing dynar.c:
56       # src/xbt/dynar.c
57       src/xbt/set.c src/xbt/setset.c src/xbt/backtrace_linux.c
58       src/mc/mc_dwarf_expression.c src/mc/mc_dwarf.c src/mc/mc_member.c
59       src/mc/mc_snapshot.c src/mc/mc_page_store.cpp src/mc/mc_page_snapshot.cpp
60       src/mc/mc_compare.cpp src/mc/mc_diff.c
61       src/mc/mc_dwarf.c src/mc/mc_dwarf_attrnames.h src/mc/mc_dwarf_expression.c src/mc/mc_dwarf_tagnames.h
62       src/mc/mc_set.cpp)
63     set_source_files_properties(${s} PROPERTIES COMPILE_FLAGS "-O3 -finline-functions -funroll-loops -fno-strict-aliasing")
64   endforeach()
65 endif()
66
67 if(APPLE AND COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
68   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
69   set(optCFLAGS "-O0 ")
70 endif()
71
72 if(NOT enable_debug)
73   set(CMAKE_C_FLAGS "-DNDEBUG ${CMAKE_C_FLAGS}")
74 endif()
75
76 if(enable_msg_deprecated)
77   set(CMAKE_C_FLAGS "-DMSG_USE_DEPRECATED ${CMAKE_C_FLAGS}")
78 endif()
79
80 set(CMAKE_C_FLAGS "${optCFLAGS}${warnCFLAGS}${CMAKE_C_FLAGS}")
81
82 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${optCFLAGS}")
83
84 # Try to make Mac a bit more complient to open source standards
85 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
86   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE")
87 endif()
88
89 set(TESH_OPTION "")
90 if(enable_coverage)
91   find_program(GCOV_PATH gcov)
92   if(GCOV_PATH)
93     set(COVERAGE_COMMAND "${GCOV_PATH}" CACHE TYPE FILEPATH FORCE)
94     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOVERAGE")
95     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
96     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
97     set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fprofile-arcs -ftest-coverage")
98     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
99     set(TESH_OPTION --enable-coverage)
100     add_definitions(-fprofile-arcs -ftest-coverage)
101   endif()
102 endif()
103
104 if(NOT $ENV{CFLAGS} STREQUAL "")
105   message(STATUS "Add CFLAGS: \"$ENV{CFLAGS}\" to CMAKE_C_FLAGS")
106   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{CFLAGS}")
107 endif()
108
109 if(NOT $ENV{CXXFLAGS} STREQUAL "")
110   message(STATUS "Add CXXFLAGS: \"$ENV{CXXFLAGS}\" to CMAKE_CXX_FLAGS")
111   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXXFLAGS}")
112 endif()
113
114 if(NOT $ENV{LDFLAGS} STREQUAL "")
115   message(STATUS "Add LDFLAGS: \"$ENV{LDFLAGS}\" to CMAKE_C_LINK_FLAGS")
116   set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} $ENV{LDFLAGS}")
117 endif()