Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT CMake Build System Support #1504

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
613 changes: 613 additions & 0 deletions CMakeLists.txt

Large diffs are not rendered by default.

150 changes: 150 additions & 0 deletions cmake/bitcoin-build-config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// Copyright (c) 2023-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://opensource.org/license/mit/.

#ifndef BITCOIN_CONFIG_H
#define BITCOIN_CONFIG_H

Comment on lines +1 to +7
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update copyright and namespace for Firo project

The file appears to be derived from Bitcoin Core, but needs to be updated for the Firo project:

  1. Update the copyright notice to reflect Firo ownership
  2. Replace the BITCOIN_CONFIG_H include guard with FIRO_CONFIG_H
-// Copyright (c) 2023-present The Bitcoin Core developers
+// Copyright (c) 2023-present The Firo Core developers
 // Distributed under the MIT software license, see the accompanying
 // file COPYING or https://opensource.org/license/mit/.

-#ifndef BITCOIN_CONFIG_H
-#define BITCOIN_CONFIG_H
+#ifndef FIRO_CONFIG_H
+#define FIRO_CONFIG_H
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Copyright (c) 2023-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://opensource.org/license/mit/.
#ifndef BITCOIN_CONFIG_H
#define BITCOIN_CONFIG_H
// Copyright (c) 2023-present The Firo Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://opensource.org/license/mit/.
#ifndef FIRO_CONFIG_H
#define FIRO_CONFIG_H

/* Version Build */
#define CLIENT_VERSION_BUILD @CLIENT_VERSION_BUILD@

/* Version is release */
#define CLIENT_VERSION_IS_RELEASE @CLIENT_VERSION_IS_RELEASE@

/* Major version */
#define CLIENT_VERSION_MAJOR @CLIENT_VERSION_MAJOR@

/* Minor version */
#define CLIENT_VERSION_MINOR @CLIENT_VERSION_MINOR@

/* Copyright holder(s) before %s replacement */
#define COPYRIGHT_HOLDERS "@COPYRIGHT_HOLDERS@"

/* Copyright holder(s) */
#define COPYRIGHT_HOLDERS_FINAL "@COPYRIGHT_HOLDERS_FINAL@"

/* Replacement for %s in copyright holders string */
#define COPYRIGHT_HOLDERS_SUBSTITUTION "@CLIENT_NAME@"

/* Copyright year */
#define COPYRIGHT_YEAR @COPYRIGHT_YEAR@

/* Define this symbol to build code that uses ARMv8 SHA-NI intrinsics */
#cmakedefine ENABLE_ARM_SHANI 1

/* Define this symbol to build code that uses AVX2 intrinsics */
#cmakedefine ENABLE_AVX2 1

/* Define if external signer support is enabled */
#cmakedefine ENABLE_EXTERNAL_SIGNER 1

/* Define this symbol to build code that uses SSE4.1 intrinsics */
#cmakedefine ENABLE_SSE41 1

/* Define to 1 to enable tracepoints for Userspace, Statically Defined Tracing
*/
#cmakedefine ENABLE_TRACING 1

/* Define to 1 to enable wallet functions. */
#cmakedefine ENABLE_WALLET 1

/* Define this symbol to build code that uses x86 SHA-NI intrinsics */
#cmakedefine ENABLE_X86_SHANI 1

/* Define to 1 if you have the declaration of `fork', and to 0 if you don't.
*/
#cmakedefine01 HAVE_DECL_FORK

/* Define to 1 if you have the declaration of `freeifaddrs', and to 0 if you
don't. */
#cmakedefine01 HAVE_DECL_FREEIFADDRS

/* Define to 1 if you have the declaration of `getifaddrs', and to 0 if you
don't. */
#cmakedefine01 HAVE_DECL_GETIFADDRS

/* Define to 1 if you have the declaration of `pipe2', and to 0 if you don't.
*/
#cmakedefine01 HAVE_DECL_PIPE2

/* Define to 1 if you have the declaration of `setsid', and to 0 if you don't.
*/
#cmakedefine01 HAVE_DECL_SETSID

/* Define to 1 if fdatasync is available. */
#cmakedefine HAVE_FDATASYNC 1

/* Define this symbol if the BSD getentropy system call is available with
sys/random.h */
#cmakedefine HAVE_GETENTROPY_RAND 1

/* Define this symbol if the Linux getrandom function call is available */
#cmakedefine HAVE_GETRANDOM 1

/* Define this symbol if you have malloc_info */
#cmakedefine HAVE_MALLOC_INFO 1

/* Define this symbol if you have mallopt with M_ARENA_MAX */
#cmakedefine HAVE_MALLOPT_ARENA_MAX 1

/* Define to 1 if O_CLOEXEC flag is available. */
#cmakedefine01 HAVE_O_CLOEXEC

/* Define this symbol if you have posix_fallocate */
#cmakedefine HAVE_POSIX_FALLOCATE 1

/* Define this symbol if platform supports unix domain sockets */
#cmakedefine HAVE_SOCKADDR_UN 1

/* Define this symbol to build code that uses getauxval */
#cmakedefine HAVE_STRONG_GETAUXVAL 1

/* Define this symbol if the BSD sysctl() is available */
#cmakedefine HAVE_SYSCTL 1

/* Define this symbol if the BSD sysctl(KERN_ARND) is available */
#cmakedefine HAVE_SYSCTL_ARND 1

/* Define to 1 if std::system or ::wsystem is available. */
#cmakedefine HAVE_SYSTEM 1

/* Define to 1 if you have the <sys/prctl.h> header file. */
#cmakedefine HAVE_SYS_PRCTL_H 1

/* Define to 1 if you have the <sys/resources.h> header file. */
#cmakedefine HAVE_SYS_RESOURCES_H 1

/* Define to 1 if you have the <sys/vmmeter.h> header file. */
#cmakedefine HAVE_SYS_VMMETER_H 1

/* Define to 1 if you have the <vm/vm_param.h> header file. */
#cmakedefine HAVE_VM_VM_PARAM_H 1

/* Define to the address where bug reports for this package should be sent. */
#define CLIENT_BUGREPORT "@CLIENT_BUGREPORT@"

/* Define to the full name of this package. */
#define CLIENT_NAME "@CLIENT_NAME@"

/* Define to the home page for this package. */
#define CLIENT_URL "@PROJECT_HOMEPAGE_URL@"

/* Define to the version of this package. */
#define CLIENT_VERSION_STRING "@CLIENT_VERSION_STRING@"

/* Define to 1 if strerror_r returns char *. */
#cmakedefine STRERROR_R_CHAR_P 1

/* Define if BDB support should be compiled in */
#cmakedefine USE_BDB 1

/* Define if dbus support should be compiled in */
#cmakedefine USE_DBUS 1

/* Define if QR support should be compiled in */
#cmakedefine USE_QRCODE 1

/* Define if sqlite support should be compiled in */
#cmakedefine USE_SQLITE 1

#endif //BITCOIN_CONFIG_H
28 changes: 28 additions & 0 deletions cmake/ccache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

if(NOT MSVC)
find_program(CCACHE_EXECUTABLE ccache)
if(CCACHE_EXECUTABLE)
execute_process(
COMMAND readlink -f ${CMAKE_CXX_COMPILER}
OUTPUT_VARIABLE compiler_resolved_link
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
Comment on lines +9 to +13
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance portability by avoiding readlink command

Using readlink -f may not be portable across all Unix-like systems (e.g., macOS). To improve portability, use CMake's built-in functions to resolve the compiler's real path.

Replace the execute_process command with get_filename_component:

-execute_process(
-  COMMAND readlink -f ${CMAKE_CXX_COMPILER}
-  OUTPUT_VARIABLE compiler_resolved_link
-  ERROR_QUIET
-  OUTPUT_STRIP_TRAILING_WHITESPACE
-)
+get_filename_component(compiler_resolved_link ${CMAKE_CXX_COMPILER} REALPATH)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
COMMAND readlink -f ${CMAKE_CXX_COMPILER}
OUTPUT_VARIABLE compiler_resolved_link
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
get_filename_component(compiler_resolved_link ${CMAKE_CXX_COMPILER} REALPATH)

if(CCACHE_EXECUTABLE STREQUAL compiler_resolved_link AND NOT WITH_CCACHE)
list(APPEND configure_warnings
"Disabling ccache was attempted using -DWITH_CCACHE=${WITH_CCACHE}, but ccache masquerades as the compiler."
)
set(WITH_CCACHE ON)
elseif(WITH_CCACHE)
list(APPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
endif()
else()
set(WITH_CCACHE OFF)
endif()
endif()

mark_as_advanced(CCACHE_EXECUTABLE)
5 changes: 5 additions & 0 deletions cmake/cov_tool_wrapper.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) 2024-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

exec @COV_TOOL@ "$@"
123 changes: 123 additions & 0 deletions cmake/crc32c.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

# This file is part of the transition from Autotools to CMake. Once CMake
# support has been merged we should switch to using the upstream CMake
# buildsystem.

include(CheckCXXSourceCompiles)

# Check for __builtin_prefetch support in the compiler.
check_cxx_source_compiles("
int main() {
char data = 0;
const char* address = &data;
__builtin_prefetch(address, 0, 0);
return 0;
}
" HAVE_BUILTIN_PREFETCH
)

# Check for _mm_prefetch support in the compiler.
check_cxx_source_compiles("
#if defined(_MSC_VER)
#include <intrin.h>
#else
#include <xmmintrin.h>
#endif

int main() {
char data = 0;
const char* address = &data;
_mm_prefetch(address, _MM_HINT_NTA);
return 0;
}
" HAVE_MM_PREFETCH
)

# Check for SSE4.2 support in the compiler.
if(MSVC)
set(SSE42_CXXFLAGS /arch:AVX)
else()
set(SSE42_CXXFLAGS -msse4.2)
endif()
check_cxx_source_compiles_with_flags("${SSE42_CXXFLAGS}" "
#include <cstdint>
#if defined(_MSC_VER)
#include <intrin.h>
#elif defined(__GNUC__) && defined(__SSE4_2__)
#include <nmmintrin.h>
#endif

int main() {
uint64_t l = 0;
l = _mm_crc32_u8(l, 0);
l = _mm_crc32_u32(l, 0);
l = _mm_crc32_u64(l, 0);
return l;
}
" HAVE_SSE42
)
Comment on lines +45 to +61
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Replace check_cxx_source_compiles_with_flags with standard CMake functions

The function check_cxx_source_compiles_with_flags is not a standard CMake function and may cause compatibility issues. To check for SSE4.2 support with specific compiler flags, you can set CMAKE_REQUIRED_FLAGS before calling check_cxx_source_compiles.

Apply the following changes to replace the function:

+set(CMAKE_REQUIRED_FLAGS "${SSE42_CXXFLAGS}")
 check_cxx_source_compiles("
   #include <cstdint>
   #if defined(_MSC_VER)
   #include <intrin.h>
   #elif defined(__GNUC__) && defined(__SSE4_2__)
   #include <nmmintrin.h>
   #endif

   int main() {
       uint64_t l = 0;
       l = _mm_crc32_u8(l, 0);
       l = _mm_crc32_u32(l, 0);
       l = _mm_crc32_u64(l, 0);
       return l;
     }
 " HAVE_SSE42)
+unset(CMAKE_REQUIRED_FLAGS)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
check_cxx_source_compiles_with_flags("${SSE42_CXXFLAGS}" "
#include <cstdint>
#if defined(_MSC_VER)
#include <intrin.h>
#elif defined(__GNUC__) && defined(__SSE4_2__)
#include <nmmintrin.h>
#endif
int main() {
uint64_t l = 0;
l = _mm_crc32_u8(l, 0);
l = _mm_crc32_u32(l, 0);
l = _mm_crc32_u64(l, 0);
return l;
}
" HAVE_SSE42
)
set(CMAKE_REQUIRED_FLAGS "${SSE42_CXXFLAGS}")
check_cxx_source_compiles("
#include <cstdint>
#if defined(_MSC_VER)
#include <intrin.h>
#elif defined(__GNUC__) && defined(__SSE4_2__)
#include <nmmintrin.h>
#endif
int main() {
uint64_t l = 0;
l = _mm_crc32_u8(l, 0);
l = _mm_crc32_u32(l, 0);
l = _mm_crc32_u64(l, 0);
return l;
}
" HAVE_SSE42)
unset(CMAKE_REQUIRED_FLAGS)


# Check for ARMv8 w/ CRC and CRYPTO extensions support in the compiler.
set(ARM64_CRC_CXXFLAGS -march=armv8-a+crc+crypto)
check_cxx_source_compiles_with_flags("${ARM64_CRC_CXXFLAGS}" "
#include <arm_acle.h>
#include <arm_neon.h>

int main() {
#ifdef __aarch64__
__crc32cb(0, 0); __crc32ch(0, 0); __crc32cw(0, 0); __crc32cd(0, 0);
vmull_p64(0, 0);
#else
#error crc32c library does not support hardware acceleration on 32-bit ARM
#endif
return 0;
}
" HAVE_ARM64_CRC32C
)
Comment on lines +65 to +79
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Replace check_cxx_source_compiles_with_flags with standard CMake functions

Similarly, check_cxx_source_compiles_with_flags is not a standard function. Use CMAKE_REQUIRED_FLAGS to include compiler flags when checking for ARM64 CRC32C support.

Here's how you can adjust the code:

+set(CMAKE_REQUIRED_FLAGS "${ARM64_CRC_CXXFLAGS}")
 check_cxx_source_compiles("
   #include <arm_acle.h>
   #include <arm_neon.h>

   int main() {
   #ifdef __aarch64__
     __crc32cb(0, 0); __crc32ch(0, 0); __crc32cw(0, 0); __crc32cd(0, 0);
     vmull_p64(0, 0);
   #else
   #error crc32c library does not support hardware acceleration on 32-bit ARM
   #endif
     return 0;
   }
 " HAVE_ARM64_CRC32C)
+unset(CMAKE_REQUIRED_FLAGS)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
check_cxx_source_compiles_with_flags("${ARM64_CRC_CXXFLAGS}" "
#include <arm_acle.h>
#include <arm_neon.h>
int main() {
#ifdef __aarch64__
__crc32cb(0, 0); __crc32ch(0, 0); __crc32cw(0, 0); __crc32cd(0, 0);
vmull_p64(0, 0);
#else
#error crc32c library does not support hardware acceleration on 32-bit ARM
#endif
return 0;
}
" HAVE_ARM64_CRC32C
)
set(CMAKE_REQUIRED_FLAGS "${ARM64_CRC_CXXFLAGS}")
check_cxx_source_compiles("
#include <arm_acle.h>
#include <arm_neon.h>
int main() {
#ifdef __aarch64__
__crc32cb(0, 0); __crc32ch(0, 0); __crc32cw(0, 0); __crc32cd(0, 0);
vmull_p64(0, 0);
#else
#error crc32c library does not support hardware acceleration on 32-bit ARM
#endif
return 0;
}
" HAVE_ARM64_CRC32C)
unset(CMAKE_REQUIRED_FLAGS)


add_library(crc32c_common INTERFACE)
target_compile_definitions(crc32c_common INTERFACE
HAVE_BUILTIN_PREFETCH=$<BOOL:${HAVE_BUILTIN_PREFETCH}>
HAVE_MM_PREFETCH=$<BOOL:${HAVE_MM_PREFETCH}>
HAVE_STRONG_GETAUXVAL=$<BOOL:${HAVE_STRONG_GETAUXVAL}>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Undefined variable HAVE_STRONG_GETAUXVAL

The variable HAVE_STRONG_GETAUXVAL is used in target_compile_definitions, but it is not defined anywhere in the file. This may lead to incorrect compile-time configurations.

Consider defining HAVE_STRONG_GETAUXVAL if it is required, or remove it from target_compile_definitions if it is unnecessary.

BYTE_ORDER_BIG_ENDIAN=$<STREQUAL:${CMAKE_CXX_BYTE_ORDER},BIG_ENDIAN>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Undefined variable CMAKE_CXX_BYTE_ORDER

CMAKE_CXX_BYTE_ORDER is not a standard CMake variable. To determine the byte order, you should use the TestBigEndian module provided by CMake.

Include the TestBigEndian module and adjust the code as follows:

+include(TestBigEndian)
+TEST_BIG_ENDIAN(IS_BIG_ENDIAN)

Then, modify target_compile_definitions:

-BYTE_ORDER_BIG_ENDIAN=$<STREQUAL:${CMAKE_CXX_BYTE_ORDER},BIG_ENDIAN>
+BYTE_ORDER_BIG_ENDIAN=$<BOOL:${IS_BIG_ENDIAN}>

Committable suggestion skipped: line range outside the PR's diff.

HAVE_SSE42=$<BOOL:${HAVE_SSE42}>
HAVE_ARM64_CRC32C=$<BOOL:${HAVE_ARM64_CRC32C}>
)
target_link_libraries(crc32c_common INTERFACE
core_interface
)

add_library(crc32c STATIC EXCLUDE_FROM_ALL
${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c.cc
${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_portable.cc
)
target_include_directories(crc32c
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/crc32c/include>
)
target_link_libraries(crc32c PRIVATE crc32c_common)
set_target_properties(crc32c PROPERTIES EXPORT_COMPILE_COMMANDS OFF)

if(HAVE_SSE42)
add_library(crc32c_sse42 STATIC EXCLUDE_FROM_ALL
${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_sse42.cc
)
target_compile_options(crc32c_sse42 PRIVATE ${SSE42_CXXFLAGS})
target_link_libraries(crc32c_sse42 PRIVATE crc32c_common)
set_target_properties(crc32c_sse42 PROPERTIES EXPORT_COMPILE_COMMANDS OFF)
target_link_libraries(crc32c PRIVATE crc32c_sse42)
endif()

if(HAVE_ARM64_CRC32C)
add_library(crc32c_arm64 STATIC EXCLUDE_FROM_ALL
${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_arm64.cc
)
target_compile_options(crc32c_arm64 PRIVATE ${ARM64_CRC_CXXFLAGS})
target_link_libraries(crc32c_arm64 PRIVATE crc32c_common)
set_target_properties(crc32c_arm64 PROPERTIES EXPORT_COMPILE_COMMANDS OFF)
target_link_libraries(crc32c PRIVATE crc32c_arm64)
endif()
Loading
Loading