add_library(cvt_core OBJECT cvt_core.c int_to_bin.c hex_to_bin.c bin_to_int.c bin_to_hex.c bin_to_nrz.c nrz_to_bin.c)
target_include_directories(cvt_core PUBLIC ${CMAKE_SOURCE_DIR}/native/inc)

if(BUILD_PYTHON)
# cvt Python module — aggregates: F32ToI16, I16ToF32, I32ToF32, I8ToF32, F32ToI16U32, F32ToI16U64, I16U32ToF32, I16U64ToF32, F32ToUQ15, UQ15ToF32, ADC
Python3_add_library(cvt MODULE WITH_SOABI cvt_ext.c)
target_link_libraries(cvt PRIVATE
    cvt_core
    f32_to_i16_core
    i16_to_f32_core
    i32_to_f32_core
    i8_to_f32_core
    f32_to_i16u32_core
    f32_to_i16u64_core
    i16u32_to_f32_core
    i16u64_to_f32_core
    f32_to_uq15_core
    uq15_to_f32_core
    adc_core
    Python3::NumPy)
target_include_directories(cvt PRIVATE ${CMAKE_SOURCE_DIR}/native/inc)
set_target_properties(cvt PROPERTIES
    LIBRARY_OUTPUT_DIRECTORY "${PYTHON_PACKAGE_DIR}/cvt"
    RUNTIME_OUTPUT_DIRECTORY "${PYTHON_PACKAGE_DIR}/cvt")
add_custom_command(TARGET cvt POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
        "$<TARGET_FILE:cvt>"
        "${PYTHON_PACKAGE_DIR}/cvt/$<TARGET_FILE_NAME:cvt>"
    VERBATIM
    COMMENT "Copy cvt extension module")
endif()

add_executable(test_cvt_core
    ${CMAKE_SOURCE_DIR}/native/tests/test_cvt_core.c)
target_link_libraries(test_cvt_core PRIVATE
    cvt_core
    f32_to_i16_core
    i16_to_f32_core
    i32_to_f32_core
    i8_to_f32_core
    f32_to_i16u32_core
    f32_to_i16u64_core
    i16u32_to_f32_core
    i16u64_to_f32_core
    f32_to_uq15_core
    uq15_to_f32_core
    adc_core
    m)
target_include_directories(test_cvt_core
    PRIVATE ${CMAKE_SOURCE_DIR}/native/inc)
add_test(NAME test_cvt_core COMMAND test_cvt_core)

add_executable(bench_cvt_core
    ${CMAKE_SOURCE_DIR}/native/benchmarks/bench_cvt_core.c)
target_link_libraries(bench_cvt_core PRIVATE
    cvt_core
    f32_to_i16_core
    i16_to_f32_core
    i32_to_f32_core
    i8_to_f32_core
    f32_to_i16u32_core
    f32_to_i16u64_core
    i16u32_to_f32_core
    i16u64_to_f32_core
    f32_to_uq15_core
    uq15_to_f32_core
    adc_core
    m)
target_include_directories(bench_cvt_core
    PRIVATE ${CMAKE_SOURCE_DIR}/native/inc
            ${CMAKE_SOURCE_DIR}/native/benchmarks)
