build: Add option for building for bare metal envs
What changed, and why it matters
This commit adds a new build option for Bitcoin Core that lets developers compile for 'bare metal' environments (systems without a full operating system). It only changes build configuration files to skip features like threads, atomics, and certain crypto components when the special CMAKE_SYSTEM_NAME=Generic setting is used. There is no change to the actual Bitcoin protocol code or to how normal builds work, and nothing in the commit suggests a security vulnerability or fix.
No security action required. Treat as a normal build-system feature addition. If reviewing further, verify that Generic builds do not accidentally weaken security assumptions in production code paths, but that is outside the scope of this commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit introduces conditional CMake logic keyed on CMAKE_SYSTEM_NAME STREQUAL ‘Generic’. When this bare-metal target is selected, it skips PIE linker checks, the Threads package, Boost header dependency, atomic library introspection, and excludes aes.cpp and lockedpool.cpp from the bitcoin_crypto static library. For non-Generic builds, behavior is unchanged. The change is purely build-system scaffolding for an unsupported/experimental target.
Changed components
CMakeLists.txtcmake/introspection.cmakesrc/CMakeLists.txtsrc/crypto/CMakeLists.txtsrc/test/util/CMakeLists.txtInspect captured patch +12 / −4
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 69db01f2..f09cec1b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -204,22 +204,28 @@ endif()
# Check and set PIC/PIE
#=============================
set(configure_warnings)
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")
include(CheckLinkerSupportsPIE)
# Set CMAKE_POSITION_INDEPENDENT_CODE early so it applies to all
# subsequent checks, including dependency packages and tool flags.
check_linker_supports_pie(configure_warnings)
+endif()
#=============================
# Find dependencies
#=============================
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(core_interface INTERFACE
Threads::Threads
)
+endif()
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")
include(AddBoostIfNeeded)
add_boost_if_needed()
+endif()
if(ENABLE_WALLET)
if(VCPKG_TARGET_TRIPLET)
diff --git a/cmake/introspection.cmake b/cmake/introspection.cmake
index d2257633..d6083f52 100644
--- a/cmake/introspection.cmake
+++ b/cmake/introspection.cmake
@@ -17,7 +17,9 @@ if(NOT WIN32)
endif()
include(TestAppendRequiredLibraries)
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")
test_append_atomic_library(core_interface)
+endif()
# Even though ::system is part of the standard library, we still check
# for it, to support building targets that don't have it, such as iOS.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8c0977f0..47266dcf 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -289,7 +289,7 @@ target_link_libraries(bitcoin_node
leveldb
minisketch
univalue
- Boost::headers
+ $<TARGET_NAME_IF_EXISTS:Boost::headers>
$<TARGET_NAME_IF_EXISTS:USDT::headers>
)
if(WITH_EMBEDDED_ASMAP)
diff --git a/src/crypto/CMakeLists.txt b/src/crypto/CMakeLists.txt
index 4dc84664..e1993a7f 100644
--- a/src/crypto/CMakeLists.txt
+++ b/src/crypto/CMakeLists.txt
@@ -3,7 +3,7 @@
# file COPYING or https://opensource.org/license/mit/.
add_library(bitcoin_crypto STATIC EXCLUDE_FROM_ALL
- aes.cpp
+ $<$<NOT:$<STREQUAL:${CMAKE_SYSTEM_NAME},Generic>>:aes.cpp>
chacha20.cpp
chacha20poly1305.cpp
hex_base.cpp
@@ -20,7 +20,7 @@ add_library(bitcoin_crypto STATIC EXCLUDE_FROM_ALL
sha512.cpp
siphash.cpp
../support/cleanse.cpp
- ../support/lockedpool.cpp
+ $<$<NOT:$<STREQUAL:${CMAKE_SYSTEM_NAME},Generic>>:../support/lockedpool.cpp>
)
target_link_libraries(bitcoin_crypto
diff --git a/src/test/util/CMakeLists.txt b/src/test/util/CMakeLists.txt
index 5d9832fc..2658809d 100644
--- a/src/test/util/CMakeLists.txt
+++ b/src/test/util/CMakeLists.txt
@@ -23,7 +23,7 @@ add_library(test_util STATIC EXCLUDE_FROM_ALL
target_link_libraries(test_util
PRIVATE
core_interface
- Boost::headers
+ $<TARGET_NAME_IF_EXISTS:Boost::headers>
$<$<BOOL:${ENABLE_WALLET}>:SQLite3::SQLite3>
PUBLIC
univalue
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.