Changeset View
Standalone View
kde-modules/KDECompilerSettings.cmake
Show First 20 Lines • Show All 180 Lines • ▼ Show 20 Line(s) | |||||
181 | endif() | 181 | endif() | ||
182 | 182 | | |||
183 | 183 | | |||
184 | 184 | | |||
185 | ############################################################ | 185 | ############################################################ | ||
186 | # Language and toolchain features | 186 | # Language and toolchain features | ||
187 | ############################################################ | 187 | ############################################################ | ||
188 | 188 | | |||
189 | include(ECMAddCompilerFlag) | ||||
190 | | ||||
189 | # Pick sensible versions of the C and C++ standards. | 191 | # Pick sensible versions of the C and C++ standards. | ||
190 | # Note that MSVC does not have equivalent flags; the features are either | 192 | # Note that MSVC does not have equivalent flags; the features are either | ||
191 | # supported or they are not. | 193 | # supported or they are not. | ||
192 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") | 194 | 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 | 195 | # We use the C89 standard because that is what is common to all our | ||
apol: Why can't we just use check_cxx_compiler_flag? | |||||
We could of course. I worked under the assumption that is not done currently because checking only ID+version is faster. CMake's check_cxx_compiler_flag is more expensive because it invokes the compiler. And it can fail, for instance if the user adds an option for which the compiler emits diagnostics output. That will be true for the "clang on Mac" situation too, but why generalise brittleness if you don't have to? rjvbb: We could of course. I worked under the assumption that is not done currently because checking… | |||||
194 | # compilers (in particular, MSVC 2010 does not support C99) | 196 | # compilers (in particular, MSVC 2010 does not support C99) | ||
195 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=iso9899:1990") | 197 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=iso9899:1990") | ||
196 | endif() | 198 | endif() | ||
197 | if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | 199 | 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") | 200 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") | ||
199 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) | 201 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) | ||
200 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") | 202 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") | ||
This "let's abuse ${ARGN} as code to be evaluated later" is pretty ugly. The previous version (with the if-statements at the caller side) is way more clean and understandable. kfunk: This "let's abuse ${ARGN} as code to be evaluated later" is pretty ugly. The previous version… | |||||
201 | endif() | 203 | endif() | ||
apol: Why have a macro that only works on Apple? | |||||
? This is a macro that encapsulates a Mac-specific peculiarity but otherwise should work everywhere. Did I miss something?! NB: ${_RESULT} is not going to be set if COMPILER_OK isn't set first, meaning the macro should always "return false" when a flag isn't supported, even if check_cxx_compiler_flag isn't used. rjvbb: ? This is a macro that encapsulates a Mac-specific peculiarity but otherwise should work… | |||||
I don't really understand why this branch is needed. The macro name name suggests it does the compile check on all compilers. Again very misleading. kfunk: I don't really understand why this branch is needed. The macro name name suggests it does the… | |||||
202 | 204 | | |||
203 | # Do not merge uninitialized global variables. | 205 | # Do not merge uninitialized global variables. | ||
204 | # This is mostly a "principle of least surprise" thing, but also | 206 | # This is mostly a "principle of least surprise" thing, but also | ||
205 | # has performance benefits. | 207 | # has performance benefits. | ||
206 | # See https://www.ibm.com/developerworks/community/blogs/zTPF/entry/benefits_of_the_fnocommon_compile_option_peter_lemieszewski?lang=en | 208 | # 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. | 209 | # Note that this only applies to C code; C++ already behaves like this. | ||
208 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR | 210 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR | ||
209 | CMAKE_C_COMPILER_ID MATCHES "Clang" OR | 211 | CMAKE_C_COMPILER_ID MATCHES "Clang" OR | ||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Line(s) | 364 | if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") | |||
364 | # Make some warnings errors | 366 | # Make some warnings errors | ||
365 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=implicit-function-declaration") | 367 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=implicit-function-declaration") | ||
366 | endif() | 368 | endif() | ||
367 | if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | 369 | if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
368 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_KDE_GCC_COMMON_WARNING_FLAGS} -Wnon-virtual-dtor -Woverloaded-virtual") | 370 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_KDE_GCC_COMMON_WARNING_FLAGS} -Wnon-virtual-dtor -Woverloaded-virtual") | ||
369 | # Make some warnings errors | 371 | # Make some warnings errors | ||
370 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type") | 372 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type") | ||
371 | endif() | 373 | endif() | ||
372 | if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR | 374 | ecm_add_cxx_compiler_flags_conditionally(FLAGS -Wvla | ||
375 | CONDITION CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR | ||||
373 | (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)) | 376 | (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)) | ||
374 | # -Wvla: use of variable-length arrays (an extension to C++) | 377 | ecm_add_cxx_compiler_flags_conditionally(FLAGS -Wdate-time | ||
375 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvla") | 378 | CONDITION (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) OR | ||
376 | endif() | | |||
377 | if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) OR | | |||
378 | (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)) | 379 | (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)) | ||
379 | include(CheckCXXCompilerFlag) | | |||
380 | check_cxx_compiler_flag(-Wdate-time HAVE_DATE_TIME) | | |||
381 | if (HAVE_DATE_TIME) | | |||
382 | # -Wdate-time: warn if we use __DATE__ or __TIME__ (we want to be able to reproduce the exact same binary) | | |||
383 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdate-time") | | |||
384 | endif() | | |||
385 | endif() | | |||
386 | 380 | | |||
387 | if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | 381 | if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
388 | if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0") | 382 | if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0") | ||
389 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override -Wlogical-op" ) | 383 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override -Wlogical-op" ) | ||
390 | endif() | 384 | endif() | ||
391 | endif() | 385 | endif() | ||
392 | 386 | | |||
393 | # -w1 turns on warnings and errors | 387 | # -w1 turns on warnings and errors | ||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Line(s) | 479 | if (MINGW AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | |||
487 | # "otherwise undefined symbol in phononcore.dll errors occurs", with the commit | 481 | # "otherwise undefined symbol in phononcore.dll errors occurs", with the commit | ||
488 | # message "set linker flag --export-all-symbols for all targets, otherwise | 482 | # message "set linker flag --export-all-symbols for all targets, otherwise | ||
489 | # some depending targets could not be build" | 483 | # some depending targets could not be build" | ||
490 | # FIXME: do our export macros not deal with this properly? | 484 | # FIXME: do our export macros not deal with this properly? | ||
491 | set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-all-symbols") | 485 | set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-all-symbols") | ||
492 | set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--export-all-symbols") | 486 | set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--export-all-symbols") | ||
493 | endif() | 487 | endif() | ||
494 | 488 | | |||
495 | if (CMAKE_GENERATOR STREQUAL "Ninja" AND | 489 | if (CMAKE_GENERATOR STREQUAL "Ninja") | ||
496 | ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) OR | | |||
497 | (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5))) | | |||
498 | # Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support. | 490 | # Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support. | ||
499 | # Rationale in https://github.com/ninja-build/ninja/issues/814 | 491 | # Rationale in https://github.com/ninja-build/ninja/issues/814 | ||
500 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") | 492 | ecm_add_cxx_compiler_flags_conditionally(FLAGS -fdiagnostics-color=always | ||
493 | CONDITION ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) OR | ||||
494 | (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5))) | ||||
501 | endif() | 495 | endif() | ||
502 | 496 | | |||
503 | include("${ECM_MODULE_DIR}/ECMEnableSanitizers.cmake") | 497 | include("${ECM_MODULE_DIR}/ECMEnableSanitizers.cmake") | ||
504 | include("${ECM_MODULE_DIR}/ECMCoverageOption.cmake") | 498 | include("${ECM_MODULE_DIR}/ECMCoverageOption.cmake") |
Why can't we just use check_cxx_compiler_flag?