if(VCPKG_TARGET_IS_WINDOWS)
    vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
    set(PATCHES curl.patch)
    #TODO: Still does not work. Requires proper "signal" support and "unistd"
else()
    set(PATCHES openssl.patch) # needed if curl is using openssl
endif()

vcpkg_from_github(
    OUT_SOURCE_PATH SOURCE_PATH
    REPO wanduow/wandio
    REF ${VERSION}
    SHA512 6468a6f22f7536b78c27d9c4399454ac0f471ea94c832869b5dad1b334edb8d66ebe931a0614ccc052b21a85fb21310fa9410850ad0ebbb4d722e3036990ffea
    HEAD_REF master
    PATCHES configure.lib.patch # This is how configure.ac files with dependencies get fixed.
            configure.patch
            ${PATCHES}
)

if (VCPKG_TARGET_IS_ANDROID)
    list(APPEND OPTIONS ac_cv_func_malloc_0_nonnull=yes)
    list(APPEND OPTIONS ac_cv_func_realloc_0_nonnull=yes)
endif()

vcpkg_make_configure(
    AUTORECONF
    SOURCE_PATH ${SOURCE_PATH}
    COPY_SOURCE
    OPTIONS
        ${OPTIONS}
)
vcpkg_make_install()

if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
    file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin)
endif()

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)

vcpkg_copy_pdbs()

file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
