# build the filegen utility
link_directories(${PROJECT_BINARY_DIR}/blosc)
add_executable(filegen filegen.c)
target_link_libraries(filegen blosc_testing)
add_dependencies(filegen blosc_testing)

add_executable(filegen-vl filegen-vl.c)
target_link_libraries(filegen-vl blosc_testing)
add_dependencies(filegen-vl blosc_testing)

# tests
if(BUILD_TESTS)
    option(TEST_INCLUDE_COMPAT "Include compat checks in the tests" ON)
    if(TEST_INCLUDE_COMPAT)
        file(GLOB DATAFILES *.cdata)
        foreach(datafile ${DATAFILES})
            # Don't test data if compressor is deactivated
            if((datafile MATCHES "zlib" AND DEACTIVATE_ZLIB) OR
               (datafile MATCHES "zstd" AND DEACTIVATE_ZSTD))
               continue()
            endif()
            get_filename_component(fname ${datafile} NAME)
            if(fname MATCHES "^bitshuffle")
                set(op_name "bitunshuffle")
            elseif(fname MATCHES "^shuffle")
                set(op_name "unshuffle")
            else()
                set(op_name "decompress")
            endif()
            add_test(NAME test_compat_${fname}
                COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:filegen> ${op_name} ${datafile})
        endforeach()
    endif()
endif()
