cmake_minimum_required(VERSION 3.20)
project(ed25519_arithmetic LANGUAGES C CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
get_filename_component(REPO "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)
set(ED25519 "${REPO}/modules/core_chat/src/infra/meshcore/crypto/ed25519")
set(ED25519_UNITS fe.c sc.c ge.c sha512.c keypair.c sign.c verify.c key_exchange.c)
set(INPUTS "${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_DIR}/probe.cpp"
    "${CMAKE_CURRENT_LIST_DIR}/manifest.py" "${CMAKE_CURRENT_LIST_DIR}/bounds.py"
    "${CMAKE_CURRENT_LIST_DIR}/rfc8032.json"
    "${CMAKE_CURRENT_LIST_DIR}/README.md" "${REPO}/tests/rns_lxmf_interop/requirements-reference.txt"
    "${REPO}/tests/rns_lxmf_interop/reference_ed25519_arithmetic.py")
set(SOURCES "${CMAKE_CURRENT_LIST_DIR}/probe.cpp")
foreach(name IN LISTS ED25519_UNITS)
    list(APPEND SOURCES "${ED25519}/${name}")
endforeach()
list(APPEND INPUTS ${SOURCES})
foreach(name fe.h sc.h ge.h sha512.h fixedint.h precomp_data.h ed_25519.h license.txt)
    list(APPEND INPUTS "${ED25519}/${name}")
endforeach()
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${INPUTS})
find_package(Python3 COMPONENTS Interpreter REQUIRED)
execute_process(COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_LIST_DIR}/manifest.py"
    "${REPO}" "${CMAKE_CURRENT_BINARY_DIR}/generation_manifest.json" ${INPUTS}
    COMMAND_ERROR_IS_FATAL ANY)
add_executable(ed25519_arithmetic_probe ${SOURCES})
target_include_directories(ed25519_arithmetic_probe PRIVATE "${ED25519}")
target_compile_features(ed25519_arithmetic_probe PRIVATE cxx_std_17)
target_compile_options(ed25519_arithmetic_probe PRIVATE -UNDEBUG -Wall -Wextra
    -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer -fno-pie)
target_link_options(ed25519_arithmetic_probe PRIVATE -fsanitize=address,undefined -no-pie)
