diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-09-27 04:00:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-27 04:00:36 +0800 |
commit | 6db13311dd6d9e9ebb10f6f5b34c5b326f69b390 (patch) | |
tree | c6901c73a0db6dd5ba9d7c2a8c41e757a90569c9 | |
parent | eb5a6aacd993e3782eaf0c0f9dbce03a0567512f (diff) | |
parent | 5722f3083cae829c28a28083fa806005ed71168c (diff) | |
download | dexon-solidity-6db13311dd6d9e9ebb10f6f5b34c5b326f69b390.tar.gz dexon-solidity-6db13311dd6d9e9ebb10f6f5b34c5b326f69b390.tar.zst dexon-solidity-6db13311dd6d9e9ebb10f6f5b34c5b326f69b390.zip |
Merge pull request #2946 from ethereum/cmake
CMake: Add compiler warning about implicit fallthough
-rw-r--r-- | cmake/EthCheckCXXCompilerFlag.cmake | 23 | ||||
-rw-r--r-- | cmake/EthCompilerSettings.cmake | 23 |
2 files changed, 30 insertions, 16 deletions
diff --git a/cmake/EthCheckCXXCompilerFlag.cmake b/cmake/EthCheckCXXCompilerFlag.cmake new file mode 100644 index 00000000..c6ed35b4 --- /dev/null +++ b/cmake/EthCheckCXXCompilerFlag.cmake @@ -0,0 +1,23 @@ +include(CheckCXXCompilerFlag) + +# Adds CXX compiler flag if the flag is supported by the compiler. +# +# This is effectively a combination of CMake's check_cxx_compiler_flag() +# and add_compile_options(): +# +# if(check_cxx_compiler_flag(flag)) +# add_compile_options(flag) +# +function(eth_add_cxx_compiler_flag_if_supported FLAG) + # Remove leading - or / from the flag name. + string(REGEX REPLACE "^-|/" "" name ${FLAG}) + check_cxx_compiler_flag(${FLAG} ${name}) + if(${name}) + add_compile_options(${FLAG}) + endif() + + # If the optional argument passed, store the result there. + if(ARGV1) + set(${ARGV1} ${name} PARENT_SCOPE) + endif() +endfunction() diff --git a/cmake/EthCompilerSettings.cmake b/cmake/EthCompilerSettings.cmake index 1a00ae70..6d4dadeb 100644 --- a/cmake/EthCompilerSettings.cmake +++ b/cmake/EthCompilerSettings.cmake @@ -4,7 +4,7 @@ # CMake file for cpp-ethereum project which specifies our compiler settings # for each supported platform and build configuration. # -# See http://www.ethdocs.org/en/latest/ethereum-clients/cpp-ethereum/. +# The documentation for cpp-ethereum is hosted at http://cpp-ethereum.org # # Copyright (c) 2014-2016 cpp-ethereum contributors. #------------------------------------------------------------------------------ @@ -14,18 +14,15 @@ # # These settings then end up spanning all POSIX platforms (Linux, OS X, BSD, etc) -include(CheckCXXCompilerFlag) +include(EthCheckCXXCompilerFlag) -check_cxx_compiler_flag(-fstack-protector-strong have_stack_protector_strong) -if (have_stack_protector_strong) - add_compile_options(-fstack-protector-strong) -else() - check_cxx_compiler_flag(-fstack-protector have_stack_protector) - if(have_stack_protector) - add_compile_options(-fstack-protector) - endif() +eth_add_cxx_compiler_flag_if_supported(-fstack-protector-strong have_stack_protector_strong_support) +if(NOT have_stack_protector_strong_support) + eth_add_cxx_compiler_flag_if_supported(-fstack-protector) endif() +eth_add_cxx_compiler_flag_if_supported(-Wimplicit-fallthrough) + if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")) # Use ISO C++11 standard language. @@ -83,12 +80,6 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA message(FATAL_ERROR "${PROJECT_NAME} requires g++ 4.7 or greater.") endif () - # Until https://github.com/ethereum/solidity/issues/2479 is handled - # disable all implicit fallthrough warnings in the codebase for GCC > 7.0 - if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0) - add_compile_options(-Wno-implicit-fallthrough) - endif() - # Additional Clang-specific compiler settings. elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |