vcpkg_check_linkage(ONLY_STATIC_LIBRARY ONLY_DYNAMIC_CRT)

vcpkg_from_github(
    OUT_SOURCE_PATH SOURCE_PATH
    REPO Microsoft/DirectXMesh
    REF nov2020
    SHA512 07bf8acba1f15f1b74d864ac624c7e0bfbdf5927c3e66f94ef78ab447e757daa01351ca8e1c8e8652dbb7008cee13c30247922af2d1712e61bc50bdb55cedf42
    HEAD_REF master
)

vcpkg_check_features(
    OUT_FEATURE_OPTIONS FEATURE_OPTIONS
    FEATURES
        dx12 BUILD_DX12
)

vcpkg_configure_cmake(
    SOURCE_PATH ${SOURCE_PATH}
    PREFER_NINJA
    OPTIONS ${FEATURE_OPTIONS}
)

if(NOT VCPKG_TARGET_IS_UWP AND NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
    vcpkg_build_cmake()
else()
    vcpkg_build_cmake(TARGET DirectXMesh)
endif()

file(INSTALL ${SOURCE_PATH}/DirectXMesh/DirectXMesh.h DESTINATION ${CURRENT_PACKAGES_DIR}/include)
file(INSTALL ${SOURCE_PATH}/DirectXMesh/DirectXMesh.inl DESTINATION ${CURRENT_PACKAGES_DIR}/include)

file(GLOB_RECURSE DEBUG_LIB ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/bin/CMake/*.lib)
file(GLOB_RECURSE RELEASE_LIB ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bin/CMake/*.lib)
file(INSTALL ${DEBUG_LIB} DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
file(INSTALL ${RELEASE_LIB} DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
if(NOT VCPKG_TARGET_IS_UWP AND NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
  vcpkg_copy_tools(
        TOOL_NAMES Meshconvert
        SEARCH_DIR ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bin/CMake
    )
endif()

file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
