2 ## This file is in charge of setting our paranoid flags with regard to warnings and optimization.
4 ## It is only used for gcc and clang. MSVC builds don't load this file.
6 ## These flags do break some classical CMake tests, so you don't
7 ## want to do so before the very end of the configuration.
9 ## Other compiler flags (C/C++ standard version) are tested and set
10 ## by the beginning of the configuration, directly in ~/CMakeList.txt
17 if(enable_compile_warnings)
18 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 ")
19 if(CMAKE_COMPILER_IS_GNUCC)
20 set(warnCFLAGS "${warnCFLAGS}-Wclobbered -Wno-error=clobbered ")
23 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")
24 if(CMAKE_COMPILER_IS_GNUCXX)
25 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wclobbered -Wno-error=clobbered")
27 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # don't care about class that become struct
28 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-mismatched-tags")
31 set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wall")
32 set(CMAKE_JAVA_COMPILE_FLAGS "-Xlint")
35 # Se the optimisation flags
36 # NOTE, we should CMAKE_BUILD_TYPE for this
37 if(enable_compile_optimizations)
38 set(optCFLAGS "-O3 -funroll-loops -fno-strict-aliasing ")
42 if(enable_compile_optimizations AND CMAKE_COMPILER_IS_GNUCC
43 AND (NOT enable_model-checking))
44 # This is redundant (already in -03):
45 set(optCFLAGS "${optCFLAGS} -finline-functions ")
49 # TODO, provide an option to manually choose whether to use LTO
50 # NOTE, cmake 3.0 has a INTERPROCEDURAL_OPTIMIZATION target
51 # property for this (http://www.cmake.org/cmake/help/v3.0/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.html)
53 if(enable_compile_optimizations
54 AND CMAKE_COMPILER_IS_GNUCC
55 AND (NOT enable_model-checking))
57 if (COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.8")
58 # On windows, we need 4.8 or higher to enable lto because of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50293
60 # We are experiencing assertion failures even with 4.8 on MinGW.
61 # Push the support forward: will see if 4.9 works when we test it.
64 elseif(LINKER_VERSION STRGREATER "2.22")
69 set(optCFLAGS "${optCFLAGS} -flto ")
70 # See https://gcc.gnu.org/wiki/LinkTimeOptimizationFAQ#ar.2C_nm_and_ranlib:
71 # "Since version 4.9 gcc produces slim object files that only contain
72 # the intermediate representation. In order to handle archives of
73 # these objects you have to use the gcc wrappers:
74 # gcc-ar, gcc-nm and gcc-ranlib."
75 if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU"
76 AND COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.8")
78 set (CMAKE_RANLIB gcc-ranlib)
82 if(enable_model-checking AND enable_compile_optimizations)
83 # Forget it, do not optimize the code (because it confuses the MC):
85 # But you can still optimize this:
88 src/xbt/log.c src/xbt/xbt_log_appender_file.c
89 src/xbt/xbt_log_layout_format.c src/xbt/xbt_log_layout_simple.c
90 src/xbt/dict.c src/xbt/dict_elm.c src/xbt/dict_multi.c src/xbt/dict_cursor.c
91 src/xbt/set.c src/xbt/setset.c
92 src/xbt/dynar.c src/xbt/fifo.c src/xbt/heap.c src/xbt/swag.c
93 src/xbt/str.c src/xbt/strbuff.c src/xbt/snprintf.c
95 src/xbt/xbt_os_time.c src/xbt/xbt_os_thread.c
98 src/xbt/backtrace_linux.c
99 ${MC_SRC_BASE} ${MC_SRC})
100 set (mcCFLAGS "-O3 -funroll-loops -fno-strict-aliasing")
101 if(CMAKE_COMPILER_IS_GNUCC)
102 set (mcCFLAGS "${mcCFLAGS} -finline-functions")
104 set_source_files_properties(${s} PROPERTIES COMPILE_FLAGS ${mcCFLAGS})
109 set(CMAKE_C_FLAGS "-DNDEBUG ${CMAKE_C_FLAGS}")
110 set(CMAKE_CXX_FLAGS "-DNDEBUG ${CMAKE_CXX_FLAGS}")
113 if(enable_msg_deprecated)
114 set(CMAKE_C_FLAGS "-DMSG_USE_DEPRECATED ${CMAKE_C_FLAGS}")
117 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${optCFLAGS} ${warnCFLAGS}")
118 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${optCFLAGS}")
120 # Try to make Mac a bit more complient to open source standards
121 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
122 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700 -D_DARWIN_C_SOURCE")
127 find_program(GCOV_PATH gcov)
129 set(COVERAGE_COMMAND "${GCOV_PATH}" CACHE TYPE FILEPATH FORCE)
130 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOVERAGE")
131 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
132 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
133 set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fprofile-arcs -ftest-coverage")
134 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
135 set(TESH_OPTION --enable-coverage)
136 add_definitions(-fprofile-arcs -ftest-coverage)
140 if(NOT $ENV{CFLAGS} STREQUAL "")
141 message(STATUS "Add CFLAGS: \"$ENV{CFLAGS}\" to CMAKE_C_FLAGS")
142 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{CFLAGS}")
145 if(NOT $ENV{CXXFLAGS} STREQUAL "")
146 message(STATUS "Add CXXFLAGS: \"$ENV{CXXFLAGS}\" to CMAKE_CXX_FLAGS")
147 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXXFLAGS}")
150 if(NOT $ENV{LDFLAGS} STREQUAL "")
151 message(STATUS "Add LDFLAGS: \"$ENV{LDFLAGS}\" to CMAKE_C_LINK_FLAGS")
152 set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} $ENV{LDFLAGS}")