5 ## Request full debugging flags
7 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
8 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
9 set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g")
12 ## We need a decent support of the c++11 standard
14 include(CheckCXXCompilerFlag)
15 CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
16 if(COMPILER_SUPPORTS_CXX11)
17 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
20 "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. "
21 "Please use a decent C++ compiler.")
23 if (CMAKE_COMPILER_IS_GNUCC)
24 if (COMPILER_CXX_VERSION_MAJOR_MINOR STRLESS "4.7")
26 "SimGrid needs g++ version 4.7 to compile "
27 "(c++11 support of previous versions is too limited).")
32 ### And we need C11 standard, too
34 include(CheckCCompilerFlag)
35 CHECK_C_COMPILER_FLAG("-std=gnu11" COMPILER_SUPPORTS_C11)
36 if(COMPILER_SUPPORTS_C11)
37 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
40 "The compiler ${CMAKE_C_COMPILER} has no C11 support. "
41 "Please use a decent C compiler "
42 "(note that c++11 support of ${CMAKE_CXX_COMPILER} seems ok).")
46 if(enable_compile_warnings)
47 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 ")
48 if(CMAKE_COMPILER_IS_GNUCC)
49 set(warnCFLAGS "${warnCFLAGS}-Wclobbered -Wno-error=clobbered ")
52 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")
53 if(CMAKE_COMPILER_IS_GNUCXX)
54 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wclobbered -Wno-error=clobbered")
57 set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wall") # FIXME: Q&D hack
59 set(CMAKE_JAVA_COMPILE_FLAGS "-Xlint")
62 if(enable_compile_optimizations)
63 set(optCFLAGS "-O3 -funroll-loops -fno-strict-aliasing ")
64 if(CMAKE_COMPILER_IS_GNUCC AND (NOT enable_model-checking))
65 set(optCFLAGS "${optCFLAGS} -finline-functions ")
67 if (COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.7")
68 # On windows, we need 4.8 or higher to enable lto because of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50293
69 set(optCFLAGS "${optCFLAGS} -flto ")
72 # On non-windows, 4.6 is enough for that
73 if(LINKER_VERSION STRGREATER "2.22")
74 set(optCFLAGS "${optCFLAGS} -flto ")
83 add_definitions(-DUSE_SDT)
87 add_definitions(-DUSE_UST)
90 if(enable_model-checking AND enable_compile_optimizations)
91 # Forget it, do not optimize the code (because it confuses the MC):
93 # But you can still optimize this:
96 src/xbt/log.c src/xbt/xbt_log_appender_file.c
97 src/xbt/xbt_log_layout_format.c src/xbt/xbt_log_layout_simple.c
98 src/xbt/dict.c src/xbt/dict_elm.c src/xbt/dict_multi.c src/xbt/dict_cursor.c
99 src/xbt/set.c src/xbt/setset.c
100 src/xbt/dynar.c src/xbt/fifo.c src/xbt/heap.c src/xbt/swag.c
101 src/xbt/str.c src/xbt/strbuff.c src/xbt/snprintf.c
103 src/xbt/xbt_os_time.c src/xbt/xbt_os_thread.c
106 src/xbt/backtrace_linux.c
107 ${MC_SRC_BASE} ${MC_SRC})
108 set (mcCFLAGS "-O3 -funroll-loops -fno-strict-aliasing")
109 if(CMAKE_COMPILER_IS_GNUCC)
110 set (mcCFLAGS "${mcCFLAGS} -finline-functions")
112 set_source_files_properties(${s} PROPERTIES COMPILE_FLAGS ${mcCFLAGS})
116 if(APPLE AND COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
117 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
118 set(optCFLAGS "-O0 ")
122 set(CMAKE_C_FLAGS "-DNDEBUG ${CMAKE_C_FLAGS}")
123 set(CMAKE_CXX_FLAGS "-DNDEBUG ${CMAKE_CXX_FLAGS}")
126 if(enable_msg_deprecated)
127 set(CMAKE_C_FLAGS "-DMSG_USE_DEPRECATED ${CMAKE_C_FLAGS}")
130 set(CMAKE_C_FLAGS "${optCFLAGS} ${warnCFLAGS} ${CMAKE_C_FLAGS}")
132 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${optCFLAGS}")
134 # Try to make Mac a bit more complient to open source standards
135 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
136 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700 -D_DARWIN_C_SOURCE")
141 find_program(GCOV_PATH gcov)
143 set(COVERAGE_COMMAND "${GCOV_PATH}" CACHE TYPE FILEPATH FORCE)
144 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOVERAGE")
145 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
146 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
147 set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fprofile-arcs -ftest-coverage")
148 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
149 set(TESH_OPTION --enable-coverage)
150 add_definitions(-fprofile-arcs -ftest-coverage)
154 if(NOT $ENV{CFLAGS} STREQUAL "")
155 message(STATUS "Add CFLAGS: \"$ENV{CFLAGS}\" to CMAKE_C_FLAGS")
156 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{CFLAGS}")
159 if(NOT $ENV{CXXFLAGS} STREQUAL "")
160 message(STATUS "Add CXXFLAGS: \"$ENV{CXXFLAGS}\" to CMAKE_CXX_FLAGS")
161 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXXFLAGS}")
164 if(NOT $ENV{LDFLAGS} STREQUAL "")
165 message(STATUS "Add LDFLAGS: \"$ENV{LDFLAGS}\" to CMAKE_C_LINK_FLAGS")
166 set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} $ENV{LDFLAGS}")