add_library(libSceNpCppWebApi SHARED EXCLUDE_FROM_ALL Export.cpp)
target_include_directories(libSceNpCppWebApi PRIVATE ${LIBS_INCLUDE_DIR})
configure_windows_unwind(libSceNpCppWebApi)
target_sources(libSceNpCppWebApi PRIVATE StringSubstrings.cpp)

if(BUILD_TESTING)
    add_test_executable(guest_np_cpp_web_api_native_accessors_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiNativeAccessors.cpp)
    target_include_directories(guest_np_cpp_web_api_native_accessors_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_native_accessors_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_native_accessors_tests)
    add_test(NAME guest_np_cpp_web_api_native_accessors COMMAND guest_np_cpp_web_api_native_accessors_tests)
    set_tests_properties(guest_np_cpp_web_api_native_accessors PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_native_accessors PROPERTIES
                ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

if(BUILD_TESTING)
    add_test_executable(guest_np_cpp_web_api_session_fields_tests NO_RUNTIME_DLL_STAGING
        ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiSessionFields.cpp)
    target_include_directories(guest_np_cpp_web_api_session_fields_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_session_fields_tests PRIVATE ${CMAKE_DL_LIBS})
    configure_windows_unwind(guest_np_cpp_web_api_session_fields_tests)
    add_custom_target(guest_np_cpp_web_api_session_field_modules DEPENDS
        ${PATCHED_DIR}/libSceNpCppWebApi.prx ${PATCHED_DIR}/libkernel.prx ${LIBC_PATCHED})
    add_dependencies(guest_np_cpp_web_api_session_fields_tests guest_np_cpp_web_api_session_field_modules)
    add_test(NAME guest_np_cpp_web_api_session_fields COMMAND guest_np_cpp_web_api_session_fields_tests
        ${PATCHED_DIR}/libSceNpCppWebApi.prx)
    set_tests_properties(guest_np_cpp_web_api_session_fields PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_session_fields PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:${PATCHED_DIR}")
    endif()
endif()

if(BUILD_TESTING)
    add_test_executable(guest_np_cpp_web_api_native_iterators_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiNativeIterators.cpp)
    target_include_directories(guest_np_cpp_web_api_native_iterators_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_native_iterators_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_native_iterators_tests)
    add_test(NAME guest_np_cpp_web_api_native_iterators COMMAND guest_np_cpp_web_api_native_iterators_tests)
    set_tests_properties(guest_np_cpp_web_api_native_iterators PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_native_iterators PROPERTIES
                ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

if(BUILD_TESTING)
    add_test_executable(guest_np_cpp_web_api_product_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiProduct.cpp)
    target_include_directories(guest_np_cpp_web_api_product_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_product_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_product_tests)
    add_test(NAME guest_np_cpp_web_api_product COMMAND guest_np_cpp_web_api_product_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_product
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_np_cpp_web_api_matchmaking_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiMatchmaking.cpp)
    target_include_directories(guest_np_cpp_web_api_matchmaking_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_matchmaking_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_matchmaking_tests)
    add_test(NAME guest_np_cpp_web_api_matchmaking COMMAND guest_np_cpp_web_api_matchmaking_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_matchmaking
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_np_cpp_web_api_matchmaking_model_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiMatchmakingModel.cpp)
    target_include_directories(guest_np_cpp_web_api_matchmaking_model_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_matchmaking_model_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_matchmaking_model_tests)
    add_test(NAME guest_np_cpp_web_api_matchmaking_model COMMAND guest_np_cpp_web_api_matchmaking_model_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_matchmaking_model
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

if(MINGW)
    foreach(runtimeLinkFlag IN ITEMS -static-libgcc -static-libstdc++ -static)
        string(REPLACE "${runtimeLinkFlag}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
    endforeach()
endif()

if(BUILD_TESTING)
    add_test_executable(guest_np_cpp_web_api_response_header_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiResponseHeader.cpp)
    target_include_directories(guest_np_cpp_web_api_response_header_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_response_header_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_response_header_tests)
    add_test(NAME guest_np_cpp_web_api_response_header COMMAND guest_np_cpp_web_api_response_header_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_response_header
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_np_cpp_web_api_string_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiString.cpp)
    target_include_directories(guest_np_cpp_web_api_string_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_string_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_string_tests)
    add_test(NAME guest_np_cpp_web_api_string COMMAND guest_np_cpp_web_api_string_tests)
    add_test_executable(guest_np_cpp_web_api_title_cloud_storage_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiTitleCloudStorage.cpp)
    target_include_directories(guest_np_cpp_web_api_title_cloud_storage_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_title_cloud_storage_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_title_cloud_storage_tests)
    add_test(NAME guest_np_cpp_web_api_title_cloud_storage COMMAND guest_np_cpp_web_api_title_cloud_storage_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_title_cloud_storage
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test(NAME guest_np_cpp_web_api_alias_append COMMAND guest_np_cpp_web_api_string_tests alias-append)
    add_test(NAME guest_np_cpp_web_api_alias_string_vector COMMAND guest_np_cpp_web_api_string_tests alias-vector)
    add_test(NAME guest_np_cpp_web_api_alias_intrusive_vector COMMAND guest_np_cpp_web_api_intrusive_ptr_tests alias-vector)
    set_tests_properties(guest_np_cpp_web_api_alias_append guest_np_cpp_web_api_alias_string_vector
        guest_np_cpp_web_api_alias_intrusive_vector PROPERTIES TIMEOUT 30)
    add_test_executable(guest_np_cpp_web_api_binary_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiBinary.cpp)
    target_include_directories(guest_np_cpp_web_api_binary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_binary_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_binary_tests)
    add_test(NAME guest_np_cpp_web_api_binary COMMAND guest_np_cpp_web_api_binary_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_string guest_np_cpp_web_api_alias_append
            guest_np_cpp_web_api_alias_string_vector guest_np_cpp_web_api_alias_intrusive_vector
            guest_np_cpp_web_api_binary
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

if(BUILD_TESTING)
    add_test_executable(guest_np_cpp_web_api_activities_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiActivities.cpp)
    target_include_directories(guest_np_cpp_web_api_activities_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_activities_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_activities_tests)
    add_test(NAME guest_np_cpp_web_api_activities COMMAND guest_np_cpp_web_api_activities_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_activities
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

if(BUILD_TESTING)
    add_test_executable(guest_np_cpp_web_api_account_ids_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiAccountIds.cpp)
    target_include_directories(guest_np_cpp_web_api_account_ids_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_account_ids_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_account_ids_tests)
    add_test(NAME guest_np_cpp_web_api_account_ids COMMAND guest_np_cpp_web_api_account_ids_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_account_ids
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

if(BUILD_TESTING)
    add_test_executable(guest_np_cpp_web_api_session_manager_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiSessionManager2.cpp)
    target_include_directories(guest_np_cpp_web_api_session_manager_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_session_manager_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_session_manager_tests)
    add_test(NAME guest_np_cpp_web_api_session_manager COMMAND guest_np_cpp_web_api_session_manager_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_session_manager
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

if(BUILD_TESTING)
    add_test_executable(guest_np_cpp_web_api_matchmaking_datetime_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiMatchmakingDateTime.cpp)
    target_include_directories(guest_np_cpp_web_api_matchmaking_datetime_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_matchmaking_datetime_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_matchmaking_datetime_tests)
    add_test(NAME guest_np_cpp_web_api_matchmaking_datetime COMMAND guest_np_cpp_web_api_matchmaking_datetime_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_matchmaking_datetime
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

if(BUILD_TESTING)
    add_test_executable(guest_np_cpp_web_api_matchmaking_strings_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiMatchmakingStrings.cpp)
    target_include_directories(guest_np_cpp_web_api_matchmaking_strings_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_matchmaking_strings_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_matchmaking_strings_tests)
    add_test(NAME guest_np_cpp_web_api_matchmaking_strings COMMAND guest_np_cpp_web_api_matchmaking_strings_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_matchmaking_strings
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

if(BUILD_TESTING)
    add_test_executable(guest_np_cpp_web_api_matchmaking_response_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiMatchmakingResponse.cpp)
    target_include_directories(guest_np_cpp_web_api_matchmaking_response_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_matchmaking_response_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_matchmaking_response_tests)
    add_test(NAME guest_np_cpp_web_api_matchmaking_response COMMAND guest_np_cpp_web_api_matchmaking_response_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_matchmaking_response
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_np_cpp_web_api_matches2v1_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiMatches2V1.cpp)
    target_include_directories(guest_np_cpp_web_api_matches2v1_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_matches2v1_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_matches2v1_tests)
    add_test(NAME guest_np_cpp_web_api_matches2v1 COMMAND guest_np_cpp_web_api_matches2v1_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_matches2v1
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_np_cpp_web_api_value_accessors_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiValueAccessors.cpp)
    target_include_directories(guest_np_cpp_web_api_value_accessors_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_value_accessors_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_value_accessors_tests)
    add_test(NAME guest_np_cpp_web_api_value_accessors COMMAND guest_np_cpp_web_api_value_accessors_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_value_accessors
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_np_cpp_web_api_session_manager_values_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiSessionManagerValues.cpp)
    target_include_directories(guest_np_cpp_web_api_session_manager_values_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_session_manager_values_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_session_manager_values_tests)
    add_test(NAME guest_np_cpp_web_api_session_manager_values COMMAND guest_np_cpp_web_api_session_manager_values_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_session_manager_values
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_np_cpp_web_api_leaderboards_board_definition_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiLeaderboardsBoardDefinition.cpp)
    target_include_directories(guest_np_cpp_web_api_leaderboards_board_definition_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_cpp_web_api_leaderboards_board_definition_tests PRIVATE libSceNpCppWebApi libc)
    configure_windows_unwind(guest_np_cpp_web_api_leaderboards_board_definition_tests)
    add_test(NAME guest_np_cpp_web_api_leaderboards_board_definition COMMAND guest_np_cpp_web_api_leaderboards_board_definition_tests)
    if(WIN32)
        set_tests_properties(guest_np_cpp_web_api_leaderboards_board_definition
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()
