Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge XBT_SG_SRC with XBT_SRC, and fix make dist.
[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()
8   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}/Zi")
9   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}/Zi")
10 endif()
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 -Wno-error=clobbered ")
14   if(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.5")
15     set(warnCFLAGS "${warnCFLAGS}-Wno-error=unused-but-set-variable ")
16   endif()
17   if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
18     string(REPLACE "-Wclobbered " "" warnCFLAGS "${warnCFLAGS}")
19   endif()
20 endif()
21
22 if(enable_compile_optimizations)
23   set(optCFLAGS "-O3 -finline-functions -funroll-loops -fno-strict-aliasing ")
24   if(COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.5")
25     set(optCFLAGS "${optCFLAGS}-flto ")
26   endif()
27 else()
28   set(optCFLAGS "-O0 ")
29 endif()
30
31 if(APPLE AND COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
32   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
33   set(optCFLAGS "-O0 ")
34 endif()
35
36 if(NOT enable_debug)
37   set(CMAKE_C_FLAGS "-DNDEBUG ${CMAKE_C_FLAGS}")
38 endif()
39
40 if(enable_msg_deprecated)
41   set(CMAKE_C_FLAGS "-DMSG_USE_DEPRECATED ${CMAKE_C_FLAGS}")
42 endif()
43
44 set(CMAKE_C_FLAGS "${optCFLAGS}${warnCFLAGS}${CMAKE_C_FLAGS}")
45
46 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${optCFLAGS}")
47
48 # Try to make Mac a bit more complient to open source standards
49 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
50   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE")
51 endif()
52
53 set(TESH_OPTION "")
54 if(enable_coverage)
55   find_program(GCOV_PATH gcov)
56   if(GCOV_PATH)
57     SET(COVERAGE_COMMAND "${GCOV_PATH}" CACHE TYPE FILEPATH FORCE)
58     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOVERAGE")
59     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
60     set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fprofile-arcs -ftest-coverage")
61     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
62     set(TESH_OPTION --enable-coverage)
63     add_definitions(-fprofile-arcs -ftest-coverage)
64   endif()
65 endif()
66
67 if(NOT $ENV{CFLAGS} STREQUAL "")
68   message(STATUS "Add CFLAGS: \"$ENV{CFLAGS}\" to CMAKE_C_FLAGS")
69   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{CFLAGS}")
70 endif()
71
72 if(NOT $ENV{LDFLAGS} STREQUAL "")
73   message(STATUS "Add LDFLAGS: \"$ENV{LDFLAGS}\" to CMAKE_C_LINK_FLAGS")
74   set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} $ENV{LDFLAGS}")
75 endif()
76
77 if(enable_model-checking AND enable_compile_optimizations)
78   message(WARNING "Sorry for now GCC optimizations does not work with model checking.\nPlease turn off optimizations with command:\ncmake -Denable_compile_optimizations=off. ")
79 endif()