add_library(libcairo SHARED EXCLUDE_FROM_ALL Export.cpp Matrix.cpp Surface.cpp Context.cpp FontOptions.cpp Region.cpp)
target_include_directories(libcairo PRIVATE ${LIBS_INCLUDE_DIR})
configure_windows_unwind(libcairo)

if(BUILD_TESTING)
    add_test_executable(guest_cairo_matrix_tests ${LIBS_INCLUDE_DIR}/tests/GuestCairoMatrix.cpp)
    target_include_directories(guest_cairo_matrix_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_cairo_matrix_tests PRIVATE libcairo libc)
    configure_windows_unwind(guest_cairo_matrix_tests)
    add_test(NAME guest_cairo_matrix COMMAND guest_cairo_matrix_tests)
    set_tests_properties(guest_cairo_matrix PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_cairo_matrix PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libcairo>")
    endif()
    add_test_executable(guest_cairo_surface_tests ${LIBS_INCLUDE_DIR}/tests/GuestCairoSurface.cpp Surface.cpp)
    target_include_directories(guest_cairo_surface_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_cairo_surface_tests PRIVATE libc)
    configure_windows_unwind(guest_cairo_surface_tests)
    add_test(NAME guest_cairo_surface COMMAND guest_cairo_surface_tests)
    set_tests_properties(guest_cairo_surface PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_cairo_surface PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_cairo_surface_user_data_tests ${LIBS_INCLUDE_DIR}/tests/GuestCairoSurfaceUserData.cpp Surface.cpp)
    target_include_directories(guest_cairo_surface_user_data_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_cairo_surface_user_data_tests PRIVATE libc)
    configure_windows_unwind(guest_cairo_surface_user_data_tests)
    add_test(NAME guest_cairo_surface_user_data COMMAND guest_cairo_surface_user_data_tests)
    set_tests_properties(guest_cairo_surface_user_data PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_cairo_surface_user_data PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_cairo_context_tests ${LIBS_INCLUDE_DIR}/tests/GuestCairoContext.cpp)
    target_include_directories(guest_cairo_context_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_cairo_context_tests PRIVATE libcairo libc)
    configure_windows_unwind(guest_cairo_context_tests)
    add_test(NAME guest_cairo_context COMMAND guest_cairo_context_tests)
    set_tests_properties(guest_cairo_context PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_cairo_context PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libcairo>")
    endif()
    add_test_executable(guest_cairo_font_options_tests ${LIBS_INCLUDE_DIR}/tests/GuestCairoFontOptions.cpp)
    target_include_directories(guest_cairo_font_options_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_cairo_font_options_tests PRIVATE libcairo libc)
    configure_windows_unwind(guest_cairo_font_options_tests)
    add_test(NAME guest_cairo_font_options COMMAND guest_cairo_font_options_tests)
    set_tests_properties(guest_cairo_font_options PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_cairo_font_options PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libcairo>")
    endif()
    add_test_executable(guest_cairo_regions_tests ${LIBS_INCLUDE_DIR}/tests/GuestCairoRegions.cpp)
    target_include_directories(guest_cairo_regions_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_cairo_regions_tests PRIVATE libcairo libc)
    configure_windows_unwind(guest_cairo_regions_tests)
    add_test(NAME guest_cairo_regions COMMAND guest_cairo_regions_tests)
    set_tests_properties(guest_cairo_regions PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_cairo_regions PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libcairo>")
    endif()
    add_test_executable(guest_cairo_graphics_state_tests ${LIBS_INCLUDE_DIR}/tests/GuestCairoGraphicsState.cpp)
    target_include_directories(guest_cairo_graphics_state_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_cairo_graphics_state_tests PRIVATE libcairo libc)
    configure_windows_unwind(guest_cairo_graphics_state_tests)
    add_test(NAME guest_cairo_graphics_state COMMAND guest_cairo_graphics_state_tests)
    set_tests_properties(guest_cairo_graphics_state PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_cairo_graphics_state PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libcairo>")
    endif()
    add_test_executable(guest_cairo_path_tests ${LIBS_INCLUDE_DIR}/tests/GuestCairoPath.cpp)
    target_include_directories(guest_cairo_path_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_cairo_path_tests PRIVATE libcairo libc)
    configure_windows_unwind(guest_cairo_path_tests)
    add_test(NAME guest_cairo_path COMMAND guest_cairo_path_tests)
    set_tests_properties(guest_cairo_path PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_cairo_path PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libcairo>")
    endif()
endif()
