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.
This commit is contained in:
Cory Fields 2025-02-05 18:28:30 +00:00
parent 1172bc4157
commit 5ca103aac6

View File

@ -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