Skip to content

Commit c98d4a4

Browse files
committed
cmake: Add REDUCE_EXPORTS option
1 parent a01cb6e commit c98d4a4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ endif()
105105
cmake_dependent_option(BUILD_WALLET_TOOL "Build bitcoin-wallet tool." ${BUILD_TESTS} "ENABLE_WALLET" OFF)
106106

107107
option(ENABLE_HARDENING "Attempt to harden the resulting executables." ON)
108+
option(REDUCE_EXPORTS "Attempt to reduce exported symbols in the resulting executables." OFF)
108109
option(WITH_CCACHE "Attempt to use ccache for compiling." ON)
109110

110111
option(WITH_NATPMP "Enable NAT-PMP." OFF)
@@ -405,6 +406,12 @@ if(ENABLE_HARDENING)
405406
endif()
406407
endif()
407408

409+
if(REDUCE_EXPORTS)
410+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
411+
try_append_linker_flag("-Wl,--exclude-libs,ALL" TARGET core_interface)
412+
try_append_linker_flag("-Wl,-no_exported_symbols" VAR CMAKE_EXE_LINKER_FLAGS)
413+
endif()
414+
408415
find_package(Python3 3.9 COMPONENTS Interpreter)
409416
if(Python3_EXECUTABLE)
410417
set(PYTHON_COMMAND ${Python3_EXECUTABLE})

0 commit comments

Comments
 (0)