diff --git a/CMakeLists.txt b/CMakeLists.txt index 2aca61d30..d8de3d149 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,7 @@ endif() option(SOLC_LINK_STATIC "Link solc executable statically on supported platforms" OFF) option(SOLC_STATIC_STDLIBS "Link solc against static versions of libgcc and libstdc++ on supported platforms" OFF) option(STRICT_Z3_VERSION "Use the latest version of Z3" ON) +option(PEDANTIC "Enable extra warnings and pedantic build flags. Treat all warnings as errors." ON) # Setup cccache. include(EthCcache) @@ -48,6 +49,9 @@ include_directories(SYSTEM ${JSONCPP_INCLUDE_DIR}) find_package(Threads) +if(NOT PEDANTIC) + message(WARNING "-- Pedantic build flags turned off. Warnings will not make compilation fail. This is NOT recommended in development builds.") +endif() # Figure out what compiler and system are we using include(EthCompilerSettings) diff --git a/cmake/EthCompilerSettings.cmake b/cmake/EthCompilerSettings.cmake index 0ddeb452a..01eee4b98 100644 --- a/cmake/EthCompilerSettings.cmake +++ b/cmake/EthCompilerSettings.cmake @@ -23,7 +23,9 @@ if(NOT EMSCRIPTEN) endif() endif() -eth_add_cxx_compiler_flag_if_supported(-Wimplicit-fallthrough) +if(PEDANTIC) + eth_add_cxx_compiler_flag_if_supported(-Wimplicit-fallthrough) +endif() # Prevent the path of the source directory from ending up in the binary via __FILE__ macros. eth_add_cxx_compiler_flag_if_supported("-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=/solidity") @@ -32,39 +34,45 @@ eth_add_cxx_compiler_flag_if_supported("-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=/ # if the argument was not wrapped in a call. This happens when moving a local # variable in a return statement when the variable is the same type as the # return type or using a move to create a new object from a temporary object. -eth_add_cxx_compiler_flag_if_supported(-Wpessimizing-move) +if(PEDANTIC) + eth_add_cxx_compiler_flag_if_supported(-Wpessimizing-move) +endif() # -Wredundant-move warns when an implicit move would already be made, so the # std::move call is not needed, such as when moving a local variable in a return # that is different from the return type. -eth_add_cxx_compiler_flag_if_supported(-Wredundant-move) +if(PEDANTIC) + eth_add_cxx_compiler_flag_if_supported(-Wredundant-move) +endif() if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")) # Enables all the warnings about constructions that some users consider questionable, # and that are easy to avoid. Also enable some extra warning flags that are not # enabled by -Wall. Finally, treat at warnings-as-errors, which forces developers # to fix warnings as they arise, so they don't accumulate "to be fixed later". - add_compile_options(-Wall) - add_compile_options(-Wextra) - add_compile_options(-Werror) - add_compile_options(-pedantic) - add_compile_options(-Wmissing-declarations) - add_compile_options(-Wno-unknown-pragmas) - add_compile_options(-Wimplicit-fallthrough) - add_compile_options(-Wsign-conversion) - add_compile_options(-Wconversion) + if(PEDANTIC) + add_compile_options(-Wall) + add_compile_options(-Wextra) + add_compile_options(-Werror) + add_compile_options(-pedantic) + add_compile_options(-Wmissing-declarations) + add_compile_options(-Wno-unknown-pragmas) + add_compile_options(-Wimplicit-fallthrough) + add_compile_options(-Wsign-conversion) + add_compile_options(-Wconversion) - check_cxx_compiler_flag(-Wextra-semi WEXTRA_SEMI) - if(WEXTRA_SEMI) - add_compile_options($<$:-Wextra-semi>) + check_cxx_compiler_flag(-Wextra-semi WEXTRA_SEMI) + if(WEXTRA_SEMI) + add_compile_options($<$:-Wextra-semi>) + endif() + eth_add_cxx_compiler_flag_if_supported(-Wfinal-dtor-non-final-class) + eth_add_cxx_compiler_flag_if_supported(-Wnewline-eof) + eth_add_cxx_compiler_flag_if_supported(-Wsuggest-destructor-override) + eth_add_cxx_compiler_flag_if_supported(-Wduplicated-cond) + eth_add_cxx_compiler_flag_if_supported(-Wduplicate-enum) + eth_add_cxx_compiler_flag_if_supported(-Wlogical-op) + eth_add_cxx_compiler_flag_if_supported(-Wno-unknown-attributes) endif() - eth_add_cxx_compiler_flag_if_supported(-Wfinal-dtor-non-final-class) - eth_add_cxx_compiler_flag_if_supported(-Wnewline-eof) - eth_add_cxx_compiler_flag_if_supported(-Wsuggest-destructor-override) - eth_add_cxx_compiler_flag_if_supported(-Wduplicated-cond) - eth_add_cxx_compiler_flag_if_supported(-Wduplicate-enum) - eth_add_cxx_compiler_flag_if_supported(-Wlogical-op) - eth_add_cxx_compiler_flag_if_supported(-Wno-unknown-attributes) # Configuration-specific compiler settings. set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -DETH_DEBUG") @@ -158,7 +166,9 @@ elseif (DEFINED MSVC) add_compile_options(/MP) # enable parallel compilation add_compile_options(/EHsc) # specify Exception Handling Model in msvc - add_compile_options(/WX) # enable warnings-as-errors + if(PEDANTIC) + add_compile_options(/WX) # enable warnings-as-errors + endif() add_compile_options(/wd4068) # disable unknown pragma warning (4068) add_compile_options(/wd4996) # disable unsafe function warning (4996) add_compile_options(/wd4503) # disable decorated name length exceeded, name was truncated (4503) diff --git a/docs/installing-solidity.rst b/docs/installing-solidity.rst index 9d6e666d2..9a613d75d 100644 --- a/docs/installing-solidity.rst +++ b/docs/installing-solidity.rst @@ -354,6 +354,17 @@ The following are dependencies for all builds of Solidity: If you do this, however, please remember to pass the ``--no-smt`` option to ``scripts/tests.sh`` to skip the SMT tests. +.. note:: + By default the build is performed in *pedantic mode*, which enables extra warnings and tells the + compiler to treat all warnings as errors. + This forces developers to fix warnings as they arise, so they do not accumulate "to be fixed later". + If you are only interested in creating a release build and do not intend to modify the source code + to deal with such warnings, you can pass ``-DPEDANTIC=OFF`` option to CMake to disable this mode. + Doing this is not recommended for general use but may be necessary when using a toolchain we are + not testing with or trying to build an older version with newer tools. + If you encounter such warnings, please consider + `reporting them `_. + Minimum Compiler Versions ^^^^^^^^^^^^^^^^^^^^^^^^^