From 5ca103aac6a49c414c852cdd2d1a36b166db702c Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Wed, 5 Feb 2025 18:28:30 +0000 Subject: [PATCH] build: add kernel-specific warnings In some cases, we'll want to be more aggressive or care about different things when building the kernel. In this case, a warning is added for symbols which may be duplicated between the kernel and downstream users. A few caveats for now: - This warning is introduced in clang 21, which is not yet released - The warning doesn't actually show unless the CXX_VISIBILITY_PRESET hack is disabled in CMake, which won't happen for a while. So this warning is not helpful for CI at the moment, but it's possible to use it manually (as I have for this PR) by disabling the hack locally until then. --- src/kernel/CMakeLists.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 2e07ba042a4..48daf8fcd63 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -78,9 +78,25 @@ add_library(bitcoinkernel ../validationinterface.cpp ../versionbits.cpp ) + +# Compiler warnings that apply only to the kernel and its dependencies. +# These can be more strict and/or warnings that only apply to shared +# libs. +add_library(kernel_warn_interface INTERFACE) +if(MSVC) +else() + try_append_cxx_flags("-Wunique-object-duplication" TARGET kernel_warn_interface SKIP_LINK) +endif() + +# Also manually apply the warnings to the kernel's internal dependencies +target_link_libraries(bitcoin_clientversion PRIVATE kernel_warn_interface) +target_link_libraries(bitcoin_crypto PRIVATE kernel_warn_interface) +target_link_libraries(leveldb PRIVATE kernel_warn_interface) + target_link_libraries(bitcoinkernel PRIVATE core_interface + kernel_warn_interface bitcoin_clientversion bitcoin_crypto leveldb