blob: 9766c8f12e473c42fb48bf406eded71ff8e841e9 [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#
22# Additional permission under GNU GPL version 3 section 7:
23#
24# If you modify this program, or any covered work, by linking or
25# combining it with the OpenSSL project's OpenSSL library (or a
26# modified version of that library), containing parts covered by the
27# terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
28# grants you additional permission to convey the resulting work.
29# Corresponding Source for a non-source form of such a combination
30# shall include the source code for the parts of OpenSSL used as well
31# as that of the covered work.
32#
33
34FIND_PROGRAM(GLIB_COMPILE_RESOURCES_EXECUTABLE NAMES glib-compile-resources)
35MARK_AS_ADVANCED(GLIB_COMPILE_RESOURCES_EXECUTABLE)
36
37INCLUDE(CMakeParseArguments)
38
39FUNCTION(GLIB_COMPILE_RESOURCES output)
40 CMAKE_PARSE_ARGUMENTS(ARGS "" "SOURCE" ${ARGN})
41 SET(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
42 SET(out_files "")
43
44 FOREACH(src ${ARGS_SOURCE} ${ARGS_UNPARSED_ARGUMENTS})
45 SET(in_file "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
46 GET_FILENAME_COMPONENT(WORKING_DIR ${in_file} PATH)
47 STRING(REPLACE ".xml" ".c" src ${src})
48 SET(out_file "${DIRECTORY}/${src}")
49 GET_FILENAME_COMPONENT(OUPUT_DIR ${out_file} PATH)
50 FILE(MAKE_DIRECTORY ${OUPUT_DIR})
51 LIST(APPEND out_files "${DIRECTORY}/${src}")
52
53 #FIXME implicit depends currently not working
54 EXECUTE_PROCESS(
55 COMMAND
56 ${GLIB_COMPILE_RESOURCES_EXECUTABLE}
57 "--generate-dependencies"
58 ${in_file}
59 WORKING_DIRECTORY ${WORKING_DIR}
60 OUTPUT_VARIABLE in_file_dep
61 )
62 STRING(REGEX REPLACE "(\r?\n)" ";" in_file_dep "${in_file_dep}")
63 SET(in_file_dep_path "")
64 FOREACH(dep ${in_file_dep})
65 LIST(APPEND in_file_dep_path "${WORKING_DIR}/${dep}")
66 ENDFOREACH(dep ${in_file_dep})
67 ADD_CUSTOM_COMMAND(
68 OUTPUT ${out_file}
69 WORKING_DIRECTORY ${WORKING_DIR}
70 COMMAND
71 ${GLIB_COMPILE_RESOURCES_EXECUTABLE}
72 ARGS
73 "--generate-source"
74 "--target=${out_file}"
75 ${in_file}
76 DEPENDS
77 ${in_file};${in_file_dep_path}
78 )
79 ENDFOREACH(src ${ARGS_SOURCES} ${ARGS_UNPARSED_ARGUMENTS})
80 SET(${output} ${out_files} PARENT_SCOPE)
81ENDFUNCTION(GLIB_COMPILE_RESOURCES)