Changeset View
Changeset View
Standalone View
Standalone View
kde-modules/KDECompilerSettings.cmake
Show First 20 Lines • Show All 258 Lines • ▼ Show 20 Line(s) | |||||
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 MATCHES "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 -DQT_NO_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 -DQT_NO_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 | string(REPLACE " -DQT_NO_EXCEPTIONS " " " ${VAR} " ${${VAR}} ") | ||
288 | # it's likely that -DQT_NO_EXCEPTIONS from CMAKE_CXX_FLAGS never made it to the COMPILE_OPTIONS | ||||
289 | # so we override/undo that global setting for this file | ||||
290 | set(${VAR} "${${VAR}} -fexceptions -UQT_NO_EXCEPTIONS") | ||||
288 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") | 291 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
289 | set(${VAR} "${${VAR}} -fexceptions") | 292 | string(REPLACE " -DQT_NO_EXCEPTIONS " " " ${VAR} " ${${VAR}} ") | ||
293 | set(${VAR} "${${VAR}} -fexceptions -UQT_NO_EXCEPTIONS") | ||||
290 | endif() | 294 | endif() | ||
291 | string(STRIP "${${VAR}}" ${VAR}) | 295 | string(STRIP "${${VAR}}" ${VAR}) | ||
292 | endmacro() | 296 | endmacro() | ||
293 | 297 | | |||
294 | function(KDE_SOURCE_FILES_ENABLE_EXCEPTIONS) | 298 | function(KDE_SOURCE_FILES_ENABLE_EXCEPTIONS) | ||
295 | foreach(source_file ${ARGV}) | 299 | foreach(source_file ${ARGV}) | ||
296 | get_source_file_property(flags ${source_file} COMPILE_FLAGS) | 300 | get_source_file_property(flags ${source_file} COMPILE_FLAGS) | ||
297 | if(NOT flags) | 301 | if(NOT flags) | ||
298 | # If COMPILE_FLAGS is not set, get_source_file_property() sets it to | 302 | # If COMPILE_FLAGS is not set, get_source_file_property() sets it to | ||
299 | # NOTFOUND, which breaks build if we concatenate anything to | 303 | # NOTFOUND, which breaks build if we concatenate anything to | ||
300 | # the "NOTFOUND" string. | 304 | # the "NOTFOUND" string. | ||
301 | # Note that NOTFOUND evaluates to False, so we do enter the if. | 305 | # Note that NOTFOUND evaluates to False, so we do enter the if. | ||
302 | set(flags "") | 306 | set(flags "") | ||
303 | endif() | 307 | endif() | ||
304 | _kdecompilersettings_append_exception_flag(flags) | 308 | _kdecompilersettings_append_exception_flag(flags) | ||
305 | set_source_files_properties(${source_file} COMPILE_FLAGS "${flags}") | 309 | set_source_files_properties(${source_file} COMPILE_FLAGS "${flags}") | ||
306 | endforeach() | 310 | endforeach() | ||
307 | endfunction() | 311 | endfunction() | ||
308 | 312 | | |||
309 | function(KDE_TARGET_ENABLE_EXCEPTIONS target mode) | 313 | function(KDE_TARGET_ENABLE_EXCEPTIONS target mode) | ||
310 | target_compile_options(${target} ${mode} "$<$<CXX_COMPILER_ID:MSVC>:-EHsc>") | 314 | target_compile_options(${target} ${mode} "$<$<CXX_COMPILER_ID:MSVC>:-EHsc>") | ||
311 | if (WIN32) | 315 | if (WIN32) | ||
312 | target_compile_options(${target} ${mode} "$<$<CXX_COMPILER_ID:Intel>:-EHsc>") | 316 | target_compile_options(${target} ${mode} "$<$<CXX_COMPILER_ID:Intel>:-EHsc>") | ||
313 | else() | 317 | else() | ||
314 | target_compile_options(${target} ${mode} "$<$<CXX_COMPILER_ID:Intel>:-fexceptions>") | 318 | target_compile_options(${target} ${mode} "$<$<CXX_COMPILER_ID:Intel>:-fexceptions;-UQT_NO_EXCEPTIONS>") | ||
315 | endif() | 319 | endif() | ||
316 | target_compile_options(${target} ${mode} | 320 | target_compile_options(${target} ${mode} | ||
317 | "$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-fexceptions>") | 321 | "$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-fexceptions;-UQT_NO_EXCEPTIONS>") | ||
318 | endfunction() | 322 | endfunction() | ||
319 | 323 | | |||
320 | function(KDE_ENABLE_EXCEPTIONS) | 324 | function(KDE_ENABLE_EXCEPTIONS) | ||
321 | # We set CMAKE_CXX_FLAGS, rather than add_compile_options(), because | 325 | # We set CMAKE_CXX_FLAGS, rather than add_compile_options(), because | ||
322 | # we only want to affect the compilation of C++ source files. | 326 | # we only want to affect the compilation of C++ source files. | ||
323 | 327 | | |||
324 | # strip any occurrences of -DQT_NO_EXCEPTIONS; this should only be defined | 328 | # strip any occurrences of -DQT_NO_EXCEPTIONS; this should only be defined | ||
325 | # if exceptions are disabled | 329 | # if exceptions are disabled | ||
▲ Show 20 Lines • Show All 169 Lines • Show Last 20 Lines |