include(${CMAKE_CURRENT_SOURCE_DIR}/FontLibrary.cmake)
add_sce_font_library(libSceFont)

if(BUILD_TESTING)
    add_test_executable(font_float_conversion_tests ${LIBS_INCLUDE_DIR}/tests/FontFloatConversion.cpp)
    target_include_directories(font_float_conversion_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(font_float_conversion_tests PRIVATE freetype)
    configure_host_test_executable(font_float_conversion_tests)
    add_test(NAME font_float_conversion COMMAND font_float_conversion_tests)

    add_test_executable(guest_font_interface_contracts_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontInterfaceContracts.cpp)
    target_include_directories(guest_font_interface_contracts_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_interface_contracts_tests PRIVATE libSceFont libc)
    configure_windows_unwind(guest_font_interface_contracts_tests)
    add_test(NAME guest_font_interface_contracts COMMAND guest_font_interface_contracts_tests)
    if(WIN32)
        set_tests_properties(guest_font_interface_contracts PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()

    add_test_executable(guest_font_tests ${LIBS_INCLUDE_DIR}/tests/GuestFont.cpp)
    target_include_directories(guest_font_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_tests PRIVATE libSceFont libSceFontFt libc)
    configure_windows_unwind(guest_font_tests)
    add_test(NAME guest_font COMMAND guest_font_tests)
    add_test_executable(font_render_surface_tests ${LIBS_INCLUDE_DIR}/tests/FontRenderSurface.cpp)
    target_include_directories(font_render_surface_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(font_render_surface_tests PRIVATE libSceFont libSceFontFt libc)
    configure_windows_unwind(font_render_surface_tests)
    add_test(NAME font_render_surface COMMAND font_render_surface_tests)
    set_tests_properties(font_render_surface PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(font_render_surface PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_font_scissor_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontScissor.cpp)
    target_include_directories(guest_font_scissor_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_scissor_tests PRIVATE libSceFont libSceFontFt libc)
    configure_windows_unwind(guest_font_scissor_tests)
    add_test(NAME guest_font_scissor COMMAND guest_font_scissor_tests)
    set_tests_properties(guest_font_scissor PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_font_scissor PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_font_output_pointers_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontOutputPointers.cpp)
    target_include_directories(guest_font_output_pointers_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_output_pointers_tests PRIVATE libSceFont libSceFontFt libc)
    configure_windows_unwind(guest_font_output_pointers_tests)
    add_test(NAME guest_font_output_pointers COMMAND guest_font_output_pointers_tests)
    set_tests_properties(guest_font_output_pointers PROPERTIES TIMEOUT 30)
    add_test(NAME guest_font_output_pointers_watched COMMAND guest_font_output_pointers_tests --watched)
    set_tests_properties(guest_font_output_pointers_watched PROPERTIES TIMEOUT 30 SKIP_RETURN_CODE 77)
    if(WIN32)
        set_tests_properties(guest_font_output_pointers guest_font_output_pointers_watched PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_font_renderer_lifecycle_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontRendererLifecycle.cpp)
    target_include_directories(guest_font_renderer_lifecycle_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_renderer_lifecycle_tests PRIVATE libSceFont libSceFontFt libc)
    configure_windows_unwind(guest_font_renderer_lifecycle_tests)
    add_test(NAME guest_font_renderer_lifecycle COMMAND guest_font_renderer_lifecycle_tests)
    set_tests_properties(guest_font_renderer_lifecycle PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_font_renderer_lifecycle PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_font_writing_metrics_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontWritingMetrics.cpp)
    target_include_directories(guest_font_writing_metrics_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_writing_metrics_tests PRIVATE libSceFont libSceFontFt libc)
    configure_windows_unwind(guest_font_writing_metrics_tests)
    add_test(NAME guest_font_writing_metrics COMMAND guest_font_writing_metrics_tests)
    set_tests_properties(guest_font_writing_metrics PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_font_writing_metrics PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_font_vertical_layout_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontVerticalLayout.cpp)
    target_include_directories(guest_font_vertical_layout_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_vertical_layout_tests PRIVATE libSceFont libSceFontFt libc)
    configure_windows_unwind(guest_font_vertical_layout_tests)
    add_test(NAME guest_font_vertical_layout COMMAND guest_font_vertical_layout_tests)
    set_tests_properties(guest_font_vertical_layout PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_font_vertical_layout PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_system_font_tests ${LIBS_INCLUDE_DIR}/tests/GuestSystemFont.cpp)
    target_include_directories(guest_system_font_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_system_font_tests PRIVATE libSceFont libSceFontFt libc)
    configure_windows_unwind(guest_system_font_tests)
    add_test(NAME guest_system_font COMMAND guest_system_font_tests)
    if(WIN32)
        set_tests_properties(guest_font guest_system_font PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_font_metrics_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontMetrics.cpp)
    target_include_directories(guest_font_metrics_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_metrics_tests PRIVATE libSceFont libSceFontFt libc)
    configure_windows_unwind(guest_font_metrics_tests)
    add_test(NAME guest_font_metrics COMMAND guest_font_metrics_tests)
    if(WIN32)
        set_tests_properties(guest_font_metrics PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_font_style_information_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontStyleInformation.cpp)
    target_include_directories(guest_font_style_information_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_style_information_tests PRIVATE libSceFont libSceFontFt libc)
    configure_windows_unwind(guest_font_style_information_tests)
    add_test(NAME guest_font_style_information COMMAND guest_font_style_information_tests)
    if(WIN32)
        set_tests_properties(guest_font_style_information PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_font_style_frame_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontStyleFrame.cpp)
    target_include_directories(guest_font_style_frame_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_style_frame_tests PRIVATE libSceFont libc)
    configure_windows_unwind(guest_font_style_frame_tests)
    add_test(NAME guest_font_style_frame COMMAND guest_font_style_frame_tests)
    if(WIN32)
        set_tests_properties(guest_font_style_frame PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_font_outline_profile_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontOutlineProfile.cpp)
    target_include_directories(guest_font_outline_profile_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_outline_profile_tests PRIVATE libSceFont libSceFontFt libc)
    configure_windows_unwind(guest_font_outline_profile_tests)
    add_test(NAME guest_font_outline_profile COMMAND guest_font_outline_profile_tests)
    if(WIN32)
        set_tests_properties(guest_font_outline_profile PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_font_writing_line_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontWritingLine.cpp)
    target_include_directories(guest_font_writing_line_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_writing_line_tests PRIVATE libSceFont libc)
    configure_windows_unwind(guest_font_writing_line_tests)
    add_test(NAME guest_font_writing_line COMMAND guest_font_writing_line_tests)
    if(WIN32)
        set_tests_properties(guest_font_writing_line PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_font_graphics_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontGraphics.cpp)
    target_include_directories(guest_font_graphics_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_graphics_tests PRIVATE libSceFont libkernel libc)
    configure_windows_unwind(guest_font_graphics_tests)
    add_test(NAME guest_font_graphics COMMAND guest_font_graphics_tests)
    if(WIN32)
        set_tests_properties(guest_font_graphics PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(font_fixed_rounding_tests ${LIBS_INCLUDE_DIR}/tests/FontFixedRounding.cpp)
    target_include_directories(font_fixed_rounding_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(font_fixed_rounding_tests PRIVATE freetype)
    configure_host_test_executable(font_fixed_rounding_tests)
    add_test(NAME font_fixed_rounding COMMAND font_fixed_rounding_tests)
    add_test_executable(font_face_lifetime_tests ${LIBS_INCLUDE_DIR}/tests/FontFaceLifetime.cpp
            ${CMAKE_CURRENT_SOURCE_DIR}/src/State.cpp)
    target_include_directories(font_face_lifetime_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(font_face_lifetime_tests PRIVATE freetype libc)
    configure_windows_unwind(font_face_lifetime_tests)
    add_test(NAME font_face_lifetime COMMAND font_face_lifetime_tests)
    add_test(NAME font_face_lifetime_replace COMMAND font_face_lifetime_tests replace)
    add_test(NAME font_face_lifetime_churn COMMAND font_face_lifetime_tests churn)
    set_tests_properties(font_face_lifetime font_face_lifetime_replace font_face_lifetime_churn PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(font_face_lifetime font_face_lifetime_replace font_face_lifetime_churn PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_font_words_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontWords.cpp)
    target_include_directories(guest_font_words_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_words_tests PRIVATE libSceFont libc)
    configure_windows_unwind(guest_font_words_tests)
    add_test(NAME guest_font_words COMMAND guest_font_words_tests)
    if(WIN32)
        set_tests_properties(guest_font_words PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_font_rebind_renderer_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontRebindRenderer.cpp)
    target_include_directories(guest_font_rebind_renderer_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_rebind_renderer_tests PRIVATE libSceFont libSceFontFt libc)
    configure_windows_unwind(guest_font_rebind_renderer_tests)
    add_test(NAME guest_font_rebind_renderer COMMAND guest_font_rebind_renderer_tests)
    set_tests_properties(guest_font_rebind_renderer PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_font_rebind_renderer PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_font_support_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontSupport.cpp)
    target_include_directories(guest_font_support_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_support_tests PRIVATE libSceFont libSceFontFt libc)
    configure_windows_unwind(guest_font_support_tests)
    add_test(NAME guest_font_support COMMAND guest_font_support_tests)
    set_tests_properties(guest_font_support PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_font_support PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(guest_font_render_characters_tests ${LIBS_INCLUDE_DIR}/tests/GuestFontRenderCharacters.cpp)
    target_include_directories(guest_font_render_characters_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_font_render_characters_tests PRIVATE libSceFont libSceFontFt libc)
    configure_windows_unwind(guest_font_render_characters_tests)
    add_test(NAME guest_font_render_characters COMMAND guest_font_render_characters_tests)
    set_tests_properties(guest_font_render_characters PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_font_render_characters PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
    endif()
    add_test_executable(font_charmap_fallback_tests ${LIBS_INCLUDE_DIR}/tests/FontCharmapFallback.cpp)
    target_include_directories(font_charmap_fallback_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(font_charmap_fallback_tests PRIVATE freetype)
    configure_host_test_executable(font_charmap_fallback_tests)
    add_test(NAME font_charmap_fallback COMMAND font_charmap_fallback_tests)
    add_test_executable(font_ft_allocation_size_tests ${LIBS_INCLUDE_DIR}/tests/FontFtAllocationSize.cpp)
    target_include_directories(font_ft_allocation_size_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(font_ft_allocation_size_tests PRIVATE libSceFontFt libc)
    configure_windows_unwind(font_ft_allocation_size_tests)
    add_test(NAME font_ft_allocation_size COMMAND font_ft_allocation_size_tests)
endif()
