Skip to content

Commit b175591

Browse files
author
Leo
authored
Merge pull request #13256 from YuviTz1/develop
Added build flag to disable pedantic builds
2 parents 5cf3973 + b7847c9 commit b175591

File tree

3 files changed

+48
-23
lines changed

3 files changed

+48
-23
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ endif()
3535
option(SOLC_LINK_STATIC "Link solc executable statically on supported platforms" OFF)
3636
option(SOLC_STATIC_STDLIBS "Link solc against static versions of libgcc and libstdc++ on supported platforms" OFF)
3737
option(STRICT_Z3_VERSION "Use the latest version of Z3" ON)
38+
option(PEDANTIC "Enable extra warnings and pedantic build flags. Treat all warnings as errors." ON)
3839

3940
# Setup cccache.
4041
include(EthCcache)
@@ -48,6 +49,9 @@ include_directories(SYSTEM ${JSONCPP_INCLUDE_DIR})
4849

4950
find_package(Threads)
5051

52+
if(NOT PEDANTIC)
53+
message(WARNING "-- Pedantic build flags turned off. Warnings will not make compilation fail. This is NOT recommended in development builds.")
54+
endif()
5155
# Figure out what compiler and system are we using
5256
include(EthCompilerSettings)
5357

cmake/EthCompilerSettings.cmake

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ if(NOT EMSCRIPTEN)
2323
endif()
2424
endif()
2525

26-
eth_add_cxx_compiler_flag_if_supported(-Wimplicit-fallthrough)
26+
if(PEDANTIC)
27+
eth_add_cxx_compiler_flag_if_supported(-Wimplicit-fallthrough)
28+
endif()
2729

2830
# Prevent the path of the source directory from ending up in the binary via __FILE__ macros.
2931
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}=/
3234
# if the argument was not wrapped in a call. This happens when moving a local
3335
# variable in a return statement when the variable is the same type as the
3436
# return type or using a move to create a new object from a temporary object.
35-
eth_add_cxx_compiler_flag_if_supported(-Wpessimizing-move)
37+
if(PEDANTIC)
38+
eth_add_cxx_compiler_flag_if_supported(-Wpessimizing-move)
39+
endif()
3640

3741
# -Wredundant-move warns when an implicit move would already be made, so the
3842
# std::move call is not needed, such as when moving a local variable in a return
3943
# that is different from the return type.
40-
eth_add_cxx_compiler_flag_if_supported(-Wredundant-move)
44+
if(PEDANTIC)
45+
eth_add_cxx_compiler_flag_if_supported(-Wredundant-move)
46+
endif()
4147

4248
if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
4349
# Enables all the warnings about constructions that some users consider questionable,
4450
# and that are easy to avoid. Also enable some extra warning flags that are not
4551
# enabled by -Wall. Finally, treat at warnings-as-errors, which forces developers
4652
# to fix warnings as they arise, so they don't accumulate "to be fixed later".
47-
add_compile_options(-Wall)
48-
add_compile_options(-Wextra)
49-
add_compile_options(-Werror)
50-
add_compile_options(-pedantic)
51-
add_compile_options(-Wmissing-declarations)
52-
add_compile_options(-Wno-unknown-pragmas)
53-
add_compile_options(-Wimplicit-fallthrough)
54-
add_compile_options(-Wsign-conversion)
55-
add_compile_options(-Wconversion)
53+
if(PEDANTIC)
54+
add_compile_options(-Wall)
55+
add_compile_options(-Wextra)
56+
add_compile_options(-Werror)
57+
add_compile_options(-pedantic)
58+
add_compile_options(-Wmissing-declarations)
59+
add_compile_options(-Wno-unknown-pragmas)
60+
add_compile_options(-Wimplicit-fallthrough)
61+
add_compile_options(-Wsign-conversion)
62+
add_compile_options(-Wconversion)
5663

57-
check_cxx_compiler_flag(-Wextra-semi WEXTRA_SEMI)
58-
if(WEXTRA_SEMI)
59-
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wextra-semi>)
64+
check_cxx_compiler_flag(-Wextra-semi WEXTRA_SEMI)
65+
if(WEXTRA_SEMI)
66+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wextra-semi>)
67+
endif()
68+
eth_add_cxx_compiler_flag_if_supported(-Wfinal-dtor-non-final-class)
69+
eth_add_cxx_compiler_flag_if_supported(-Wnewline-eof)
70+
eth_add_cxx_compiler_flag_if_supported(-Wsuggest-destructor-override)
71+
eth_add_cxx_compiler_flag_if_supported(-Wduplicated-cond)
72+
eth_add_cxx_compiler_flag_if_supported(-Wduplicate-enum)
73+
eth_add_cxx_compiler_flag_if_supported(-Wlogical-op)
74+
eth_add_cxx_compiler_flag_if_supported(-Wno-unknown-attributes)
6075
endif()
61-
eth_add_cxx_compiler_flag_if_supported(-Wfinal-dtor-non-final-class)
62-
eth_add_cxx_compiler_flag_if_supported(-Wnewline-eof)
63-
eth_add_cxx_compiler_flag_if_supported(-Wsuggest-destructor-override)
64-
eth_add_cxx_compiler_flag_if_supported(-Wduplicated-cond)
65-
eth_add_cxx_compiler_flag_if_supported(-Wduplicate-enum)
66-
eth_add_cxx_compiler_flag_if_supported(-Wlogical-op)
67-
eth_add_cxx_compiler_flag_if_supported(-Wno-unknown-attributes)
6876

6977
# Configuration-specific compiler settings.
7078
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -DETH_DEBUG")
@@ -158,7 +166,9 @@ elseif (DEFINED MSVC)
158166

159167
add_compile_options(/MP) # enable parallel compilation
160168
add_compile_options(/EHsc) # specify Exception Handling Model in msvc
161-
add_compile_options(/WX) # enable warnings-as-errors
169+
if(PEDANTIC)
170+
add_compile_options(/WX) # enable warnings-as-errors
171+
endif()
162172
add_compile_options(/wd4068) # disable unknown pragma warning (4068)
163173
add_compile_options(/wd4996) # disable unsafe function warning (4996)
164174
add_compile_options(/wd4503) # disable decorated name length exceeded, name was truncated (4503)

docs/installing-solidity.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,17 @@ The following are dependencies for all builds of Solidity:
354354
If you do this, however, please remember to pass the ``--no-smt`` option to ``scripts/tests.sh``
355355
to skip the SMT tests.
356356

357+
.. note::
358+
By default the build is performed in *pedantic mode*, which enables extra warnings and tells the
359+
compiler to treat all warnings as errors.
360+
This forces developers to fix warnings as they arise, so they do not accumulate "to be fixed later".
361+
If you are only interested in creating a release build and do not intend to modify the source code
362+
to deal with such warnings, you can pass ``-DPEDANTIC=OFF`` option to CMake to disable this mode.
363+
Doing this is not recommended for general use but may be necessary when using a toolchain we are
364+
not testing with or trying to build an older version with newer tools.
365+
If you encounter such warnings, please consider
366+
`reporting them <https://github.com/ethereum/solidity/issues/new>`_.
367+
357368
Minimum Compiler Versions
358369
^^^^^^^^^^^^^^^^^^^^^^^^^
359370

0 commit comments

Comments
 (0)