vcpkg_from_github(
        OUT_SOURCE_PATH REPO_ROOT_PATH
        REPO {{ port.git.repo }}
        REF {{ port.git.ref }}
        SHA512 {{ port.git.sha }}
        HEAD_REF {{ port.git.head_ref }}
)

{% if port.git.subdirectory %}set(SOURCE_PATH "${REPO_ROOT_PATH}/{{ port.git.subdirectory }}"){% else %}set(SOURCE_PATH "${REPO_ROOT_PATH}"){% endif %}

set(FEATURE_OPTIONS "")
if("tests" IN_LIST FEATURES)
    list(APPEND FEATURE_OPTIONS -DPORTAL_BUILD_TESTS=ON)
else()
    list(APPEND FEATURE_OPTIONS -DPORTAL_BUILD_TESTS=OFF)
endif()

if("profile" IN_LIST FEATURES)
    list(APPEND FEATURE_OPTIONS -DPORTAL_PROFILE=ON)
endif()

vcpkg_cmake_configure(
        SOURCE_PATH "${SOURCE_PATH}"
        OPTIONS
        {% if port.options %}OPTIONS{% for option in port.options %}
        -D{{ option }}{% endfor %}{% endif %}
        ${FEATURE_OPTIONS}
)

vcpkg_cmake_install()

vcpkg_cmake_config_fixup(
        PACKAGE_NAME {{ port.name }}
        CONFIG_PATH share/{{ port.name }}
)

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" "${CURRENT_PACKAGES_DIR}/debug/share")

configure_file("${CMAKE_CURRENT_LIST_DIR}/usage" "${CURRENT_PACKAGES_DIR}/share/${PORT}/usage" COPYONLY)

vcpkg_copy_pdbs()
vcpkg_install_copyright(FILE_LIST "${REPO_ROOT_PATH}/LICENSE")