add_library(dataset_hash SHARED
    dataset_hash.cpp
    crypto/sha256_hasher.cpp
    crypto/sha256_generic.cpp
    crypto/sha256_armv8.cpp
    crypto/sha256_x86.cpp
    io/file_hash.cpp
    threading/parallel_hash.cpp
)

target_include_directories(dataset_hash PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/crypto
    ${CMAKE_CURRENT_SOURCE_DIR}/io
    ${CMAKE_CURRENT_SOURCE_DIR}/threading
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
    $<INSTALL_INTERFACE:include/fetchml>
)

target_include_directories(dataset_hash PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/../common/include
)

target_link_libraries(dataset_hash PRIVATE
    fetchml_common
    Threads::Threads
)

target_compile_features(dataset_hash PUBLIC cxx_std_20)

if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM|aarch64|AARCH64")
    target_compile_options(dataset_hash PRIVATE -march=armv8-a+crypto)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
    # SHA-NI is optional, let runtime detection handle it
endif()

set_target_properties(dataset_hash PROPERTIES
    VERSION ${PROJECT_VERSION}
    SOVERSION ${PROJECT_VERSION_MAJOR}
    PUBLIC_HEADER "dataset_hash.h"
    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)

install(TARGETS dataset_hash
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    PUBLIC_HEADER DESTINATION include/fetchml
)
