add_library(libSceLibcInternal SHARED EXCLUDE_FROM_ALL Export.cpp FileTime.cpp Getopt.cpp SignalList.cpp Spawn.cpp UserContext.cpp)
target_include_directories(libSceLibcInternal PRIVATE ${LIBS_INCLUDE_DIR})
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_byte_extrema_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalByteExtrema.cpp)
    target_include_directories(guest_libc_internal_byte_extrema_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_byte_extrema_tests PRIVATE libSceLibcInternal libc libkernel)
    configure_windows_unwind(guest_libc_internal_byte_extrema_tests)
    add_test(NAME guest_libc_internal_min_byte COMMAND guest_libc_internal_byte_extrema_tests min)
    add_test(NAME guest_libc_internal_max_byte COMMAND guest_libc_internal_byte_extrema_tests max)
    set_tests_properties(guest_libc_internal_min_byte guest_libc_internal_max_byte PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_min_byte guest_libc_internal_max_byte PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
set_source_files_properties(UserContext.cpp PROPERTIES COMPILE_OPTIONS -fno-omit-frame-pointer)
target_sources(libSceLibcInternal PRIVATE SignalMask.cpp)
target_link_libraries(libSceLibcInternal PRIVATE ${CMAKE_DL_LIBS})
target_sources(libSceLibcInternal PRIVATE InventoryExports2.cpp)
target_sources(libSceLibcInternal PRIVATE Directory.cpp)
target_sources(libSceLibcInternal PRIVATE MemoryResource.cpp)
target_sources(libSceLibcInternal PRIVATE InventoryExports.cpp)
target_sources(libSceLibcInternal PRIVATE Pad.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_pad_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalPad.cpp)
    target_include_directories(guest_libc_internal_pad_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_pad_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_pad_tests)
    add_test(NAME guest_libc_internal_pad COMMAND guest_libc_internal_pad_tests)
    set_tests_properties(guest_libc_internal_pad PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_pad PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE InitOnce.cpp)
target_sources(libSceLibcInternal PRIVATE Mutex.cpp)
target_sources(libSceLibcInternal PRIVATE AlignedNew.cpp)
target_sources(libSceLibcInternal PRIVATE Format.cpp)
target_sources(libSceLibcInternal PRIVATE Numpunct.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_numpunct_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalNumpunct.cpp)
    target_include_directories(guest_libc_internal_numpunct_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_numpunct_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_numpunct_tests)
    add_test(NAME guest_libc_internal_numpunct COMMAND guest_libc_internal_numpunct_tests)
    set_tests_properties(guest_libc_internal_numpunct PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_numpunct PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE Stream.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_stream_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalStream.cpp)
    target_include_directories(guest_libc_internal_stream_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_stream_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_stream_tests)
    add_test(NAME guest_libc_internal_stream COMMAND guest_libc_internal_stream_tests)
    set_tests_properties(guest_libc_internal_stream PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_stream PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_format_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalFormat.cpp)
    target_include_directories(guest_libc_internal_format_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_format_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_format_tests)
    add_test(NAME guest_libc_internal_format COMMAND guest_libc_internal_format_tests)
    set_tests_properties(guest_libc_internal_format PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_format PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_showmanyc_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalShowmanyc.cpp)
    target_include_directories(guest_libc_internal_showmanyc_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_showmanyc_tests PRIVATE libSceLibcInternal)
    configure_windows_unwind(guest_libc_internal_showmanyc_tests)
    add_test(NAME guest_libc_internal_showmanyc COMMAND guest_libc_internal_showmanyc_tests)
    set_tests_properties(guest_libc_internal_showmanyc PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_showmanyc PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()

    add_test_executable(guest_libc_internal_aligned_new_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalAlignedNew.cpp)
    target_include_directories(guest_libc_internal_aligned_new_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_aligned_new_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_aligned_new_tests)
    add_test(NAME guest_libc_internal_aligned_new COMMAND guest_libc_internal_aligned_new_tests)
    set_tests_properties(guest_libc_internal_aligned_new PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_aligned_new PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE CxxRuntimeForwards.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_cxx_forwards_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalCxxForwards.cpp)
    target_include_directories(guest_libc_internal_cxx_forwards_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_cxx_forwards_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_cxx_forwards_tests)
    add_test(NAME guest_libc_internal_cxx_forwards COMMAND guest_libc_internal_cxx_forwards_tests)
    set_tests_properties(guest_libc_internal_cxx_forwards PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_cxx_forwards PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE JumpBuffer.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_longjmp_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalLongjmp.cpp)
    target_include_directories(guest_libc_internal_longjmp_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_longjmp_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_longjmp_tests)
    add_test(NAME guest_libc_internal_longjmp COMMAND guest_libc_internal_longjmp_tests)
    set_tests_properties(guest_libc_internal_longjmp PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_longjmp PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_mtx_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalMtx.cpp)
    target_include_directories(guest_libc_internal_mtx_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_mtx_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_mtx_tests)
    add_test(NAME guest_libc_internal_mtx COMMAND guest_libc_internal_mtx_tests)
    set_tests_properties(guest_libc_internal_mtx PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_mtx PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
if(BUILD_TESTING)
    add_test_executable(guest_init_once_tests ${LIBS_INCLUDE_DIR}/tests/GuestInitOnce.cpp)
    target_include_directories(guest_init_once_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_init_once_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_init_once_tests)
    add_test(NAME guest_init_once COMMAND guest_init_once_tests)
    set_tests_properties(guest_init_once PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_init_once PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_placement_delete_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalPlacementDelete.cpp)
    target_include_directories(guest_libc_internal_placement_delete_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_placement_delete_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_placement_delete_tests)
    add_test(NAME guest_libc_internal_placement_delete COMMAND guest_libc_internal_placement_delete_tests)
    set_tests_properties(guest_libc_internal_placement_delete PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_placement_delete PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE Err.cpp)
target_sources(libSceLibcInternal PRIVATE RecoveredInventory.cpp)
target_sources(libSceLibcInternal PRIVATE VectorAlgorithms.cpp)

if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_vector_algorithms_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalVectorAlgorithms.cpp)
    target_include_directories(guest_libc_internal_vector_algorithms_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_vector_algorithms_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_vector_algorithms_tests)
    add_test(NAME guest_libc_internal_vector_algorithms COMMAND guest_libc_internal_vector_algorithms_tests)
    set_tests_properties(guest_libc_internal_vector_algorithms PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_vector_algorithms PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE TimeGet.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_time_get_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalTimeGet.cpp)
    target_include_directories(guest_libc_internal_time_get_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_time_get_tests PRIVATE libSceLibcInternal libkernel libc ${CMAKE_DL_LIBS})
    configure_windows_unwind(guest_libc_internal_time_get_tests)
    add_test(NAME guest_libc_internal_time_get COMMAND guest_libc_internal_time_get_tests $<TARGET_FILE:libSceLibcInternal>)
    set_tests_properties(guest_libc_internal_time_get PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_time_get PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE IntegerExtrema.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_integer_extrema_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalIntegerExtrema.cpp)
    target_include_directories(guest_libc_internal_integer_extrema_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_integer_extrema_tests PRIVATE libSceLibcInternal libc libkernel)
    configure_windows_unwind(guest_libc_internal_integer_extrema_tests)
    add_test(NAME guest_libc_internal_integer_extrema COMMAND guest_libc_internal_integer_extrema_tests)
    set_tests_properties(guest_libc_internal_integer_extrema PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_integer_extrema PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE RelativeSleep.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_relative_sleep_tests ${LIBS_INCLUDE_DIR}/tests/GuestRelativeSleep.cpp)
    target_include_directories(guest_relative_sleep_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_relative_sleep_tests PRIVATE libSceLibcInternal libc)
    configure_windows_unwind(guest_relative_sleep_tests)
    set(relativeSleepTests guest_relative_sleep)
    add_test(NAME guest_relative_sleep COMMAND guest_relative_sleep_tests)
    if(Python3_Interpreter_FOUND)
        add_test(NAME guest_relative_sleep_large COMMAND ${Python3_EXECUTABLE}
            ${LIBS_INCLUDE_DIR}/tests/test_relative_sleep.py $<TARGET_FILE:guest_relative_sleep_tests>)
        list(APPEND relativeSleepTests guest_relative_sleep_large)
    endif()
    set_tests_properties(${relativeSleepTests} PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(${relativeSleepTests} PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE ExceptionDestructors.cpp)
target_sources(libSceLibcInternal PRIVATE ConstantMembers.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_constant_members_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalConstantMembers.cpp)
    target_include_directories(guest_libc_internal_constant_members_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_constant_members_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_constant_members_tests)
    add_test(NAME guest_libc_internal_constant_members COMMAND guest_libc_internal_constant_members_tests)
    set_tests_properties(guest_libc_internal_constant_members PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_constant_members PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE TypeInfoDestructors.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_type_info_destructors_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalTypeInfoDestructors.cpp)
    target_include_directories(guest_libc_internal_type_info_destructors_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_type_info_destructors_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_type_info_destructors_tests)
    add_test(NAME guest_libc_internal_type_info_destructors COMMAND guest_libc_internal_type_info_destructors_tests)
    set_tests_properties(guest_libc_internal_type_info_destructors PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_type_info_destructors PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE ExceptionVirtuals.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_exception_virtuals_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalExceptionVirtuals.cpp)
    target_include_directories(guest_libc_internal_exception_virtuals_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_exception_virtuals_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_exception_virtuals_tests)
    add_test(NAME guest_libc_internal_exception_virtuals COMMAND guest_libc_internal_exception_virtuals_tests)
    set_tests_properties(guest_libc_internal_exception_virtuals PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_exception_virtuals PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_exception_destructors_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalExceptionDestructors.cpp)
    target_include_directories(guest_libc_internal_exception_destructors_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_exception_destructors_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_exception_destructors_tests)
    add_test(NAME guest_libc_internal_exception_destructors COMMAND guest_libc_internal_exception_destructors_tests)
    set_tests_properties(guest_libc_internal_exception_destructors PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_exception_destructors PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_libc_internal_deleting_destructors_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalDeletingDestructors.cpp)
    target_include_directories(guest_libc_internal_deleting_destructors_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_deleting_destructors_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_deleting_destructors_tests)
    add_test(NAME guest_libc_internal_deleting_destructors COMMAND guest_libc_internal_deleting_destructors_tests)
    set_tests_properties(guest_libc_internal_deleting_destructors PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_deleting_destructors PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    if(MINGW OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
        enable_language(ASM)
        add_test_executable(guest_libc_internal_libc_forwards_tests
            ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalLibcForwards.cpp
            ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Exceptions.S)
        target_include_directories(guest_libc_internal_libc_forwards_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_libc_internal_libc_forwards_tests PRIVATE libSceLibcInternal libkernel libc)
        configure_windows_unwind(guest_libc_internal_libc_forwards_tests)
        add_test(NAME guest_libc_internal_libc_forwards COMMAND guest_libc_internal_libc_forwards_tests)
        set_tests_properties(guest_libc_internal_libc_forwards PROPERTIES TIMEOUT 20)
        if(WIN32)
            set_tests_properties(guest_libc_internal_libc_forwards PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
        endif()
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE AtomicWaitDeadline.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_atomic_wait_deadline_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalAtomicWaitDeadline.cpp)
    target_include_directories(guest_libc_internal_atomic_wait_deadline_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_atomic_wait_deadline_tests PRIVATE libSceLibcInternal libc libkernel)
    configure_windows_unwind(guest_libc_internal_atomic_wait_deadline_tests)
    add_test(NAME guest_libc_internal_atomic_wait_deadline COMMAND guest_libc_internal_atomic_wait_deadline_tests)
    set_tests_properties(guest_libc_internal_atomic_wait_deadline PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_atomic_wait_deadline PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE UnversionedFilesystemCalls.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_unversioned_filesystem_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalUnversionedFilesystem.cpp)
    target_include_directories(guest_libc_internal_unversioned_filesystem_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_unversioned_filesystem_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_unversioned_filesystem_tests)
    add_test(NAME guest_libc_internal_unversioned_filesystem COMMAND guest_libc_internal_unversioned_filesystem_tests)
    set_tests_properties(guest_libc_internal_unversioned_filesystem PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_unversioned_filesystem PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
configure_windows_unwind(libSceLibcInternal)
target_sources(libSceLibcInternal PRIVATE FilesystemStatistics.cpp PathStatistics.cpp)
target_sources(libSceLibcInternal PRIVATE Inet.cpp)
target_sources(libSceLibcInternal PRIVATE InventoryExports6.cpp)
target_sources(libSceLibcInternal PRIVATE IosBase.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_ios_base_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalIosBase.cpp)
    target_include_directories(guest_libc_internal_ios_base_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_ios_base_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_ios_base_tests)
    add_test(NAME guest_libc_internal_ios_base COMMAND guest_libc_internal_ios_base_tests)
    set_tests_properties(guest_libc_internal_ios_base PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_ios_base PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE BitsetToString.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_bitset_to_string_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalBitsetToString.cpp)
    target_include_directories(guest_libc_internal_bitset_to_string_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_bitset_to_string_tests PRIVATE libSceLibcInternal libc libkernel)
    configure_windows_unwind(guest_libc_internal_bitset_to_string_tests)
    add_test(NAME guest_libc_internal_bitset_to_string COMMAND guest_libc_internal_bitset_to_string_tests)
    set_tests_properties(guest_libc_internal_bitset_to_string PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_bitset_to_string PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE Filesystem.cpp)
target_sources(libSceLibcInternal PRIVATE FacetPut.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_facet_put_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalFacetPut.cpp)
    target_include_directories(guest_libc_internal_facet_put_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_facet_put_tests PRIVATE libSceLibcInternal libkernel libc ${CMAKE_DL_LIBS})
    configure_windows_unwind(guest_libc_internal_facet_put_tests)
    add_test(NAME guest_libc_internal_facet_put COMMAND guest_libc_internal_facet_put_tests $<TARGET_FILE:libSceLibcInternal>)
    set_tests_properties(guest_libc_internal_facet_put PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_facet_put PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE Collate.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_collate_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalCollate.cpp)
    target_include_directories(guest_libc_internal_collate_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_collate_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_collate_tests)
    add_test(NAME guest_libc_internal_collate COMMAND guest_libc_internal_collate_tests)
    set_tests_properties(guest_libc_internal_collate PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_collate PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE BasicString.cpp)
if(BUILD_TESTING AND (MINGW OR CMAKE_SYSTEM_NAME STREQUAL "Linux"))
    enable_language(ASM)
    add_test_executable(guest_libc_internal_basic_string_tests
        ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalBasicString.cpp
        ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Exceptions.S)
    target_include_directories(guest_libc_internal_basic_string_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_basic_string_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_basic_string_tests)
    add_test(NAME guest_libc_internal_basic_string COMMAND guest_libc_internal_basic_string_tests)
    set_tests_properties(guest_libc_internal_basic_string PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_basic_string PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
target_sources(libSceLibcInternal PRIVATE PlacementDelete.cpp)
target_sources(libSceLibcInternal PRIVATE RemPio2.cpp)
set_source_files_properties(RemPio2.cpp PROPERTIES COMPILE_OPTIONS $<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-ffp-contract=off>)

if(BUILD_TESTING)
    add_test_executable(guest_statvfs_tests ${LIBS_INCLUDE_DIR}/tests/GuestStatvfs.cpp)
    target_include_directories(guest_statvfs_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_statvfs_tests PRIVATE libSceLibcInternal libc)
    configure_windows_unwind(guest_statvfs_tests)
    add_test(NAME guest_statvfs COMMAND guest_statvfs_tests)
    set_tests_properties(guest_statvfs PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_statvfs PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_fstatvfs_conversion_tests ${LIBS_INCLUDE_DIR}/tests/GuestFstatvfsConversion.cpp FilesystemStatistics.cpp)
    target_include_directories(guest_fstatvfs_conversion_tests PRIVATE ${LIBS_INCLUDE_DIR})
    configure_windows_unwind(guest_fstatvfs_conversion_tests)
    add_test(NAME guest_fstatvfs_conversion COMMAND guest_fstatvfs_conversion_tests)
    set_tests_properties(guest_fstatvfs_conversion PROPERTIES TIMEOUT 20)
    add_test_executable(guest_kernel_rem_pio2_tests ${LIBS_INCLUDE_DIR}/tests/GuestKernelRemPio2.cpp)
    target_include_directories(guest_kernel_rem_pio2_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_kernel_rem_pio2_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_kernel_rem_pio2_tests)
    add_test(NAME guest_kernel_rem_pio2 COMMAND guest_kernel_rem_pio2_tests)
    set_tests_properties(guest_kernel_rem_pio2 PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_kernel_rem_pio2 PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_fstatvfs_tests ${LIBS_INCLUDE_DIR}/tests/GuestFstatvfs.cpp)
    target_include_directories(guest_fstatvfs_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_fstatvfs_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_fstatvfs_tests)
    add_test(NAME guest_fstatvfs COMMAND guest_fstatvfs_tests)
    set_tests_properties(guest_fstatvfs PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_fstatvfs PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_fdopendir_tests ${LIBS_INCLUDE_DIR}/tests/GuestFdopendir.cpp)
    target_include_directories(guest_fdopendir_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_fdopendir_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_fdopendir_tests)
    add_test(NAME guest_fdopendir COMMAND guest_fdopendir_tests)
    if(WIN32)
        set_tests_properties(guest_fdopendir PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_opendir2_tests ${LIBS_INCLUDE_DIR}/tests/GuestOpendir2.cpp)
    target_include_directories(guest_opendir2_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_opendir2_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_opendir2_tests)
    add_test(NAME guest_opendir2 COMMAND guest_opendir2_tests)
    if(WIN32)
        set_tests_properties(guest_opendir2 PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_utime_forwarding_tests ${LIBS_INCLUDE_DIR}/tests/GuestUtimeForwarding.cpp FileTime.cpp)
    target_include_directories(guest_utime_forwarding_tests PRIVATE ${LIBS_INCLUDE_DIR})
    configure_windows_unwind(guest_utime_forwarding_tests)
    add_test(NAME guest_utime_forwarding COMMAND guest_utime_forwarding_tests)
    set_tests_properties(guest_utime_forwarding PROPERTIES TIMEOUT 20)
    add_test_executable(guest_utime_tests ${LIBS_INCLUDE_DIR}/tests/GuestUtime.cpp)
    target_include_directories(guest_utime_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_utime_tests PRIVATE libSceLibcInternal libc)
    configure_windows_unwind(guest_utime_tests)
    add_test(NAME guest_utime COMMAND guest_utime_tests)
    set_tests_properties(guest_utime PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_utime PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    if(NOT WIN32)
        add_test_executable(guest_posix_spawn_errors_tests ${LIBS_INCLUDE_DIR}/tests/GuestPosixSpawnErrors.cpp)
        target_include_directories(guest_posix_spawn_errors_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_posix_spawn_errors_tests PRIVATE libSceLibcInternal libc libkernel)
        file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/spawn-errors)
        add_test(NAME guest_posix_spawn_errors COMMAND guest_posix_spawn_errors_tests)
        set_tests_properties(guest_posix_spawn_errors PROPERTIES TIMEOUT 20
            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/spawn-errors)
    endif()
    add_test_executable(guest_posix_spawn_tests ${LIBS_INCLUDE_DIR}/tests/GuestPosixSpawn.cpp)
    target_include_directories(guest_posix_spawn_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_posix_spawn_tests PRIVATE libSceLibcInternal libc libkernel)
    configure_windows_unwind(guest_posix_spawn_tests)
    add_test(NAME guest_posix_spawn COMMAND guest_posix_spawn_tests)
    set_tests_properties(guest_posix_spawn PROPERTIES TIMEOUT 20)
    add_asan_test_options(guest_posix_spawn handle_sigbus=0)
    if(WIN32)
        set_tests_properties(guest_posix_spawn PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_posix_spawn_optional_pid_tests ${LIBS_INCLUDE_DIR}/tests/GuestPosixSpawnOptionalPid.cpp)
    target_include_directories(guest_posix_spawn_optional_pid_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_posix_spawn_optional_pid_tests PRIVATE libSceLibcInternal libc libkernel)
    configure_windows_unwind(guest_posix_spawn_optional_pid_tests)
    file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/spawn-optional-pid)
    add_test(NAME guest_posix_spawn_optional_pid COMMAND guest_posix_spawn_optional_pid_tests)
    set_tests_properties(guest_posix_spawn_optional_pid PROPERTIES TIMEOUT 20
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/spawn-optional-pid)
    add_asan_test_options(guest_posix_spawn_optional_pid handle_sigbus=0)
    if(WIN32)
        set_tests_properties(guest_posix_spawn_optional_pid PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_program_name_tests ${LIBS_INCLUDE_DIR}/tests/GuestProgramName.cpp)
    target_include_directories(guest_program_name_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_program_name_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_program_name_tests)
    add_test(NAME guest_program_name COMMAND guest_program_name_tests)
    set_tests_properties(guest_program_name PROPERTIES TIMEOUT 20)
    if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
        add_test_executable(guest_posix_spawn_flags_tests ${LIBS_INCLUDE_DIR}/tests/GuestPosixSpawnFlags.cpp)
        target_include_directories(guest_posix_spawn_flags_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_posix_spawn_flags_tests PRIVATE libSceLibcInternal libc libkernel ${CMAKE_DL_LIBS})
        file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/spawn-flags)
        add_test(NAME guest_posix_spawn_flags COMMAND guest_posix_spawn_flags_tests)
        set_tests_properties(guest_posix_spawn_flags PROPERTIES TIMEOUT 20
            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/spawn-flags)
    endif()
    if(WIN32)
        set_tests_properties(guest_program_name PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_thread_atexit_tests ${LIBS_INCLUDE_DIR}/tests/GuestThreadAtexit.cpp)
    target_include_directories(guest_thread_atexit_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_thread_atexit_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_thread_atexit_tests)
    add_test(NAME guest_thread_atexit COMMAND guest_thread_atexit_tests)
    set_tests_properties(guest_thread_atexit PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_thread_atexit PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_err_tests ${LIBS_INCLUDE_DIR}/tests/GuestErr.cpp)
    target_include_directories(guest_err_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_err_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_err_tests)
    add_test(NAME guest_err COMMAND guest_err_tests)
    set_tests_properties(guest_err PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_err PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_libc_internal_memory_resource_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalMemoryResource.cpp)
    target_include_directories(guest_libc_internal_memory_resource_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_memory_resource_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_memory_resource_tests)
    add_test(NAME guest_libc_internal_memory_resource COMMAND guest_libc_internal_memory_resource_tests)
    set_tests_properties(guest_libc_internal_memory_resource PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_memory_resource PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_libc_internal_runtime_hooks_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalRuntimeHooks.cpp)
    target_include_directories(guest_libc_internal_runtime_hooks_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_runtime_hooks_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_runtime_hooks_tests)
    add_test(NAME guest_libc_internal_runtime_hooks COMMAND guest_libc_internal_runtime_hooks_tests)
    set_tests_properties(guest_libc_internal_runtime_hooks PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_runtime_hooks PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_libc_internal_empty_facet_members_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalEmptyFacetMembers.cpp)
    target_include_directories(guest_libc_internal_empty_facet_members_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_empty_facet_members_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_empty_facet_members_tests)
    add_test(NAME guest_libc_internal_empty_facet_members COMMAND guest_libc_internal_empty_facet_members_tests)
    set_tests_properties(guest_libc_internal_empty_facet_members PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_empty_facet_members PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_libc_internal_facet_queries_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalFacetQueries.cpp)
    target_include_directories(guest_libc_internal_facet_queries_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_facet_queries_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_facet_queries_tests)
    add_test(NAME guest_libc_internal_facet_queries COMMAND guest_libc_internal_facet_queries_tests)
    set_tests_properties(guest_libc_internal_facet_queries PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_facet_queries PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_getopt_tests ${LIBS_INCLUDE_DIR}/tests/GuestGetopt.cpp)
    target_include_directories(guest_getopt_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_getopt_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_getopt_tests)
    add_test(NAME guest_getopt COMMAND guest_getopt_tests)
    set_tests_properties(guest_getopt PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_getopt PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_inet_address_tests ${LIBS_INCLUDE_DIR}/tests/GuestInetAddress.cpp)
    target_include_directories(guest_inet_address_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_inet_address_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_inet_address_tests)
    add_test(NAME guest_inet_address COMMAND guest_inet_address_tests)
    set_tests_properties(guest_inet_address PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_inet_address PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_force_tls_destructor_tests ${LIBS_INCLUDE_DIR}/tests/GuestForceTlsDestructor.cpp)
    target_include_directories(guest_force_tls_destructor_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_force_tls_destructor_tests PRIVATE libSceLibcInternal libkernel libc ${CMAKE_DL_LIBS})
    configure_windows_unwind(guest_force_tls_destructor_tests)
    add_test(NAME guest_force_tls_destructor COMMAND guest_force_tls_destructor_tests)
    set_tests_properties(guest_force_tls_destructor PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_force_tls_destructor PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_fminf_tests ${LIBS_INCLUDE_DIR}/tests/GuestFminf.cpp)
    target_include_directories(guest_fminf_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_fminf_tests PRIVATE libSceLibcInternal libc)
    configure_windows_unwind(guest_fminf_tests)
    add_test(NAME guest_fminf COMMAND guest_fminf_tests)
    set_tests_properties(guest_fminf PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_fminf PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_signal_list_tests ${LIBS_INCLUDE_DIR}/tests/GuestSignalList.cpp)
    target_include_directories(guest_signal_list_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_signal_list_tests PRIVATE libSceLibcInternal)
    configure_windows_unwind(guest_signal_list_tests)
    add_test(NAME guest_signal_list COMMAND guest_signal_list_tests)
    set_tests_properties(guest_signal_list PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_signal_list PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()

    add_test_executable(guest_legacy_signal_mask_tests ${LIBS_INCLUDE_DIR}/tests/GuestLegacySignalMask.cpp)
    target_include_directories(guest_legacy_signal_mask_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_legacy_signal_mask_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_legacy_signal_mask_tests)
    add_test(NAME guest_legacy_signal_mask COMMAND guest_legacy_signal_mask_tests)
    set_tests_properties(guest_legacy_signal_mask PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_legacy_signal_mask PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
    add_test_executable(guest_legacy_signal_mask_forwarding_tests
        ${LIBS_INCLUDE_DIR}/tests/GuestLegacySignalMaskForwarding.cpp SignalMask.cpp)
    target_include_directories(guest_legacy_signal_mask_forwarding_tests PRIVATE ${LIBS_INCLUDE_DIR})
    configure_windows_unwind(guest_legacy_signal_mask_forwarding_tests)
    add_test(NAME guest_legacy_signal_mask_forwarding COMMAND guest_legacy_signal_mask_forwarding_tests)
    set_tests_properties(guest_legacy_signal_mask_forwarding PROPERTIES TIMEOUT 10)
endif()

if(BUILD_TESTING)
    add_test_executable(guest_libc_filesystem_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcFilesystem.cpp)
    target_include_directories(guest_libc_filesystem_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_filesystem_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_filesystem_tests)
    add_test(NAME guest_libc_filesystem COMMAND guest_libc_filesystem_tests)
    if(WIN32)
        set_tests_properties(guest_libc_filesystem PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()

target_sources(libSceLibcInternal PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Sigvec.cpp)

if(BUILD_TESTING AND (WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Linux"))
    add_test_executable(guest_sigvec_modules_tests
        ${LIBS_INCLUDE_DIR}/tests/GuestSigvecModules.cpp
        ${LIBS_INCLUDE_DIR}/nid/src/NidCompute.cpp
        ${LIBS_INCLUDE_DIR}/nid/src/Sha1.cpp)
    target_include_directories(guest_sigvec_modules_tests PRIVATE ${LIBS_INCLUDE_DIR} ${LIBS_INCLUDE_DIR}/nid/include)
    target_link_libraries(guest_sigvec_modules_tests PRIVATE ${CMAKE_DL_LIBS})
    set_source_files_properties(${LIBS_INCLUDE_DIR}/tests/GuestSigvecModules.cpp PROPERTIES COMPILE_OPTIONS "-fno-exceptions;-fno-asynchronous-unwind-tables")
    if(MINGW)
        target_compile_options(guest_sigvec_modules_tests PRIVATE -fasynchronous-unwind-tables)
        target_link_options(guest_sigvec_modules_tests PRIVATE -static -static-libgcc -static-libstdc++)
    endif()
    add_library(sigvec_modules_exceptions SHARED ${LIBS_INCLUDE_DIR}/tests/SigvecModulesExceptions.cpp)
    target_include_directories(sigvec_modules_exceptions PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(sigvec_modules_exceptions PRIVATE libc)
    set_target_properties(sigvec_modules_exceptions PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
    configure_windows_unwind(sigvec_modules_exceptions)
    add_dependencies(guest_sigvec_modules_tests libc libkernel libSceLibcInternal nid_patcher sigvec_modules_exceptions)
    set(sigvecAllocatorArgument)
    if(TARGET mimalloc)
        set(sigvecAllocatorArgument -DALLOCATOR_DIRECTORY=$<TARGET_FILE_DIR:mimalloc>)
    endif()
    add_test(NAME guest_sigvec_modules COMMAND ${CMAKE_COMMAND}
        -DEXCEPTION_PROBE=$<TARGET_FILE:sigvec_modules_exceptions>
        -DPATCHER=$<TARGET_FILE:nid_patcher>
        -DLIBC=$<TARGET_FILE:libc>
        -DKERNEL=$<TARGET_FILE:libkernel>
        -DINTERNAL=$<TARGET_FILE:libSceLibcInternal>
        ${sigvecAllocatorArgument}
        -DWORK_DIR=${CMAKE_CURRENT_BINARY_DIR}/sigvec-modules
        -P ${LIBS_INCLUDE_DIR}/tests/SigvecModules.cmake
        -- "$<TARGET_FILE:guest_sigvec_modules_tests>")
    set_tests_properties(guest_sigvec_modules PROPERTIES TIMEOUT 20)
endif()

target_sources(libSceLibcInternal PRIVATE MultiPrecision.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_multi_precision_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalMultiPrecision.cpp)
    target_include_directories(guest_libc_internal_multi_precision_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_multi_precision_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_multi_precision_tests)
    add_test(NAME guest_libc_internal_multi_precision COMMAND guest_libc_internal_multi_precision_tests)
    set_tests_properties(guest_libc_internal_multi_precision PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_multi_precision PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()

if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_firmware_answers_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalFirmwareAnswers.cpp)
    target_include_directories(guest_libc_internal_firmware_answers_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_firmware_answers_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_firmware_answers_tests)
    add_test(NAME guest_libc_internal_firmware_answers COMMAND guest_libc_internal_firmware_answers_tests)
    set_tests_properties(guest_libc_internal_firmware_answers PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_firmware_answers PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()

target_sources(libSceLibcInternal PRIVATE Unexpected.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_unexpected_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalUnexpected.cpp)
    target_include_directories(guest_libc_internal_unexpected_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_unexpected_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_unexpected_tests)
    add_test(NAME guest_libc_internal_unexpected COMMAND guest_libc_internal_unexpected_tests)
    set_tests_properties(guest_libc_internal_unexpected PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_unexpected PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()

target_sources(libSceLibcInternal PRIVATE NestedException.cpp)
if(BUILD_TESTING)
    add_test_executable(guest_libc_internal_nested_exception_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalNestedException.cpp)
    target_include_directories(guest_libc_internal_nested_exception_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_internal_nested_exception_tests PRIVATE libSceLibcInternal libkernel libc)
    configure_windows_unwind(guest_libc_internal_nested_exception_tests)
    add_test(NAME guest_libc_internal_nested_exception COMMAND guest_libc_internal_nested_exception_tests)
    set_tests_properties(guest_libc_internal_nested_exception PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_internal_nested_exception PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
    endif()
endif()
