@@ -18,103 +18,110 @@ include(EthCheckCXXCompilerFlag)
1818
1919eth_add_cxx_compiler_flag_if_supported(-fstack-protector-strong have_stack_protector_strong_support)
2020if (NOT have_stack_protector_strong_support)
21- eth_add_cxx_compiler_flag_if_supported(-fstack-protector)
21+ eth_add_cxx_compiler_flag_if_supported(-fstack-protector)
2222endif ()
2323
2424eth_add_cxx_compiler_flag_if_supported(-Wimplicit-fallthrough)
2525
2626if (("${CMAKE_CXX_COMPILER_ID} " MATCHES "GNU" ) OR ("${CMAKE_CXX_COMPILER_ID} " MATCHES "Clang" ))
27- # Enables all the warnings about constructions that some users consider questionable,
28- # and that are easy to avoid. Also enable some extra warning flags that are not
29- # enabled by -Wall. Finally, treat at warnings-as-errors, which forces developers
30- # to fix warnings as they arise, so they don't accumulate "to be fixed later".
31- add_compile_options (-Wall)
32- add_compile_options (-Wextra)
33- add_compile_options (-Werror)
34-
35- # Disable warnings about unknown pragmas (which is enabled by -Wall).
36- add_compile_options (-Wno-unknown-pragmas)
37-
38- # Configuration-specific compiler settings.
39- set (CMAKE_CXX_FLAGS_DEBUG "-Og -g -DETH_DEBUG" )
40- set (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG" )
41- set (CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" )
42- set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g" )
43-
44- option (USE_LD_GOLD "Use GNU gold linker" ON )
45- if (USE_LD_GOLD)
46- execute_process (COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
47- if ("${LD_VERSION} " MATCHES "GNU gold" )
48- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold" )
49- set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold" )
50- endif ()
51- endif ()
52-
53- # Check GCC compiler version.
54- if ("${CMAKE_CXX_COMPILER_ID} " MATCHES "GNU" )
55- if ("${CMAKE_CXX_COMPILER_VERSION} " VERSION_LESS 4.8)
56- message (FATAL_ERROR "This compiler ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} is not supported. GCC 4.8 or newer is required." )
57- endif ()
58-
59- # Stop if buggy clang compiler detected.
60- elseif ("${CMAKE_CXX_COMPILER_ID} " MATCHES AppleClang)
61- if ("${CMAKE_CXX_COMPILER_VERSION} " VERSION_LESS 8.4)
62- message (FATAL_ERROR "This compiler ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} is not able to compile required libff. Install clang 4+ from Homebrew or XCode 9." )
63- endif ()
64- endif ()
27+ # Enables all the warnings about constructions that some users consider questionable,
28+ # and that are easy to avoid. Also enable some extra warning flags that are not
29+ # enabled by -Wall. Finally, treat at warnings-as-errors, which forces developers
30+ # to fix warnings as they arise, so they don't accumulate "to be fixed later".
31+ add_compile_options (-Wall)
32+ add_compile_options (-Wextra)
33+ add_compile_options (-Werror)
34+
35+ # Disable warnings about unknown pragmas (which is enabled by -Wall).
36+ add_compile_options (-Wno-unknown-pragmas)
37+
38+ # Configuration-specific compiler settings.
39+ set (CMAKE_CXX_FLAGS_DEBUG "-Og -g -DETH_DEBUG" )
40+ set (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG" )
41+ set (CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" )
42+ set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g" )
43+
44+ option (USE_LD_GOLD "Use GNU gold linker" ON )
45+ if (USE_LD_GOLD)
46+ execute_process (COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
47+ if ("${LD_VERSION} " MATCHES "GNU gold" )
48+ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold" )
49+ set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold" )
50+ endif ()
51+ endif ()
52+
53+ # Hide all symbols by default.
54+ add_compile_options (-fvisibility=hidden)
55+ if (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
56+ # Do not export symbols from dependencies.
57+ set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--exclude-libs,ALL" )
58+ endif ()
59+
60+ # Check GCC compiler version.
61+ if ("${CMAKE_CXX_COMPILER_ID} " MATCHES "GNU" )
62+ if ("${CMAKE_CXX_COMPILER_VERSION} " VERSION_LESS 5)
63+ message (FATAL_ERROR "This compiler ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} is not supported. GCC 5 or newer is required." )
64+ endif ()
65+
66+ # Stop if buggy clang compiler detected.
67+ elseif ("${CMAKE_CXX_COMPILER_ID} " MATCHES AppleClang)
68+ if ("${CMAKE_CXX_COMPILER_VERSION} " VERSION_LESS 8.4)
69+ message (FATAL_ERROR "This compiler ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} is not able to compile required libff. Install clang 4+ from Homebrew or XCode 9." )
70+ endif ()
71+ endif ()
6572
6673# The major alternative compiler to GCC/Clang is Microsoft's Visual C++ compiler, only available on Windows.
6774elseif (MSVC )
6875
69- add_compile_options (/MP) # enable parallel compilation
70- add_compile_options (/EHsc) # specify Exception Handling Model in msvc
71- add_compile_options (/WX) # enable warnings-as-errors
72- add_compile_options (/wd4068) # disable unknown pragma warning (4068)
73- add_compile_options (/wd4996) # disable unsafe function warning (4996)
74- add_compile_options (/wd4503) # disable decorated name length exceeded, name was truncated (4503)
75- add_compile_options (/wd4267) # disable conversion from 'size_t' to 'type', possible loss of data (4267)
76- add_compile_options (/wd4180) # disable qualifier applied to function type has no meaning; ignored (4180)
77- add_compile_options (/wd4290) # disable C++ exception specification ignored except to indicate a function is not __declspec(nothrow) (4290)
78- add_compile_options (/wd4297) # disable <vector>'s function assumed not to throw an exception but does (4297)
79- add_compile_options (/wd4244) # disable conversion from 'type1' to 'type2', possible loss of data (4244)
80- add_compile_options (/wd4800) # disable forcing value to bool 'true' or 'false' (performance warning) (4800)
81- add_compile_options (-D_WIN32_WINNT=0x0600) # declare Windows Vista API requirement
82- add_compile_options (-DNOMINMAX) # undefine windows.h MAX && MIN macros cause it cause conflicts with std::min && std::max functions
83- add_compile_options (-DMINIUPNP_STATICLIB) # define miniupnp static library
84-
85- # Always use Release variant of C++ runtime.
86- # We don't want to provide Debug variants of all dependencies. Some default
87- # flags set by CMake must be tweaked.
88- string (REPLACE "/MDd" "/MD" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} " )
89- string (REPLACE "/D_DEBUG" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} " )
90- string (REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} " )
91- string (REPLACE "/MDd" "/MD" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} " )
92- string (REPLACE "/D_DEBUG" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} " )
93- string (REPLACE "/RTC1" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} " )
94- set_property (GLOBAL PROPERTY DEBUG_CONFIGURATIONS OFF )
95-
96- # disable empty object file warning
97- set (CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221" )
98- # warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/SAFESEH' specification
99- # warning LNK4099: pdb was not found with lib
100- # stack size 16MB
101- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4099,4075 /STACK:16777216" )
76+ add_compile_options (/MP) # enable parallel compilation
77+ add_compile_options (/EHsc) # specify Exception Handling Model in msvc
78+ add_compile_options (/WX) # enable warnings-as-errors
79+ add_compile_options (/wd4068) # disable unknown pragma warning (4068)
80+ add_compile_options (/wd4996) # disable unsafe function warning (4996)
81+ add_compile_options (/wd4503) # disable decorated name length exceeded, name was truncated (4503)
82+ add_compile_options (/wd4267) # disable conversion from 'size_t' to 'type', possible loss of data (4267)
83+ add_compile_options (/wd4180) # disable qualifier applied to function type has no meaning; ignored (4180)
84+ add_compile_options (/wd4290) # disable C++ exception specification ignored except to indicate a function is not __declspec(nothrow) (4290)
85+ add_compile_options (/wd4297) # disable <vector>'s function assumed not to throw an exception but does (4297)
86+ add_compile_options (/wd4244) # disable conversion from 'type1' to 'type2', possible loss of data (4244)
87+ add_compile_options (/wd4800) # disable forcing value to bool 'true' or 'false' (performance warning) (4800)
88+ add_compile_options (-D_WIN32_WINNT=0x0600) # declare Windows Vista API requirement
89+ add_compile_options (-DNOMINMAX) # undefine windows.h MAX && MIN macros cause it cause conflicts with std::min && std::max functions
90+ add_compile_options (-DMINIUPNP_STATICLIB) # define miniupnp static library
91+
92+ # Always use Release variant of C++ runtime.
93+ # We don't want to provide Debug variants of all dependencies. Some default
94+ # flags set by CMake must be tweaked.
95+ string (REPLACE "/MDd" "/MD" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} " )
96+ string (REPLACE "/D_DEBUG" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} " )
97+ string (REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} " )
98+ string (REPLACE "/MDd" "/MD" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} " )
99+ string (REPLACE "/D_DEBUG" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} " )
100+ string (REPLACE "/RTC1" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} " )
101+ set_property (GLOBAL PROPERTY DEBUG_CONFIGURATIONS OFF )
102+
103+ # disable empty object file warning
104+ set (CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221" )
105+ # warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/SAFESEH' specification
106+ # warning LNK4099: pdb was not found with lib
107+ # stack size 16MB
108+ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4099,4075 /STACK:16777216" )
102109
103110# If you don't have GCC, Clang or VC++ then you are on your own. Good luck!
104111else ()
105- message (WARNING "Your compiler is not tested, if you run into any issues, we'd welcome any patches." )
112+ message (WARNING "Your compiler is not tested, if you run into any issues, we'd welcome any patches." )
106113endif ()
107114
108115if (SANITIZE)
109- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=${SANITIZE} " )
110- if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" )
111- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-blacklist=${CMAKE_SOURCE_DIR} /sanitizer-blacklist.txt" )
112- endif ()
116+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=${SANITIZE} " )
117+ if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" )
118+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-blacklist=${CMAKE_SOURCE_DIR} /sanitizer-blacklist.txt" )
119+ endif ()
113120endif ()
114121
115122option (COVERAGE "Build with code coverage support" OFF )
116123if (COVERAGE)
117- add_compile_options (-g --coverage)
118- set (CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS} " )
119- set (CMAKE_EXE_LINKER_FLAGS "--coverage ${CMAKE_EXE_LINKER_FLAGS} " )
124+ add_compile_options (-g --coverage)
125+ set (CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS} " )
126+ set (CMAKE_EXE_LINKER_FLAGS "--coverage ${CMAKE_EXE_LINKER_FLAGS} " )
120127endif ()
0 commit comments