Skip to content

Commit 7c7fd0c

Browse files
committed
Update GResources.cmake
1 parent eac5ca0 commit 7c7fd0c

2 files changed

Lines changed: 64 additions & 33 deletions

File tree

cmake/gresource.cmake

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,68 @@
1-
# Used for GResource.
21
#
3-
# resource_dir: Directory where the .gresource.xml is located.
4-
# resource_file: Filename of the .gresource.xml file (just the
5-
# filename, not the complete path).
6-
# output_dir: Directory where the C output file is written.
7-
# output_file: This variable will be set with the complete path of the
8-
# output C file.
2+
# Copyright (C) 2013 Venom authors and contributors
3+
#
4+
# This file is part of Venom.
5+
#
6+
# Venom is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Venom is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with Venom. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
20+
FIND_PROGRAM(GLIB_COMPILE_RESOURCES_EXECUTABLE NAMES glib-compile-resources)
21+
MARK_AS_ADVANCED(GLIB_COMPILE_RESOURCES_EXECUTABLE)
922

10-
function (gresource resource_dir resource_file output_dir output_file)
11-
# Get the output file path
12-
get_filename_component (resource_name ${resource_file} NAME_WE)
13-
set (output "${output_dir}/${resource_name}-resources.c")
14-
set (${output_file} ${output} PARENT_SCOPE)
23+
INCLUDE(CMakeParseArguments)
1524

16-
# Get the dependencies of the gresource
17-
execute_process (
18-
OUTPUT_VARIABLE _files
19-
WORKING_DIRECTORY ${resource_dir}
20-
COMMAND ${gresources_executable} --generate-dependencies ${resource_file}
21-
)
25+
FUNCTION(GLIB_COMPILE_RESOURCES output)
26+
CMAKE_PARSE_ARGUMENTS(ARGS "" "" "SOURCE" ${ARGN})
27+
SET(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
28+
SET(out_files "")
2229

23-
string (REPLACE "\n" ";" files ${_files})
30+
FOREACH(src ${ARGS_SOURCE} ${ARGS_UNPARSED_ARGUMENTS})
31+
SET(in_file "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
32+
GET_FILENAME_COMPONENT(WORKING_DIR ${in_file} PATH)
33+
STRING(REPLACE ".xml" ".c" src ${src})
34+
SET(out_file "${DIRECTORY}/${src}")
35+
GET_FILENAME_COMPONENT(OUPUT_DIR ${out_file} PATH)
36+
FILE(MAKE_DIRECTORY ${OUPUT_DIR})
37+
LIST(APPEND out_files "${DIRECTORY}/${src}")
2438

25-
set (depends "")
26-
foreach (cur_file ${files})
27-
list (APPEND depends "${resource_dir}/${cur_file}")
28-
endforeach ()
39+
#FIXME implicit depends currently not working
40+
EXECUTE_PROCESS(
41+
COMMAND
42+
${GLIB_COMPILE_RESOURCES_EXECUTABLE}
43+
"--generate-dependencies"
44+
${in_file}
45+
WORKING_DIRECTORY ${WORKING_DIR}
46+
OUTPUT_VARIABLE in_file_dep
47+
)
48+
STRING(REGEX REPLACE "(\r?\n)" ";" in_file_dep "${in_file_dep}")
49+
SET(in_file_dep_path "")
50+
FOREACH(dep ${in_file_dep})
51+
LIST(APPEND in_file_dep_path "${WORKING_DIR}/${dep}")
52+
ENDFOREACH(dep ${in_file_dep})
53+
ADD_CUSTOM_COMMAND(
54+
OUTPUT ${out_file}
55+
WORKING_DIRECTORY ${WORKING_DIR}
56+
COMMAND
57+
${GLIB_COMPILE_RESOURCES_EXECUTABLE}
58+
ARGS
59+
"--generate-source"
60+
"--target=${out_file}"
61+
${in_file}
62+
DEPENDS
63+
${in_file};${in_file_dep_path}
64+
)
65+
ENDFOREACH(src ${ARGS_SOURCES} ${ARGS_UNPARSED_ARGUMENTS})
66+
SET(${output} ${out_files} PARENT_SCOPE)
67+
ENDFUNCTION(GLIB_COMPILE_RESOURCES)
2968

30-
# Command to compile the resources
31-
add_custom_command (
32-
OUTPUT ${output}
33-
DEPENDS "${resource_dir}/${resource_file}" ${depends}
34-
WORKING_DIRECTORY ${resource_dir}
35-
COMMAND ${gresources_executable} --generate-source --target=${output} ${resource_file}
36-
)
37-
endfunction ()

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ OPTIONS
5959
--vapidir=${CMAKE_SOURCE_DIR}/vapi
6060
)
6161

62-
include (GResource)
63-
glib_compile_resources (GLIB_RESOURCES_ICONS SOURCE ../data/icons/icons.gresource.xml)
62+
include (gresource)
63+
glib_compile_resources(GLIB_RESOURCES_ICONS SOURCE ../data/icons/icons.gresource.xml)
6464

6565

6666
add_executable(com.github.philip-scott.spice-up ${VALA_C} ${GLIB_RESOURCES_ICONS})

0 commit comments

Comments
 (0)