diff --git a/cmake/modules/AddCompilerFlags.cmake b/cmake/modules/AddCompilerFlags.cmake --- a/cmake/modules/AddCompilerFlags.cmake +++ b/cmake/modules/AddCompilerFlags.cmake @@ -16,7 +16,7 @@ set(${RESULT} ${${TEST_NAME}} PARENT_SCOPE) endfunction() -function(add_c_compiler_flag) +function(add_c_compiler_flags) foreach(f ${ARGN}) check_compiler_flag(FLAG_IS_SUPPORTED C ${f}) if(${FLAG_IS_SUPPORTED}) @@ -26,7 +26,7 @@ set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} PARENT_SCOPE) endfunction() -function(add_cxx_compiler_flag) +function(add_cxx_compiler_flags) foreach(f ${ARGN}) check_compiler_flag(FLAG_IS_SUPPORTED CXX ${f}) if(${FLAG_IS_SUPPORTED}) @@ -36,9 +36,9 @@ set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} PARENT_SCOPE) endfunction() -macro(add_compiler_flag) - add_c_compiler_flag(${ARGN}) - add_cxx_compiler_flag(${ARGN}) +macro(add_compiler_flags) + add_c_compiler_flags(${ARGN}) + add_cxx_compiler_flags(${ARGN}) endmacro() macro(remove_c_compiler_flags) @@ -97,7 +97,7 @@ # However since CMake 3.2 introduced the CMP0056 policy, the # CMAKE_EXE_LINKER_FLAGS variable is used by the try_compile function, so there # is a workaround that allow for testing the linker flags. -function(add_linker_flag) +function(add_linker_flags) foreach(f ${ARGN}) sanitize_c_cxx_definition("have_linker_" ${f} FLAG_IS_SUPPORTED) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -67,7 +67,7 @@ list(APPEND CMAKE_RC_FLAGS "-DWINDRES_PREPROC") # Build all static so there is no dll file to distribute. - add_compiler_flag(-static) + add_compiler_flags(-static) endif() if(ENABLE_REDUCE_EXPORTS) @@ -81,38 +81,38 @@ endif() # Also hide symbols from static libraries - add_linker_flag(-Wl,--exclude-libs,ALL) + add_linker_flags(-Wl,--exclude-libs,ALL) endif() # Enable statically linking libstdc++ if(ENABLE_STATIC_LIBSTDCXX) - add_linker_flag(-static-libstdc++) + add_linker_flags(-static-libstdc++) endif() # All windows code is PIC, forcing it on just adds useless compile warnings if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") - add_compiler_flag(-fPIC) + add_compiler_flags(-fPIC) endif() if(ENABLE_HARDENING) # Enable stack protection - add_cxx_compiler_flag(-fstack-protector-all -Wstack-protector) + add_cxx_compiler_flags(-fstack-protector-all -Wstack-protector) # Enable some buffer overflow checking - add_compiler_flag(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2) + add_compiler_flags(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2) # Enable ASLR (these flags are primarily targeting MinGw) - add_linker_flag(-Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va) + add_linker_flags(-Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va) # Make the relocated sections read-only - add_linker_flag(-Wl,-z,relro -Wl,-z,now) + add_linker_flags(-Wl,-z,relro -Wl,-z,now) # CMake provides the POSITION_INDEPENDENT_CODE property to set PIC/PIE. # Unfortunately setting the -pie linker flag this way require CMake >= 3.14, # which is not widely distributed at the time of writing. # FIXME: use the POSITION_INDEPENDENT_CODE property instead - add_compiler_flag(-fPIE) - add_linker_flag(-pie) + add_compiler_flags(-fPIE) + add_linker_flags(-pie) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") # MinGw provides its own libssp for stack smashing protection @@ -121,8 +121,8 @@ endif() # Enable warning -add_c_compiler_flag(-Wnested-externs -Wstrict-prototypes) -add_compiler_flag( +add_c_compiler_flags(-Wnested-externs -Wstrict-prototypes) +add_compiler_flags( -Wall -Wextra -Wformat @@ -138,10 +138,10 @@ option(EXTRA_WARNINGS "Enable extra warnings" OFF) if(EXTRA_WARNINGS) - add_cxx_compiler_flag(-Wsuggest-override) + add_cxx_compiler_flags(-Wsuggest-override) else() - add_compiler_flag(-Wno-unused-parameter) - add_compiler_flag(-Wno-implicit-fallthrough) + add_compiler_flags(-Wno-unused-parameter) + add_compiler_flags(-Wno-implicit-fallthrough) endif() # Create a target for OpenSSL @@ -229,8 +229,8 @@ target_compile_definitions(util PRIVATE "-DFDELT_TYPE=${FDELT_TYPE}") # Wrap some glibc functions with ours - add_linker_flag(-Wl,--wrap=__divmoddi4) - add_linker_flag(-Wl,--wrap=log2f) + add_linker_flags(-Wl,--wrap=__divmoddi4) + add_linker_flags(-Wl,--wrap=log2f) target_sources(util PRIVATE compat/glibc_compat.cpp) endif() diff --git a/src/leveldb/CMakeLists.txt b/src/leveldb/CMakeLists.txt --- a/src/leveldb/CMakeLists.txt +++ b/src/leveldb/CMakeLists.txt @@ -9,8 +9,8 @@ set(CMAKE_CXX_STANDARD 11) # Remove some warnings for leveldb as they can get noisy. -add_compiler_flag(-Wno-sign-compare -Wno-implicit-fallthrough) -add_c_compiler_flag(-Wno-strict-prototypes) +add_compiler_flags(-Wno-sign-compare -Wno-implicit-fallthrough) +add_c_compiler_flags(-Wno-strict-prototypes) remove_compiler_flags(-Wstrict-prototypes) include(CheckIncludeFileCXX) diff --git a/src/secp256k1/CMakeLists.txt b/src/secp256k1/CMakeLists.txt --- a/src/secp256k1/CMakeLists.txt +++ b/src/secp256k1/CMakeLists.txt @@ -4,13 +4,13 @@ project(secp256k1) # libsecp256k1 use a different set of flags. -add_compiler_flag( +add_compiler_flags( -pedantic -Wno-unused-function -Wno-overlength-strings ) -add_c_compiler_flag( +add_c_compiler_flags( -std=c89 -Wno-long-long )