add_library(libSceNpTrophy SHARED EXCLUDE_FROM_ALL Export.cpp)
target_include_directories(libSceNpTrophy PRIVATE ${LIBS_INCLUDE_DIR})
configure_windows_unwind(libSceNpTrophy)

if(BUILD_TESTING)
    add_test_executable(guest_np_trophy_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpTrophy.cpp)
    target_include_directories(guest_np_trophy_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_trophy_tests PRIVATE libSceNpTrophy)
    configure_windows_unwind(guest_np_trophy_tests)
    add_test(NAME guest_np_trophy COMMAND guest_np_trophy_tests)
    set_tests_properties(guest_np_trophy PROPERTIES TIMEOUT 20)
    add_test_executable(guest_np_trophy_state_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpTrophyState.cpp)
    target_include_directories(guest_np_trophy_state_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_trophy_state_tests PRIVATE libSceNpTrophy)
    configure_windows_unwind(guest_np_trophy_state_tests)
    add_test(NAME guest_np_trophy_state COMMAND guest_np_trophy_state_tests)
    set_tests_properties(guest_np_trophy_state PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_np_trophy guest_np_trophy_state PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceNpTrophy>")
        add_test_executable(guest_np_trophy_host_write_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpTrophyHostWrite.cpp)
        target_include_directories(guest_np_trophy_host_write_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_np_trophy_host_write_tests PRIVATE libSceNpTrophy libkernel libc)
        configure_windows_unwind(guest_np_trophy_host_write_tests)
        add_test(NAME guest_np_trophy_host_write COMMAND guest_np_trophy_host_write_tests)
        set_tests_properties(guest_np_trophy_host_write PROPERTIES TIMEOUT 20 ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceNpTrophy>")
    endif()
endif()

if(BUILD_TESTING)
    add_test_executable(guest_np_trophy_system_debug_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpTrophySystemDebug.cpp)
    target_include_directories(guest_np_trophy_system_debug_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_trophy_system_debug_tests PRIVATE libSceNpTrophy)
    configure_windows_unwind(guest_np_trophy_system_debug_tests)
    add_test(NAME guest_np_trophy_system_debug COMMAND guest_np_trophy_system_debug_tests)
    set_tests_properties(guest_np_trophy_system_debug PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_np_trophy_system_debug PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceNpTrophy>")
    endif()
endif()

if(BUILD_TESTING)
    add_test_executable(guest_np_trophy_helpers_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpTrophyHelpers.cpp)
    target_include_directories(guest_np_trophy_helpers_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_trophy_helpers_tests PRIVATE libSceNpTrophy ${CMAKE_DL_LIBS})
    configure_windows_unwind(guest_np_trophy_helpers_tests)
    add_test(NAME guest_np_trophy_helpers COMMAND guest_np_trophy_helpers_tests)
    foreach(kind group sum set)
        add_test(NAME guest_np_trophy_${kind}_memory COMMAND guest_np_trophy_helpers_tests ${kind}-memory)
        set_tests_properties(guest_np_trophy_${kind}_memory PROPERTIES TIMEOUT 20)
        if(WIN32)
            set_tests_properties(guest_np_trophy_${kind}_memory PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceNpTrophy>")
        endif()
    endforeach()
    set_tests_properties(guest_np_trophy_helpers PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_np_trophy_helpers PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceNpTrophy>")
    endif()
endif()
