blob: cf51a923ead9561ae0869f81f94ca31b4be7423f [file] [log] [blame]
Stepan Salenikovicha8df7ea2015-02-18 12:46:36 -05001# The code below was taken from the Venom project which is released under the
2# GNU General Public License, version 3
3#
4# Copyright (C) 2013 Venom authors and contributors
5#
6# See https://github.com/naxuroqa/Venom for a list of contributors.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21#
Stepan Salenikovicha8df7ea2015-02-18 12:46:36 -050022
23FIND_PROGRAM(GLIB_COMPILE_RESOURCES_EXECUTABLE NAMES glib-compile-resources)
24MARK_AS_ADVANCED(GLIB_COMPILE_RESOURCES_EXECUTABLE)
25
26INCLUDE(CMakeParseArguments)
27
28FUNCTION(GLIB_COMPILE_RESOURCES output)
29 CMAKE_PARSE_ARGUMENTS(ARGS "" "SOURCE" ${ARGN})
30 SET(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
31 SET(out_files "")
32
33 FOREACH(src ${ARGS_SOURCE} ${ARGS_UNPARSED_ARGUMENTS})
34 SET(in_file "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
35 GET_FILENAME_COMPONENT(WORKING_DIR ${in_file} PATH)
36 STRING(REPLACE ".xml" ".c" src ${src})
37 SET(out_file "${DIRECTORY}/${src}")
38 GET_FILENAME_COMPONENT(OUPUT_DIR ${out_file} PATH)
39 FILE(MAKE_DIRECTORY ${OUPUT_DIR})
40 LIST(APPEND out_files "${DIRECTORY}/${src}")
41
42 #FIXME implicit depends currently not working
43 EXECUTE_PROCESS(
44 COMMAND
45 ${GLIB_COMPILE_RESOURCES_EXECUTABLE}
46 "--generate-dependencies"
47 ${in_file}
48 WORKING_DIRECTORY ${WORKING_DIR}
49 OUTPUT_VARIABLE in_file_dep
50 )
51 STRING(REGEX REPLACE "(\r?\n)" ";" in_file_dep "${in_file_dep}")
52 SET(in_file_dep_path "")
53 FOREACH(dep ${in_file_dep})
54 LIST(APPEND in_file_dep_path "${WORKING_DIR}/${dep}")
55 ENDFOREACH(dep ${in_file_dep})
56 ADD_CUSTOM_COMMAND(
57 OUTPUT ${out_file}
58 WORKING_DIRECTORY ${WORKING_DIR}
59 COMMAND
60 ${GLIB_COMPILE_RESOURCES_EXECUTABLE}
61 ARGS
62 "--generate-source"
63 "--target=${out_file}"
64 ${in_file}
65 DEPENDS
66 ${in_file};${in_file_dep_path}
67 )
68 ENDFOREACH(src ${ARGS_SOURCES} ${ARGS_UNPARSED_ARGUMENTS})
69 SET(${output} ${out_files} PARENT_SCOPE)
70ENDFUNCTION(GLIB_COMPILE_RESOURCES)