5 ## Request full debugging flags
7 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -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_C_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 if(enable_compile_warnings)
33 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 ")
34 if(CMAKE_COMPILER_IS_GNUCC)
35 set(warnCFLAGS "${warnCFLAGS}-Wclobbered -Wno-error=clobbered ")
38 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")
39 if(CMAKE_COMPILER_IS_GNUCXX)
40 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wclobbered -Wno-error=clobbered")
43 set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wall") # FIXME: Q&D hack
45 set(CMAKE_JAVA_COMPILE_FLAGS "-Xlint")
48 if(enable_compile_optimizations)
49 set(optCFLAGS "-O3 -funroll-loops -fno-strict-aliasing ")
50 if(CMAKE_COMPILER_IS_GNUCC AND (NOT enable_model-checking))
51 set(optCFLAGS "${optCFLAGS} -finline-functions ")
53 if (COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.7")
54 # On windows, we need 4.8 or higher to enable lto because of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50293
55 set(optCFLAGS "${optCFLAGS} -flto ")
58 # On non-windows, 4.6 is enough for that
59 if(LINKER_VERSION STRGREATER "2.22")
60 set(optCFLAGS "${optCFLAGS} -flto ")
69 add_definitions(-DUSE_SDT)
73 add_definitions(-DUSE_UST)
76 if(enable_model-checking AND enable_compile_optimizations)
77 # Forget it, do not optimize the code (because it confuses the MC):
79 # But you can still optimize this:
82 src/xbt/log.c src/xbt/xbt_log_appender_file.c
83 src/xbt/xbt_log_layout_format.c src/xbt/xbt_log_layout_simple.c
84 src/xbt/dict.c src/xbt/dict_elm.c src/xbt/dict_multi.c src/xbt/dict_cursor.c
85 src/xbt/set.c src/xbt/setset.c
86 src/xbt/dynar.c src/xbt/fifo.c src/xbt/heap.c src/xbt/swag.c
87 src/xbt/str.c src/xbt/strbuff.c src/xbt/snprintf.c
89 src/xbt/xbt_os_time.c src/xbt/xbt_os_thread.c
92 src/xbt/backtrace_linux.c
93 ${MC_SRC_BASE} ${MC_SRC})
94 set (mcCFLAGS "-O3 -funroll-loops -fno-strict-aliasing")
95 if(CMAKE_COMPILER_IS_GNUCC)
96 set (mcCFLAGS "${mcCFLAGS} -finline-functions")
98 set_source_files_properties(${s} PROPERTIES COMPILE_FLAGS ${mcCFLAGS})
102 if(APPLE AND COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
103 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
104 set(optCFLAGS "-O0 ")
108 set(CMAKE_C_FLAGS "-DNDEBUG ${CMAKE_C_FLAGS}")
109 set(CMAKE_CXX_FLAGS "-DNDEBUG ${CMAKE_CXX_FLAGS}")
112 if(enable_msg_deprecated)
113 set(CMAKE_C_FLAGS "-DMSG_USE_DEPRECATED ${CMAKE_C_FLAGS}")
116 set(CMAKE_C_FLAGS "${optCFLAGS} ${warnCFLAGS} ${CMAKE_C_FLAGS}")
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}")