Changeset View
Changeset View
Standalone View
Standalone View
kde-modules/KDECompilerSettings.cmake
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Line(s) | 94 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | |||
---|---|---|---|---|---|
95 | if (WIN32) | 95 | if (WIN32) | ||
96 | _kde_compiler_min_version("4.7") | 96 | _kde_compiler_min_version("4.7") | ||
97 | elseif (APPLE) | 97 | elseif (APPLE) | ||
98 | # FIXME: Apple heavily modifies GCC, so checking the | 98 | # FIXME: Apple heavily modifies GCC, so checking the | ||
99 | # GCC version on OS/X is not very useful. | 99 | # GCC version on OS/X is not very useful. | ||
100 | else() | 100 | else() | ||
101 | _kde_compiler_min_version("4.5") | 101 | _kde_compiler_min_version("4.5") | ||
102 | endif() | 102 | endif() | ||
103 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") | 103 | elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
104 | _kde_compiler_min_version("3.1") | 104 | _kde_compiler_min_version("3.1") | ||
105 | else() | 105 | else() | ||
106 | message(WARNING "${CMAKE_CXX_COMPILER_ID} is not a supported C++ compiler.") | 106 | message(WARNING "${CMAKE_CXX_COMPILER_ID} is not a supported C++ compiler.") | ||
107 | endif() | 107 | endif() | ||
108 | 108 | | |||
109 | 109 | | |||
110 | 110 | | |||
111 | ############################################################ | 111 | ############################################################ | ||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | |||||
184 | 184 | | |||
185 | ############################################################ | 185 | ############################################################ | ||
186 | # Language and toolchain features | 186 | # Language and toolchain features | ||
187 | ############################################################ | 187 | ############################################################ | ||
188 | 188 | | |||
189 | # Pick sensible versions of the C and C++ standards. | 189 | # Pick sensible versions of the C and C++ standards. | ||
190 | # Note that MSVC does not have equivalent flags; the features are either | 190 | # Note that MSVC does not have equivalent flags; the features are either | ||
191 | # supported or they are not. | 191 | # supported or they are not. | ||
192 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") | 192 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") | ||
193 | # We use the C89 standard because that is what is common to all our | 193 | # We use the C89 standard because that is what is common to all our | ||
194 | # compilers (in particular, MSVC 2010 does not support C99) | 194 | # compilers (in particular, MSVC 2010 does not support C99) | ||
195 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=iso9899:1990") | 195 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=iso9899:1990") | ||
196 | endif() | 196 | endif() | ||
197 | if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | 197 | if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
198 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") | 198 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") | ||
199 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) | 199 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) | ||
200 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") | 200 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") | ||
201 | endif() | 201 | endif() | ||
202 | 202 | | |||
203 | # Do not merge uninitialized global variables. | 203 | # Do not merge uninitialized global variables. | ||
204 | # This is mostly a "principle of least surprise" thing, but also | 204 | # This is mostly a "principle of least surprise" thing, but also | ||
205 | # has performance benefits. | 205 | # has performance benefits. | ||
206 | # See https://www.ibm.com/developerworks/community/blogs/zTPF/entry/benefits_of_the_fnocommon_compile_option_peter_lemieszewski?lang=en | 206 | # See https://www.ibm.com/developerworks/community/blogs/zTPF/entry/benefits_of_the_fnocommon_compile_option_peter_lemieszewski?lang=en | ||
207 | # Note that this only applies to C code; C++ already behaves like this. | 207 | # Note that this only applies to C code; C++ already behaves like this. | ||
208 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR | 208 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR | ||
209 | CMAKE_C_COMPILER_ID STREQUAL "Clang" OR | 209 | CMAKE_C_COMPILER_ID MATCHES "Clang" OR | ||
210 | (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT WIN32)) | 210 | (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT WIN32)) | ||
211 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-common") | 211 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-common") | ||
212 | endif() | 212 | endif() | ||
213 | 213 | | |||
214 | # Do not treat the operator name keywords and, bitand, bitor, compl, not, or and xor as synonyms as keywords. | 214 | # Do not treat the operator name keywords and, bitand, bitor, compl, not, or and xor as synonyms as keywords. | ||
215 | # They're not supported under Visual Studio out of the box thus using them limits the portability of code | 215 | # They're not supported under Visual Studio out of the box thus using them limits the portability of code | ||
216 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR | 216 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR | ||
217 | CMAKE_C_COMPILER_ID STREQUAL "Clang" OR | 217 | CMAKE_C_COMPILER_ID MATCHES "Clang" OR | ||
218 | (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT WIN32)) | 218 | (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT WIN32)) | ||
219 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-operator-names") | 219 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-operator-names") | ||
220 | endif() | 220 | endif() | ||
221 | 221 | | |||
222 | # Default to hidden visibility for symbols | 222 | # Default to hidden visibility for symbols | ||
223 | set(CMAKE_C_VISIBILITY_PRESET hidden) | 223 | set(CMAKE_C_VISIBILITY_PRESET hidden) | ||
224 | set(CMAKE_CXX_VISIBILITY_PRESET hidden) | 224 | set(CMAKE_CXX_VISIBILITY_PRESET hidden) | ||
225 | set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) | 225 | set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) | ||
Show All 32 Lines | |||||
258 | # TODO: Deal with QT_NO_EXCEPTIONS for non-gnu compilers? | 258 | # TODO: Deal with QT_NO_EXCEPTIONS for non-gnu compilers? | ||
259 | # This should be defined if and only if exceptions are disabled. | 259 | # This should be defined if and only if exceptions are disabled. | ||
260 | # qglobal.h has some magic to set it when exceptions are disabled | 260 | # qglobal.h has some magic to set it when exceptions are disabled | ||
261 | # with gcc, but other compilers are unaccounted for. | 261 | # with gcc, but other compilers are unaccounted for. | ||
262 | 262 | | |||
263 | # Turn off exceptions by default | 263 | # Turn off exceptions by default | ||
264 | if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | 264 | if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
265 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") | 265 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") | ||
266 | elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | 266 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
267 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") | 267 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") | ||
268 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) | 268 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) | ||
269 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") | 269 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") | ||
270 | #elseif (MSVC OR (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Intel")) | 270 | #elseif (MSVC OR (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Intel")) | ||
271 | # Exceptions appear to be disabled by default for MSVC | 271 | # Exceptions appear to be disabled by default for MSVC | ||
272 | # http://msdn.microsoft.com/en-us/library/1deeycx5.aspx | 272 | # http://msdn.microsoft.com/en-us/library/1deeycx5.aspx | ||
273 | 273 | | |||
274 | # FIXME: are exceptions disabled by default for Intel? | 274 | # FIXME: are exceptions disabled by default for Intel? | ||
275 | endif() | 275 | endif() | ||
276 | 276 | | |||
277 | macro(_kdecompilersettings_append_exception_flag VAR) | 277 | macro(_kdecompilersettings_append_exception_flag VAR) | ||
278 | if (MSVC) | 278 | if (MSVC) | ||
279 | set(${VAR} "${${VAR}} -EHsc") | 279 | set(${VAR} "${${VAR}} -EHsc") | ||
280 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") | 280 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") | ||
281 | if (WIN32) | 281 | if (WIN32) | ||
282 | set(${VAR} "${${VAR}} -EHsc") | 282 | set(${VAR} "${${VAR}} -EHsc") | ||
283 | else() | 283 | else() | ||
284 | set(${VAR} "${${VAR}} -fexceptions") | 284 | set(${VAR} "${${VAR}} -fexceptions") | ||
285 | endif() | 285 | endif() | ||
286 | elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | 286 | elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
287 | set(${VAR} "${${VAR}} -fexceptions") | 287 | set(${VAR} "${${VAR}} -fexceptions") | ||
288 | elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | 288 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
289 | set(${VAR} "${${VAR}} -fexceptions") | 289 | set(${VAR} "${${VAR}} -fexceptions") | ||
290 | endif() | 290 | endif() | ||
291 | string(STRIP "${${VAR}}" ${VAR}) | 291 | string(STRIP "${${VAR}}" ${VAR}) | ||
292 | endmacro() | 292 | endmacro() | ||
293 | 293 | | |||
294 | function(KDE_SOURCE_FILES_ENABLE_EXCEPTIONS) | 294 | function(KDE_SOURCE_FILES_ENABLE_EXCEPTIONS) | ||
295 | foreach(source_file ${ARGV}) | 295 | foreach(source_file ${ARGV}) | ||
296 | get_source_file_property(flags ${source_file} COMPILE_FLAGS) | 296 | get_source_file_property(flags ${source_file} COMPILE_FLAGS) | ||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 343 | if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT APPLE) OR | |||
348 | set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--fatal-warnings ${CMAKE_MODULE_LINKER_FLAGS}") | 348 | set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--fatal-warnings ${CMAKE_MODULE_LINKER_FLAGS}") | ||
349 | 349 | | |||
350 | # Do not allow undefined symbols, even in non-symbolic shared libraries | 350 | # Do not allow undefined symbols, even in non-symbolic shared libraries | ||
351 | set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined ${CMAKE_SHARED_LINKER_FLAGS}") | 351 | set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined ${CMAKE_SHARED_LINKER_FLAGS}") | ||
352 | set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined ${CMAKE_MODULE_LINKER_FLAGS}") | 352 | set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined ${CMAKE_MODULE_LINKER_FLAGS}") | ||
353 | endif() | 353 | endif() | ||
354 | 354 | | |||
355 | set(_KDE_GCC_COMMON_WARNING_FLAGS "-Wall -Wextra -Wcast-align -Wchar-subscripts -Wformat-security -Wno-long-long -Wpointer-arith -Wundef") | 355 | set(_KDE_GCC_COMMON_WARNING_FLAGS "-Wall -Wextra -Wcast-align -Wchar-subscripts -Wformat-security -Wno-long-long -Wpointer-arith -Wundef") | ||
356 | if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") | 356 | if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") | ||
357 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_KDE_GCC_COMMON_WARNING_FLAGS} -Wmissing-format-attribute -Wwrite-strings") | 357 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_KDE_GCC_COMMON_WARNING_FLAGS} -Wmissing-format-attribute -Wwrite-strings") | ||
358 | # Make some warnings errors | 358 | # Make some warnings errors | ||
359 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=implicit-function-declaration") | 359 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=implicit-function-declaration") | ||
360 | endif() | 360 | endif() | ||
361 | if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | 361 | if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
362 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_KDE_GCC_COMMON_WARNING_FLAGS} -Wnon-virtual-dtor -Woverloaded-virtual") | 362 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_KDE_GCC_COMMON_WARNING_FLAGS} -Wnon-virtual-dtor -Woverloaded-virtual") | ||
363 | # Make some warnings errors | 363 | # Make some warnings errors | ||
364 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type") | 364 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type") | ||
365 | endif() | 365 | endif() | ||
366 | 366 | | |||
367 | # -w1 turns on warnings and errors | 367 | # -w1 turns on warnings and errors | ||
368 | # FIXME: someone needs to have a closer look at the Intel compiler options | 368 | # FIXME: someone needs to have a closer look at the Intel compiler options | ||
369 | if (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) | 369 | if (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) | ||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |