Skip to content

Commit

Permalink
[CMAKE] Use plural form when multiple arguments are expected
Browse files Browse the repository at this point in the history
Summary:
Some `add_xxx_flag()` functions can actually take multiple flags are
argument. Rename them to `add_xxx_flags()` (note the 's') makes it
clearer and more consistent with other function names.

There is no behavior change.

Test Plan:
  ninja check

Reviewers: #bitcoin_abc, deadalnix, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D3801
  • Loading branch information
Fabcien committed Aug 6, 2019
1 parent e5f0bbd commit b7e198b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
12 changes: 6 additions & 6 deletions cmake/modules/AddCompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function(check_compiler_flag RESULT LANGUAGE FLAG)
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})
Expand All @@ -26,7 +26,7 @@ function(add_c_compiler_flag)
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})
Expand All @@ -36,9 +36,9 @@ function(add_cxx_compiler_flag)
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)
Expand Down Expand Up @@ -97,7 +97,7 @@ endfunction()
# 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)

Expand Down
34 changes: 17 additions & 17 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
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)
Expand All @@ -81,38 +81,38 @@ if(ENABLE_REDUCE_EXPORTS)
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
Expand All @@ -121,8 +121,8 @@ if(ENABLE_HARDENING)
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
Expand All @@ -138,10 +138,10 @@ add_compiler_flag(

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
Expand Down Expand Up @@ -229,8 +229,8 @@ if(ENABLE_GLIBC_BACK_COMPAT)
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()
Expand Down
4 changes: 2 additions & 2 deletions src/leveldb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ project(Leveldb VERSION 0.1.0 LANGUAGES C CXX)
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)
Expand Down
4 changes: 2 additions & 2 deletions src/secp256k1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ cmake_minimum_required(VERSION 3.5)
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
)
Expand Down

0 comments on commit b7e198b

Please sign in to comment.