Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1# Copyright 2017 The CRC32C Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file. See the AUTHORS file for names of contributors.5cmake_minimum_required(VERSION 3.1)6project(Crc32c VERSION 1.1.0 LANGUAGES C CXX)8# C standard can be overridden when this is used as a sub-project.9if(NOT CMAKE_C_STANDARD)10# This project can use C11, but will gracefully decay down to C89.11set(CMAKE_C_STANDARD 11)12set(CMAKE_C_STANDARD_REQUIRED OFF)13set(CMAKE_C_EXTENSIONS OFF)14endif(NOT CMAKE_C_STANDARD)16# C++ standard can be overridden when this is used as a sub-project.17if(NOT CMAKE_CXX_STANDARD)18# This project requires C++11.19set(CMAKE_CXX_STANDARD 11)20set(CMAKE_CXX_STANDARD_REQUIRED ON)21set(CMAKE_CXX_EXTENSIONS OFF)22endif(NOT CMAKE_CXX_STANDARD)24# https://github.com/izenecloud/cmake/blob/master/SetCompilerWarningAll.cmake25if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")26# Use the highest warning level for Visual Studio.27set(CMAKE_CXX_WARNING_LEVEL 4)28if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")29string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")30else(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")31set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")32endif(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")34# Disable C++ exceptions.35string(REGEX REPLACE "/EH[a-z]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")36set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")37add_definitions(-D_HAS_EXCEPTIONS=0)39# Disable RTTI.40string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")41set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")42else(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")43# Use -Wall for clang and gcc.44if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")45set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")46endif(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")48# Use -Wextra for clang and gcc.49if(NOT CMAKE_CXX_FLAGS MATCHES "-Wextra")50set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")51endif(NOT CMAKE_CXX_FLAGS MATCHES "-Wextra")53# Use -Werror for clang and gcc.54if(NOT CMAKE_CXX_FLAGS MATCHES "-Werror")55set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")56endif(NOT CMAKE_CXX_FLAGS MATCHES "-Werror")58# Disable C++ exceptions.59string(REGEX REPLACE "-fexceptions" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")60set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")62# Disable RTTI.63string(REGEX REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")64set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")65endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")67option(CRC32C_BUILD_TESTS "Build CRC32C's unit tests" ON)68option(CRC32C_BUILD_BENCHMARKS "Build CRC32C's benchmarks" ON)69option(CRC32C_USE_GLOG "Build CRC32C's tests with Google Logging" ON)70option(CRC32C_INSTALL "Install CRC32C's header and library" ON)72include(TestBigEndian)73test_big_endian(BYTE_ORDER_BIG_ENDIAN)75include(CheckCXXCompilerFlag)76# Used by glog.77check_cxx_compiler_flag(-Wno-deprecated CRC32C_HAVE_NO_DEPRECATED)78# Used by glog.79check_cxx_compiler_flag(-Wno-sign-compare CRC32C_HAVE_NO_SIGN_COMPARE)80# Used by glog.81check_cxx_compiler_flag(-Wno-unused-parameter CRC32C_HAVE_NO_UNUSED_PARAMETER)82# Used by googletest.83check_cxx_compiler_flag(-Wno-missing-field-initializers84CRC32C_HAVE_NO_MISSING_FIELD_INITIALIZERS)86# Check for __builtin_prefetch support in the compiler.87include(CheckCXXSourceCompiles)88check_cxx_source_compiles("89int main() {90char data = 0;91const char* address = &data;92__builtin_prefetch(address, 0, 0);93return 0;94}95" HAVE_BUILTIN_PREFETCH)97# Check for _mm_prefetch support in the compiler.98include(CheckCXXSourceCompiles)99check_cxx_source_compiles("100#if defined(_MSC_VER)101#include <intrin.h>102#else // !defined(_MSC_VER)103#include <xmmintrin.h>104#endif // defined(_MSC_VER)106int main() {107char data = 0;108const char* address = &data;109_mm_prefetch(address, _MM_HINT_NTA);110return 0;111}112" HAVE_MM_PREFETCH)114# Check for SSE4.2 support in the compiler.115set(OLD_CMAKE_REQURED_FLAGS ${CMAKE_REQUIRED_FLAGS})116if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")117set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} /arch:AVX")118else(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")119set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -msse4.2")120endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")121check_cxx_source_compiles("122#if defined(_MSC_VER)123#include <intrin.h>124#else // !defined(_MSC_VER)125#include <cpuid.h>126#include <nmmintrin.h>127#endif // defined(_MSC_VER)129int main() {130_mm_crc32_u8(0, 0); _mm_crc32_u32(0, 0);131#if defined(_M_X64) || defined(__x86_64__)132_mm_crc32_u64(0, 0);133#endif // defined(_M_X64) || defined(__x86_64__)134return 0;135}136" HAVE_SSE42)137set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQURED_FLAGS})139# Check for ARMv8 w/ CRC and CRYPTO extensions support in the compiler.140set(OLD_CMAKE_REQURED_FLAGS ${CMAKE_REQUIRED_FLAGS})141if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")142# TODO(pwnall): Insert correct flag when VS gets ARM CRC32C support.143set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} /arch:NOTYET")144else(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")145set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -march=armv8-a+crc+crypto")146endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")147check_cxx_source_compiles("148#include <arm_acle.h>149#include <arm_neon.h>151int main() {152__crc32cb(0, 0); __crc32ch(0, 0); __crc32cw(0, 0); __crc32cd(0, 0);153vmull_p64(0, 0);154return 0;155}156" HAVE_ARM64_CRC32C)157set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQURED_FLAGS})159# Check for strong getauxval() support in the system headers.160check_cxx_source_compiles("161#include <arm_acle.h>162#include <arm_neon.h>163#include <sys/auxv.h>165int main() {166getauxval(AT_HWCAP);167return 0;168}169" HAVE_STRONG_GETAUXVAL)171# Check for weak getauxval() support in the compiler.172check_cxx_source_compiles("173unsigned long getauxval(unsigned long type) __attribute__((weak));174#define AT_HWCAP 16176int main() {177getauxval(AT_HWCAP);178return 0;179}180" HAVE_WEAK_GETAUXVAL)182if(CRC32C_USE_GLOG)183# glog requires this setting to avoid using dynamic_cast.184set(DISABLE_RTTI ON CACHE BOOL "" FORCE)186# glog's test targets trigger deprecation warnings, and compiling them burns187# CPU cycles on the CI.188set(BUILD_TESTING_SAVED "${BUILD_TESTING}")189set(BUILD_TESTING OFF CACHE BOOL "" FORCE)190add_subdirectory("third_party/glog" EXCLUDE_FROM_ALL)191set(BUILD_TESTING "${BUILD_TESTING_SAVED}" CACHE BOOL "" FORCE)193# glog triggers deprecation warnings on OSX.194# https://github.com/google/glog/issues/185195if(CRC32C_HAVE_NO_DEPRECATED)196set_property(TARGET glog APPEND PROPERTY COMPILE_OPTIONS -Wno-deprecated)197endif(CRC32C_HAVE_NO_DEPRECATED)199# glog triggers sign comparison warnings on gcc.200if(CRC32C_HAVE_NO_SIGN_COMPARE)201set_property(TARGET glog APPEND PROPERTY COMPILE_OPTIONS -Wno-sign-compare)202endif(CRC32C_HAVE_NO_SIGN_COMPARE)204# glog triggers unused parameter warnings on clang.205if(CRC32C_HAVE_NO_UNUSED_PARAMETER)206set_property(TARGET glog207APPEND PROPERTY COMPILE_OPTIONS -Wno-unused-parameter)208endif(CRC32C_HAVE_NO_UNUSED_PARAMETER)210set(CRC32C_TESTS_BUILT_WITH_GLOG 1)211endif(CRC32C_USE_GLOG)213configure_file(214"src/crc32c_config.h.in"215"${PROJECT_BINARY_DIR}/include/crc32c/crc32c_config.h"216)218include_directories("${PROJECT_BINARY_DIR}/include")220# ARM64 CRC32C code is built separately, so we don't accidentally compile221# unsupported instructions into code that gets run without ARM32 support.222add_library(crc32c_arm64 OBJECT "")223target_sources(crc32c_arm64224PRIVATE225"${PROJECT_BINARY_DIR}/include/crc32c/crc32c_config.h"226"src/crc32c_arm64.cc"227"src/crc32c_arm64.h"228)229if(HAVE_ARM64_CRC32C)230if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")231# TODO(pwnall): Insert correct flag when VS gets ARM64 CRC32C support.232target_compile_options(crc32c_arm64 PRIVATE "/arch:NOTYET")233else(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")234target_compile_options(crc32c_arm64 PRIVATE "-march=armv8-a+crc+crypto")235endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")236endif(HAVE_ARM64_CRC32C)238# CMake only enables PIC by default in SHARED and MODULE targets.239if(BUILD_SHARED_LIBS)240set_property(TARGET crc32c_arm64 PROPERTY POSITION_INDEPENDENT_CODE TRUE)241endif(BUILD_SHARED_LIBS)243# SSE4.2 code is built separately, so we don't accidentally compile unsupported244# instructions into code that gets run without SSE4.2 support.245add_library(crc32c_sse42 OBJECT "")246target_sources(crc32c_sse42247PRIVATE248"${PROJECT_BINARY_DIR}/include/crc32c/crc32c_config.h"249"src/crc32c_sse42.cc"250"src/crc32c_sse42.h"
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.