4 include(CheckCXXCompilerFlag)
6 if (CMAKE_COMPILER_IS_GNUCC)
7 if (COMPILER_C_VERSION_MAJOR_MINOR STRLESS "4.7")
8 message(FATAL_ERROR "SimGrid needs g++ version 4.7 to compile.")
12 if(NOT __VISUALC__ AND NOT __BORLANDC__)
13 CHECK_CXX_COMPILER_FLAG("-std=gnu++11" HAVE_CXX11)
14 CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" HAVE_CXX0X)
16 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
18 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
20 message(FATAL_ERROR "Missing support for C++11.")
24 if(NOT __VISUALC__ AND NOT __BORLANDC__)
25 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -g3")
26 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
27 set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g")
29 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}/Zi")
30 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}/Zi")
33 if(enable_compile_warnings)
34 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 ")
35 if(CMAKE_COMPILER_IS_GNUCC)
36 set(warnCFLAGS "${warnCFLAGS}-Wclobbered -Wno-error=clobbered ")
39 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")
40 if(CMAKE_COMPILER_IS_GNUCXX)
41 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wclobbered -Wno-error=clobbered")
44 set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wall") # FIXME: Q&D hack
46 set(CMAKE_JAVA_COMPILE_FLAGS "-Xlint")
49 if(enable_compile_optimizations)
50 set(optCFLAGS "-O3 -funroll-loops -fno-strict-aliasing ")
51 if(CMAKE_COMPILER_IS_GNUCC AND (NOT enable_model-checking))
52 set(optCFLAGS "${optCFLAGS} -finline-functions ")
54 if (COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.7")
55 # On windows, we need 4.8 or higher to enable lto because of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50293
56 set(optCFLAGS "${optCFLAGS} -flto ")
59 # On non-windows, 4.6 is enough for that
60 if(LINKER_VERSION STRGREATER "2.22")
61 set(optCFLAGS "${optCFLAGS} -flto ")
70 add_definitions(-DUSE_SDT)
74 add_definitions(-DUSE_UST)
77 if(enable_model-checking AND enable_compile_optimizations)
78 # Forget it, do not optimize the code (because it confuses the MC):
80 # But you can still optimize this:
83 src/xbt/log.c src/xbt/xbt_log_appender_file.c
84 src/xbt/xbt_log_layout_format.c src/xbt/xbt_log_layout_simple.c
85 src/xbt/dict.c src/xbt/dict_elm.c src/xbt/dict_multi.c src/xbt/dict_cursor.c
86 src/xbt/set.c src/xbt/setset.c
87 src/xbt/dynar.c src/xbt/fifo.c src/xbt/heap.c src/xbt/swag.c
88 src/xbt/str.c src/xbt/strbuff.c src/xbt/snprintf.c
90 src/xbt/xbt_os_time.c src/xbt/xbt_os_thread.c
93 src/xbt/backtrace_linux.c
94 ${MC_SRC_BASE} ${MC_SRC})
95 set (mcCFLAGS "-O3 -funroll-loops -fno-strict-aliasing")
96 if(CMAKE_COMPILER_IS_GNUCC)
97 set (mcCFLAGS "${mcCFLAGS} -finline-functions")
99 set_source_files_properties(${s} PROPERTIES COMPILE_FLAGS ${mcCFLAGS})
103 if(APPLE AND COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
104 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
105 set(optCFLAGS "-O0 ")
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 "${optCFLAGS} ${warnCFLAGS} ${CMAKE_C_FLAGS}")
119 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${optCFLAGS}")
121 # Try to make Mac a bit more complient to open source standards
122 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
123 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700 -D_DARWIN_C_SOURCE")
128 find_program(GCOV_PATH gcov)
130 set(COVERAGE_COMMAND "${GCOV_PATH}" CACHE TYPE FILEPATH FORCE)
131 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOVERAGE")
132 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
133 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
134 set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fprofile-arcs -ftest-coverage")
135 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
136 set(TESH_OPTION --enable-coverage)
137 add_definitions(-fprofile-arcs -ftest-coverage)
141 if(NOT $ENV{CFLAGS} STREQUAL "")
142 message(STATUS "Add CFLAGS: \"$ENV{CFLAGS}\" to CMAKE_C_FLAGS")
143 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{CFLAGS}")
146 if(NOT $ENV{CXXFLAGS} STREQUAL "")
147 message(STATUS "Add CXXFLAGS: \"$ENV{CXXFLAGS}\" to CMAKE_CXX_FLAGS")
148 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXXFLAGS}")
151 if(NOT $ENV{LDFLAGS} STREQUAL "")
152 message(STATUS "Add LDFLAGS: \"$ENV{LDFLAGS}\" to CMAKE_C_LINK_FLAGS")
153 set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} $ENV{LDFLAGS}")