forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #6: build: Add CMake-based build system (2 of N)
df89945 cmake: Build `leveldb` static library (Hennadii Stepanov) 2e2ce85 cmake: Build `crc32c` static library (Hennadii Stepanov) 4cd5efd cmake: Check compiler features (Hennadii Stepanov) 89be42f cmake: Check system symbols (Hennadii Stepanov) 64b1fd4 cmake: Check system headers (Hennadii Stepanov) 7b87a48 cmake: Add `cmake/introspection.cmake` file (Hennadii Stepanov) Pull request description: The parent PR: bitcoin#25797. The previous PR in the staging branch: #5. This PR details: 1. Added project-wide system introspection. | Autoconf macro | Symbols in `bitcoin-config.h` | CMake implementation | |---|---|---| | [`AC_INIT`](https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/autoconf.html#Initializing-configure) | `PACKAGE_NAME` `PACKAGE_TARNAME` `PACKAGE_VERSION` `PACKAGE_STRING` `PACKAGE_BUGREPORT` `PACKAGE_URL` | Done in #5, except for `PACKAGE_TARNAME` and `PACKAGE_STRING`, which are not currently used | | [`AX_CXX_COMPILE_STDCXX`](https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html) | `HAVE_CXX17` `HAVE_CXX20` | CMake uses its own [implementation](https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html) | | [`AC_C_BIGENDIAN`](https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/autoconf.html#index-AC_005fC_005fBIGENDIAN-892) | `AC_APPLE_UNIVERSAL_BUILD` `WORDS_BIGENDIAN` and C headers | CMake uses its own [implementation](https://cmake.org/cmake/help/latest/module/TestBigEndian.html) | | [`AX_PTHREAD`](https://www.gnu.org/software/autoconf-archive/ax_pthread.html) | `HAVE_PTHREAD` `HAVE_PTHREAD_PRIO_INHERIT` `PTHREAD_CREATE_JOINABLE` | CMake uses its own [implementation](https://cmake.org/cmake/help/latest/module/FindThreads.html) | | [`AC_SYS_LARGEFILE`](https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/autoconf.html#index-AC_005fSYS_005fLARGEFILE-1103) | `_FILE_OFFSET_BITS` `_LARGE_FILES` | _Not implemented yet_ | | [`AC_FUNC_STRERROR_R`](https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/autoconf.html#index-AC_005fFUNC_005fSTRERROR_005fR-517) | `HAVE_DECL_STRERROR_R` `HAVE_STRERROR_R` `STRERROR_R_CHAR_P` and C headers | Implemented `STRERROR_R_CHAR_P`, others are not used | C headers | `HAVE_INTTYPES_H` `HAVE_STDINT_H` `HAVE_STDIO_H` `HAVE_STDLIB_H` `HAVE_STRINGS_H` `HAVE_STRING_H` `HAVE_SYS_STAT_H` `HAVE_SYS_TYPES_H` `HAVE_UNISTD_H` `STDC_HEADERS` | Only `HAVE_STRING_H`, `HAVE_SYS_TYPES_H` and `HAVE_UNISTD_H` are evaluated for internal needs --- 2. Added the `leveldb` build target (including its `crc32c` dependency): - on Linux / *BSD / macOS: ```sh cmake -S . -B build cmake --build build --target leveldb ``` - on Windows: ```cmd cmake -G "Visual Studio 17 2022" -A x64 -S . -B build cmake --build build --config Debug --target leveldb # or --config Release ``` **NOTE**. On Windows (MSVC), the `leveldb` library now uses `crc32c` one. That is not the case when using the current build system from the `build_msvc` directory: https://github.com/hebasto/bitcoin/blob/fe1b3256888bd0e70d0c9655f565e139ec87b606/build_msvc/libleveldb/libleveldb.vcxproj#L53 ACKs for top commit: theuni: > ACK [df89945](df89945) TheCharlatan: ACK df89945 Tree-SHA512: 9a7a4e2d22d5e18af20fec937f64ce43b5c296576abde61db3e4420edadb87d2e830d331fabbf4e8c17e557bf9bd534f491b227d2554839651967f20707bba7b
- Loading branch information
Showing
6 changed files
with
676 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Copyright (c) 2023 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
# 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 | ||
) | ||
|
||
# Check for ARMv8 w/ CRC and CRYPTO extensions support in the compiler. | ||
set(ARM_CRC_CXXFLAGS -march=armv8-a+crc) | ||
check_cxx_source_compiles_with_flags("${ARM_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 | ||
) | ||
|
||
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_compile_definitions(crc32c | ||
PRIVATE | ||
HAVE_BUILTIN_PREFETCH=$<BOOL:${HAVE_BUILTIN_PREFETCH}> | ||
HAVE_MM_PREFETCH=$<BOOL:${HAVE_MM_PREFETCH}> | ||
HAVE_STRONG_GETAUXVAL=$<BOOL:${HAVE_STRONG_GETAUXVAL}> | ||
HAVE_SSE42=$<BOOL:${HAVE_SSE42}> | ||
HAVE_ARM64_CRC32C=$<BOOL:${HAVE_ARM64_CRC32C}> | ||
BYTE_ORDER_BIG_ENDIAN=${WORDS_BIGENDIAN} | ||
) | ||
|
||
target_include_directories(crc32c | ||
PUBLIC | ||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/crc32c/include> | ||
) | ||
|
||
if(HAVE_SSE42) | ||
target_sources(crc32c PRIVATE ${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_sse42.cc) | ||
set_property(SOURCE ${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_sse42.cc | ||
APPEND PROPERTY COMPILE_OPTIONS ${SSE42_CXXFLAGS} | ||
) | ||
endif() | ||
|
||
if(HAVE_ARM64_CRC32C) | ||
target_sources(crc32c PRIVATE ${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_arm64.cc) | ||
set_property(SOURCE ${PROJECT_SOURCE_DIR}/src/crc32c/src/crc32c_arm64.cc | ||
APPEND PROPERTY COMPILE_OPTIONS ${ARM_CRC_CXXFLAGS} | ||
) | ||
endif() |
Oops, something went wrong.