#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#

IF(NOT CMAKE_SET_XSLT)

set(CMAKE_SET_XSLT true)

find_program(CMAKE_XSLTPROC NAME xsltproc HINTS ${CMAKE_SYSTEM_PROGRAM_PATH})

if (CMAKE_XSLTPROC)
  message(STATUS "XSLTPROC found")
else()
  message(FATAL_ERROR "XSLTPROC not found")
endif()

function(xslt_generate)
  set(OPTIONS )
  set(SINGLE_VALUE_KEYWORDS OUT_FILE XML_FILE XSL_FILE)
  set(MULTI_VALUE_KEYWORDS)
  cmake_parse_arguments(XSLT
                        "${OPTIONS}"
                        "${SINGLE_VALUE_KEYWORDS}"
                        "${MULTI_VALUE_KEYWORDS}"
                        ${ARGN})


  message(STATUS "generating ${CMAKE_XSLTPROC} --nonet  -o ${XSLT_OUT_FILE} ${XSLT_XSL_FILE} ${XSLT_XML_FILE} ")
  execute_process(
    COMMAND ${CMAKE_XSLTPROC} --nonet -o ${XSLT_OUT_FILE} ${XSLT_XSL_FILE} ${XSLT_XML_FILE}
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    OUTPUT_VARIABLE OUT
    ERROR_VARIABLE ERR
  )

  message(STATUS ${OUT})
  message(STATUS ${ERR})

endfunction()

ENDIF()
