From 56bc45ce4d07a7a9a415e9dc8ad2f7c3f3c9e48d Mon Sep 17 00:00:00 2001 From: fiaxh Date: Thu, 2 Mar 2017 15:37:32 +0100 Subject: Initial commit --- cmake/GenerateGXML.cmake | 124 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 cmake/GenerateGXML.cmake (limited to 'cmake/GenerateGXML.cmake') diff --git a/cmake/GenerateGXML.cmake b/cmake/GenerateGXML.cmake new file mode 100644 index 00000000..4be96041 --- /dev/null +++ b/cmake/GenerateGXML.cmake @@ -0,0 +1,124 @@ +include(CMakeParseArguments) + +# Generates the resource XML controlling file from resource list (and saves it +# to xml_path). It's not recommended to use this function directly, since it +# doesn't handle invalid arguments. It is used by the function +# COMPILE_GRESOURCES() to create a custom command, so that this function is +# invoked at build-time in script mode from CMake. +function(GENERATE_GXML xml_path) + # Available options: + # COMPRESS_ALL, NO_COMPRESS_ALL Overrides the COMPRESS flag in all + # registered resources. + # STRIPBLANKS_ALL, NO_STRIPBLANKS_ALL Overrides the STRIPBLANKS flag in all + # registered resources. + # TOPIXDATA_ALL, NO_TOPIXDATA_ALL Overrides the TOPIXDATA flag in all + # registered resources. + set(GXML_OPTIONS COMPRESS_ALL NO_COMPRESS_ALL + STRIPBLANKS_ALL NO_STRIPBLANKS_ALL + TOPIXDATA_ALL NO_TOPIXDATA_ALL) + + # Available one value options: + # PREFIX Overrides the resource prefix that is prepended to each + # relative file name in registered resources. + set(GXML_ONEVALUEARGS PREFIX) + + # Available multi-value options: + # RESOURCES The list of resource files. Whether absolute or relative path is + # equal, absolute paths are stripped down to relative ones. If the + # absolute path is not inside the given base directory SOURCE_DIR + # or CMAKE_SOURCE_DIR (if SOURCE_DIR is not overriden), this + # function aborts. + set(GXML_MULTIVALUEARGS RESOURCES) + + # Parse the arguments. + cmake_parse_arguments(GXML_ARG + "${GXML_OPTIONS}" + "${GXML_ONEVALUEARGS}" + "${GXML_MULTIVALUEARGS}" + "${ARGN}") + + # Variable to store the double-quote (") string. Since escaping + # double-quotes in strings is not possible we need a helper variable that + # does this job for us. + set(Q \") + + # Process resources and generate XML file. + # Begin with the XML header and header nodes. + set(GXML_XML_FILE "") + set(GXML_XML_FILE "${GXML_XML_FILE}") + + # Process each resource. + foreach(res ${GXML_ARG_RESOURCES}) + if ("${res}" STREQUAL "COMPRESS") + set(GXML_COMPRESSION_FLAG ON) + elseif ("${res}" STREQUAL "STRIPBLANKS") + set(GXML_STRIPBLANKS_FLAG ON) + elseif ("${res}" STREQUAL "TOPIXDATA") + set(GXML_TOPIXDATA_FLAG ON) + else() + # The file name. + set(GXML_RESOURCE_PATH "${res}") + + # Append to real resource file dependency list. + list(APPEND GXML_RESOURCES_DEPENDENCIES ${GXML_RESOURCE_PATH}) + + # Assemble node. + set(GXML_RES_LINE "${GXML_RESOURCE_PATH}") + + # Append to file string. + set(GXML_XML_FILE "${GXML_XML_FILE}${GXML_RES_LINE}") + + # Unset variables. + unset(GXML_COMPRESSION_FLAG) + unset(GXML_STRIPBLANKS_FLAG) + unset(GXML_TOPIXDATA_FLAG) + endif() + + endforeach() + + # Append closing nodes. + set(GXML_XML_FILE "${GXML_XML_FILE}") + + # Use "file" function to generate XML controlling file. + get_filename_component(xml_path_only_name "${xml_path}" NAME) + file(WRITE ${xml_path} ${GXML_XML_FILE}) + +endfunction() + -- cgit v1.2.3-54-g00ecf