move glade files into resources inside the binary

This commit is contained in:
Mario Hüttel 2018-05-18 18:47:19 +02:00
parent f42a4c40fb
commit 302a0d1da7
5 changed files with 37 additions and 13 deletions

View File

@ -1,4 +1,16 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
find_package(PkgConfig REQUIRED)
pkg_search_module(GLIB REQUIRED glib-2.0)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
project(gds-render)
add_subdirectory(glade)
include_directories(${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS} "layer-widget")
link_directories(${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS})
add_definitions(${GLIB2_CFLAGS_OTHER})
aux_source_directory("layer-widget" SUB_SOURCES) aux_source_directory("layer-widget" SUB_SOURCES)
set(SOURCE "main.c" "gdsparse.c" "layer-selector.c") set(SOURCE "main.c" "gdsparse.c" "layer-selector.c")
@ -9,16 +21,9 @@ set(SOURCE
${SUB_SOURCES} ${SUB_SOURCES}
) )
find_package(PkgConfig REQUIRED)
pkg_search_module(GLIB REQUIRED glib-2.0)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
include_directories(${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS} "layer-widget")
link_directories(${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS})
configure_file(glade/main.glade glade/main.glade COPYONLY)
configure_file(glade/layer-widget.glade glade/layer-widget.glade COPYONLY)
project(gds-render)
add_executable(${PROJECT_NAME} ${SOURCE})
add_executable(${PROJECT_NAME} ${SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/glade/resources.c)
add_dependencies(${PROJECT_NAME} glib-resources)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/glade/resources.c PROPERTIES GENERATED 1)
target_link_libraries(${PROJECT_NAME} ${GLIB_LDFLAGS} ${GTK3_LDFLAGS} m) target_link_libraries(${PROJECT_NAME} ${GLIB_LDFLAGS} ${GTK3_LDFLAGS} m)

10
glade/CMakeLists.txt Normal file
View File

@ -0,0 +1,10 @@
add_custom_target(glib-resources DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/resources.c)
add_custom_command(DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/resources.xml
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/resources.c
COMMAND
echo "$(pwd)"
COMMAND
glib-compile-resources --target="${CMAKE_CURRENT_BINARY_DIR}/resources.c" --sourcedir="${CMAKE_CURRENT_SOURCE_DIR}" --generate-source "${CMAKE_CURRENT_SOURCE_DIR}/resources.xml"
)

9
glade/resources.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource>
<file compressed="true">main.glade</file>
<file>layer-widget.glade</file>
</gresource>
</gresources>

View File

@ -39,7 +39,7 @@ static void layer_element_init(LayerElement *self)
{ {
GtkBuilder *builder; GtkBuilder *builder;
GtkWidget *glade_box; GtkWidget *glade_box;
builder = gtk_builder_new_from_file("glade/layer-widget.glade"); builder = gtk_builder_new_from_resource("/layer-widget.glade");
glade_box = GTK_WIDGET(gtk_builder_get_object(builder, "box")); glade_box = GTK_WIDGET(gtk_builder_get_object(builder, "box"));
gtk_box_pack_start(GTK_BOX(self), glade_box, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(self), glade_box, TRUE, TRUE, 0);

2
main.c
View File

@ -156,7 +156,7 @@ int main(int argc, char **argv)
gtk_init(&argc, &argv); gtk_init(&argc, &argv);
main_builder = gtk_builder_new_from_file("glade/main.glade"); main_builder = gtk_builder_new_from_resource("/main.glade");
gtk_builder_connect_signals(main_builder, NULL); gtk_builder_connect_signals(main_builder, NULL);