add_library(libSceLibreSsl SHARED EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/Export.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/Digest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/Runtime.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/Aes.cpp)
target_include_directories(libSceLibreSsl PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(libSceLibreSsl PRIVATE mbedcrypto)
configure_windows_unwind(libSceLibreSsl)

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

    add_test_executable(guest_libressl_digest_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibreSslDigest.cpp)
    target_include_directories(guest_libressl_digest_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libressl_digest_tests PRIVATE libSceLibreSsl libc)
    configure_windows_unwind(guest_libressl_digest_tests)
    add_test(NAME guest_libressl_digest COMMAND guest_libressl_digest_tests)
    set_tests_properties(guest_libressl_digest PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_libressl_digest PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibreSsl>")
    endif()

    add_test_executable(guest_libressl_des_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibreSslDes.cpp)
    target_include_directories(guest_libressl_des_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libressl_des_tests PRIVATE libSceLibreSsl libc)
    configure_windows_unwind(guest_libressl_des_tests)
    add_test(NAME guest_libressl_des COMMAND guest_libressl_des_tests)
    set_tests_properties(guest_libressl_des PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libressl_des PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibreSsl>")
    endif()

    add_test_executable(guest_libressl_runtime_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibreSslRuntime.cpp)
    target_include_directories(guest_libressl_runtime_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libressl_runtime_tests PRIVATE libSceLibreSsl libc)
    configure_windows_unwind(guest_libressl_runtime_tests)
    add_test(NAME guest_libressl_runtime COMMAND guest_libressl_runtime_tests)
    set_tests_properties(guest_libressl_runtime PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_libressl_runtime PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibreSsl>")
    endif()

    add_test_executable(guest_libressl_aes_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibreSslAes.cpp)
    target_include_directories(guest_libressl_aes_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libressl_aes_tests PRIVATE libSceLibreSsl libc)
    configure_windows_unwind(guest_libressl_aes_tests)
    add_test(NAME guest_libressl_aes COMMAND guest_libressl_aes_tests)
    set_tests_properties(guest_libressl_aes PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_libressl_aes PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibreSsl>")
    endif()
endif()
