cmake_minimum_required(VERSION 3.14)
project(FEXMingwTests)

set(CMAKE_CXX_STANDARD 20)

set(GENERATE_GUEST_INSTALL_TARGETS TRUE)

# Use intel masm syntax. ATT style asm syntax is archaic and hard to read.
add_compile_options(-masm=intel)
# Override a define so catch2 doesn't use ATT style inline asm
add_definitions(-D"CATCH_BREAK_INTO_DEBUGGER\(\)"="[]{ if\( Catch::isDebuggerActive\(\) \) { __builtin_trap\(\)\; } }\(\)")

file(GLOB_RECURSE TESTS CONFIGURE_DEPENDS *.cpp)
if(BITNESS EQUAL 64)
  file(GLOB_RECURSE TESTS_32_ONLY CONFIGURE_DEPENDS *.32.cpp)
  list(REMOVE_ITEM TESTS ${TESTS_32_ONLY})
else()
  file(GLOB_RECURSE TESTS_64_ONLY CONFIGURE_DEPENDS *.64.cpp)
  list(REMOVE_ITEM TESTS ${TESTS_64_ONLY})
endif()

option(CATCH_BUILD_STATIC_LIBRARY "" ON)
set(CATCH_BUILD_STATIC_LIBRARY ON)
add_subdirectory(../../../External/Catch2/ Catch2)

foreach(TEST ${TESTS})
  get_filename_component(TEST_NAME ${TEST} NAME_WE)

  add_executable(${TEST_NAME}.${BITNESS} ${TEST})
  target_link_libraries(${TEST_NAME}.${BITNESS} PRIVATE Catch2::Catch2WithMain)
  target_include_directories(${TEST_NAME}.${BITNESS} PRIVATE include/)
endforeach()
