--- /dev/null
+mark_as_advanced(BLAKE3_INCLUDE_DIR)
+mark_as_advanced(BLAKE3_LIBRARY)
+
+if(DEP_BLAKE3 STREQUAL "BUNDLED")
+ message(STATUS "Using bundled Blake3 as requested")
+else()
+ find_path(BLAKE3_INCLUDE_DIR blake3.h)
+ find_library(BLAKE3_LIBRARY blake3)
+ if(BLAKE3_INCLUDE_DIR)
+ file(READ "${BLAKE3_INCLUDE_DIR}/blake3.h" _blake3_h)
+ string(REGEX MATCH "#define _blake3_version_string \"([0-9]+).([0-9]+).*([0-9]+)\"" _ "${_blake3_h}")
+ set(_blake3_version_string "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
+ if(NOT "${CMAKE_MATCH_0}" STREQUAL "" AND "${_blake3_version_string}" VERSION_GREATER_EQUAL "${Blake3_FIND_VERSION}")
+ if(BLAKE3_LIBRARY)
+ message(STATUS "Using system Blake3 (${BLAKE3_LIBRARY})")
+ add_library(dep_blake3 UNKNOWN IMPORTED)
+ set_target_properties(
+ dep_blake3
+ PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${BLAKE3_INCLUDE_DIR}"
+ IMPORTED_LOCATION "${BLAKE3_LIBRARY}"
+ )
+ endif()
+ register_dependency(Blake3 "SYSTEM (${BLAKE3_LIBRARY})" "${_blake3_version_string}")
+ endif()
+ endif()
+ if(NOT TARGET dep_blake3)
+ message(STATUS "Using bundled Blake3 since Blake3>=${Blake3_FIND_VERSION} was not found locally")
+ endif()
+endif()
-add_library(dep_blake3 STATIC blake3.c blake3_dispatch.c blake3_portable.c)
+register_dependency(Blake3 BUNDLED 1.5.1)
-target_include_directories(dep_blake3 INTERFACE "${CMAKE_SOURCE_DIR}/src/third_party/blake3")
+add_library(
+ dep_blake3 STATIC
+ "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3.c"
+ "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3_dispatch.c"
+ "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3_portable.c"
+)
+
+target_include_directories(dep_blake3 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(dep_blake3 PRIVATE standard_settings)
if(MSVC)
- # No object file is created if masm is passed the compile options from standard_settings,
- # so don't pass any flags at all to assembler (as no flags are needed anyway).
+ # No object file is created if masm is passed the compile options from
+ # standard_settings, so don't pass any flags at all to assembler (as no
+ # flags are needed anyway).
string(REPLACE "<FLAGS> " "" CMAKE_ASM_MASM_COMPILE_OBJECT "${CMAKE_ASM_MASM_COMPILE_OBJECT}")
endif()
include(CheckCSourceCompiles)
-function(add_source_if_enabled feature msvc_flags others_flags intrinsic)
+function(_add_blake3_source_if_enabled feature msvc_flags others_flags intrinsic)
if(MSVC)
set(compile_flags "${msvc_flags}")
else()
# First check if it's possible to use the assembler variant for the feature.
string(TOUPPER "have_asm_${feature}" have_feature)
if(NOT DEFINED "${have_feature}" AND CMAKE_SIZEOF_VOID_P EQUAL 8
-# Force intrinsic version for msbuild because of a bug in the cmake generator
-# or msbuild itself with masm flags.
+ # Force intrinsic version for msbuild because of a bug in the CMake
+ # generator or msbuild itself with masm flags.
AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
if(NOT CMAKE_REQUIRED_QUIET)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
- # Must set CMAKE_ASM_MASM_CREATE_STATIC_LIBRARY explicitly otherwise try_compile
- # fails, see https://discourse.cmake.org/t/building-lib-file-from-asm-cmake-bug/1959
+ # Must set CMAKE_ASM_MASM_CREATE_STATIC_LIBRARY explicitly otherwise
+ # try_compile fails, see
+ # <https://discourse.cmake.org/t/building-lib-file-from-asm-cmake-bug/1959>.
try_compile(
${have_feature}
${CMAKE_CURRENT_BINARY_DIR}
- "${CMAKE_CURRENT_SOURCE_DIR}/blake3_${feature}${suffix}"
+ "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3_${feature}${suffix}"
CMAKE_FLAGS -DCMAKE_ASM_MASM_CREATE_STATIC_LIBRARY=${CMAKE_C_CREATE_STATIC_LIBRARY}
- COMPILE_DEFINITIONS ${compile_flags})
+ COMPILE_DEFINITIONS ${compile_flags}
+ )
unset(CMAKE_TRY_COMPILE_TARGET_TYPE)
endif()
endif()
- # If the assembler variant didn't work, try the c variant.
+ # If the assembler variant didn't work, try the C variant.
if(NOT ${have_feature})
string(TOUPPER "have_c_${feature}" have_feature)
set(suffix ".c")
endif()
if(${have_feature})
- target_sources(dep_blake3 PRIVATE blake3_${feature}${suffix})
+ target_sources(
+ dep_blake3
+ PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3_${feature}${suffix}"
+ )
if(suffix STREQUAL ".c")
if(MINGW AND feature STREQUAL "avx512")
- # Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65782.
+ # Workaround for <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65782>.
# Taken from blake3's build.rs.
set(compile_flags "${compile_flags} -fno-asynchronous-unwind-tables")
endif()
set_property(
- SOURCE blake3_${feature}${suffix}
+ SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3_${feature}${suffix}"
APPEND PROPERTY COMPILE_FLAGS ${compile_flags})
elseif(NOT MSVC)
set_property(
- SOURCE blake3_${feature}${suffix}
+ SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3_${feature}${suffix}"
PROPERTY COMPILE_FLAGS ${compile_flags})
endif()
else()
string(TOUPPER "blake3_no_${feature}" no_feature)
- target_compile_definitions(blake3 PRIVATE ${no_feature})
+ target_compile_definitions(dep_blake3 PRIVATE ${no_feature})
endif()
endfunction()
# https://software.intel.com/sites/landingpage/IntrinsicsGuide/
-add_source_if_enabled(sse2 "" "-msse2"
- "_mm_set1_epi32(42)")
-add_source_if_enabled(sse41 "" "-msse4.1"
- "_mm_test_all_ones(_mm_set1_epi32(42))")
-add_source_if_enabled(avx2 "/arch:AVX2" "-mavx2"
- "_mm256_abs_epi8(_mm256_set1_epi32(42))")
-add_source_if_enabled(avx512 "/arch:AVX512" "-mavx512f -mavx512vl"
- "_mm256_abs_epi64(_mm256_set1_epi32(42))")
+_add_blake3_source_if_enabled(sse2 "" "-msse2" "_mm_set1_epi32(42)")
+_add_blake3_source_if_enabled(sse41 "" "-msse4.1" "_mm_test_all_ones(_mm_set1_epi32(42))")
+_add_blake3_source_if_enabled(avx2 "/arch:AVX2" "-mavx2" "_mm256_abs_epi8(_mm256_set1_epi32(42))")
+_add_blake3_source_if_enabled(avx512 "/arch:AVX512" "-mavx512f -mavx512vl" "_mm256_abs_epi64(_mm256_set1_epi32(42))")
# Neon is always available on AArch64
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
]=]
HAVE_NEON)
if(HAVE_NEON)
- target_sources(blake3 PRIVATE blake3_neon.c)
- target_compile_definitions(blake3 PRIVATE BLAKE3_USE_NEON)
+ target_sources(dep_blake3 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/blake3/blake3_neon.c")
+ target_compile_definitions(dep_blake3 PRIVATE BLAKE3_USE_NEON)
endif()
endif()