#pugixml

set(PUGIXML_GIT_TAG "v1.10")
set(PUGIXML_INSTALL_DIR ${EXTERNALS_INSTALL_DIR}/pugixml-${PUGIXML_GIT_TAG})

if(NOT EXISTS "${PUGIXML_INSTALL_DIR}/include/pugixml.hpp")
    set(PUGIXML_BUILD_DIRECTORY ${EXTERNALS_BUILD_DIR}/externals/pugixml)
    file(REMOVE_RECURSE ${PUGIXML_BUILD_DIRECTORY})
    file(MAKE_DIRECTORY ${PUGIXML_BUILD_DIRECTORY})
    execute_process(
        COMMAND ${CMAKE_COMMAND}
            -DPUGIXML_GIT_TAG=${PUGIXML_GIT_TAG}
			-DPUGIXML_BUILD_DIR=${PUGIXML_BUILD_DIRECTORY}
            -DPUGIXML_INSTALL_DIR=${PUGIXML_INSTALL_DIR}
            -G ${CMAKE_GENERATOR}
            ${CMAKE_GENERATOR_PLATFORM_PARAM}
            -S ${CMAKE_SOURCE_DIR}/externals/pugixml
            -B ${PUGIXML_BUILD_DIRECTORY}
        WORKING_DIRECTORY ${PUGIXML_BUILD_DIRECTORY}
    )
    execute_process(
        COMMAND ${CMAKE_COMMAND}
            --build .
        WORKING_DIRECTORY ${PUGIXML_BUILD_DIRECTORY}
    )
endif()

set(CMAKE_PREFIX_PATH_OLD ${CMAKE_PREFIX_PATH})
set(CMAKE_PREFIX_PATH ${PUGIXML_INSTALL_DIR})
find_package(pugixml REQUIRED)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH_OLD})

#end pugixml
