2 ## This file is in charge of setting our paranoid flags with regard to warnings and optimization.
4 ## These flags do break some classical CMake tests, so you don't
5 ## want to do so before the very end of the configuration.
7 ## Other compiler flags (C/C++ standard version) are tested and set
8 ## by the beginning of the configuration, directly in ~/CMakeList.txt
15 if(enable_compile_warnings)
16 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 ")
17 if(CMAKE_COMPILER_IS_GNUCC)
18 set(warnCFLAGS "${warnCFLAGS}-Wclobbered -Wno-error=clobbered ")
21 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wunused -Wpointer-arith -Wchar-subscripts -Wcomment -Wformat -Wwrite-strings -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing -Wno-format-nonliteral -Werror")
22 if(CMAKE_COMPILER_IS_GNUCXX)
23 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wclobbered -Wno-error=clobbered")
25 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # don't care about class that become struct
26 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-mismatched-tags")
29 set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wall") # FIXME: Q&D hack
31 set(CMAKE_JAVA_COMPILE_FLAGS "-Xlint")
34 if(enable_compile_optimizations)
35 set(optCFLAGS "-O3 -funroll-loops -fno-strict-aliasing ")
36 if(CMAKE_COMPILER_IS_GNUCC AND (NOT enable_model-checking))
37 set(optCFLAGS "${optCFLAGS} -finline-functions ")
39 if (COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.7")
40 # On windows, we need 4.8 or higher to enable lto because of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50293
41 set(optCFLAGS "${optCFLAGS} -flto ")
44 # On non-windows, 4.6 is enough for that
45 if(LINKER_VERSION STRGREATER "2.22")
46 set(optCFLAGS "${optCFLAGS} -flto ")
55 add_definitions(-DUSE_SDT)
59 add_definitions(-DUSE_UST)
62 if(enable_model-checking AND enable_compile_optimizations)
63 # Forget it, do not optimize the code (because it confuses the MC):
65 # But you can still optimize this:
68 src/xbt/log.c src/xbt/xbt_log_appender_file.c
69 src/xbt/xbt_log_layout_format.c src/xbt/xbt_log_layout_simple.c
70 src/xbt/dict.c src/xbt/dict_elm.c src/xbt/dict_multi.c src/xbt/dict_cursor.c
71 src/xbt/set.c src/xbt/setset.c
72 src/xbt/dynar.c src/xbt/fifo.c src/xbt/heap.c src/xbt/swag.c
73 src/xbt/str.c src/xbt/strbuff.c src/xbt/snprintf.c
75 src/xbt/xbt_os_time.c src/xbt/xbt_os_thread.c
78 src/xbt/backtrace_linux.c
79 ${MC_SRC_BASE} ${MC_SRC})
80 set (mcCFLAGS "-O3 -funroll-loops -fno-strict-aliasing")
81 if(CMAKE_COMPILER_IS_GNUCC)
82 set (mcCFLAGS "${mcCFLAGS} -finline-functions")
84 set_source_files_properties(${s} PROPERTIES COMPILE_FLAGS ${mcCFLAGS})
88 if(APPLE AND COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
89 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
94 set(CMAKE_C_FLAGS "-DNDEBUG ${CMAKE_C_FLAGS}")
95 set(CMAKE_CXX_FLAGS "-DNDEBUG ${CMAKE_CXX_FLAGS}")
98 if(enable_msg_deprecated)
99 set(CMAKE_C_FLAGS "-DMSG_USE_DEPRECATED ${CMAKE_C_FLAGS}")
102 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${optCFLAGS} ${warnCFLAGS}")
103 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${optCFLAGS}")
105 # Try to make Mac a bit more complient to open source standards
106 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
107 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700 -D_DARWIN_C_SOURCE")
112 find_program(GCOV_PATH gcov)
114 set(COVERAGE_COMMAND "${GCOV_PATH}" CACHE TYPE FILEPATH FORCE)
115 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOVERAGE")
116 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
117 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
118 set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fprofile-arcs -ftest-coverage")
119 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
120 set(TESH_OPTION --enable-coverage)
121 add_definitions(-fprofile-arcs -ftest-coverage)
125 if(NOT $ENV{CFLAGS} STREQUAL "")
126 message(STATUS "Add CFLAGS: \"$ENV{CFLAGS}\" to CMAKE_C_FLAGS")
127 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{CFLAGS}")
130 if(NOT $ENV{CXXFLAGS} STREQUAL "")
131 message(STATUS "Add CXXFLAGS: \"$ENV{CXXFLAGS}\" to CMAKE_CXX_FLAGS")
132 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXXFLAGS}")
135 if(NOT $ENV{LDFLAGS} STREQUAL "")
136 message(STATUS "Add LDFLAGS: \"$ENV{LDFLAGS}\" to CMAKE_C_LINK_FLAGS")
137 set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} $ENV{LDFLAGS}")