Logo AND Algorithmique Numérique Distribuée

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