add_library(libSceNpCommon SHARED EXCLUDE_FROM_ALL PendingExports.cpp PendingExportsRound7.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_np_hex_capacity_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpHexCapacity.cpp)
    target_include_directories(guest_np_hex_capacity_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_hex_capacity_tests PRIVATE libSceNpCommon libc)
    configure_windows_unwind(guest_np_hex_capacity_tests)
    add_test(NAME guest_np_hex_capacity COMMAND guest_np_hex_capacity_tests)
    set_tests_properties(guest_np_hex_capacity PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_np_hex_capacity PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceNpCommon>")
    endif()
endif()

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Export.cpp")
    target_sources(libSceNpCommon PRIVATE Export.cpp)
endif()
target_sources(libSceNpCommon PRIVATE Json.cpp RingBuf.cpp Runtime.cpp Strings.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_np_integer_radices_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpIntegerRadices.cpp)
    target_include_directories(guest_np_integer_radices_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_integer_radices_tests PRIVATE libSceNpCommon libc)
    configure_windows_unwind(guest_np_integer_radices_tests)
    add_test(NAME guest_np_integer_radices COMMAND guest_np_integer_radices_tests)
    set_tests_properties(guest_np_integer_radices PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_np_integer_radices PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceNpCommon>")
    endif()
endif()

target_include_directories(libSceNpCommon PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(libSceNpCommon PRIVATE libc libkernel libSceRtc libSceUserService)
configure_windows_unwind(libSceNpCommon)

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

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

    add_test_executable(guest_np_common_rtc_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCommonRtc.cpp)
    target_include_directories(guest_np_common_rtc_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_np_common_rtc_tests PRIVATE libSceNpCommon libSceRtc libc)
    configure_windows_unwind(guest_np_common_rtc_tests)
    add_test(NAME guest_np_common_rtc COMMAND guest_np_common_rtc_tests)
    if(WIN32)
        set_tests_properties(guest_np_common_rtc PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceNpCommon>")
    endif()

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