option(XXH_CPP_USE_AVX2 "Use AVX2 instructions for tests" OFF)

function(xxh_cpp_add_test name xxh_vector)
  add_executable(${name} test_main.cpp)
  target_link_libraries(${name} PRIVATE xxhash_cpp)
  target_compile_definitions(${name} PRIVATE -DXXH_VECTOR=${xxh_vector})
  if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    target_compile_options(${name} PRIVATE -Wall -Wextra -pedantic -Werror)
  elseif(MSVC)
    target_compile_options(${name} PRIVATE /W3 /WX)
  endif()
  if(XXH_CPP_USE_AVX2)
    if(MSVC)
      target_compile_options(${name} PRIVATE /arch:AVX2)
    else()
      target_compile_options(${name} PRIVATE -mavx2)
    endif()
  endif()
  add_test(NAME ${name} COMMAND ${name})
endfunction()

xxh_cpp_add_test(test_scalar 0)
xxh_cpp_add_test(test_sse2 1)
xxh_cpp_add_test(test_avx2 2)
