Using resources instead of .ui files.

This commit is contained in:
Pcornat 2026-03-18 19:39:25 +01:00
commit a84cace7b6
Signed by: Pcornat
GPG key ID: E0326CC678A00BDD
3 changed files with 40 additions and 3 deletions

View file

@ -1,10 +1,12 @@
cmake_minimum_required(VERSION 3.30)
project(BillyGui LANGUAGES CXX)
project(BillyGui LANGUAGES C CXX)
include(FetchContent)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTKMM4 REQUIRED IMPORTED_TARGET gtkmm-4.0)
find_program(GLIB_COMPILE_RESOURCES NAMES glib-compile-resources REQUIRED)
fetchcontent_declare(BillySheet
GIT_REPOSITORY https://gitea.pcornatcloud.fr/Pcornat/BillySheet.git
GIT_TAG main
@ -73,13 +75,41 @@ set(SPDLOG_NO_TLS ON)
set(SPDLOG_NO_ATOMIC_LEVELS ON)
fetchcontent_makeavailable(spdlog)
set(GRESOURCE_C resources.c)
set(GRESOURCE_XML billy_gui.gresource.xml)
# Step 2:
add_custom_command(
OUTPUT ${GRESOURCE_C}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${GLIB_COMPILE_RESOURCES}
ARGS
--target=${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C} ${GRESOURCE_XML} --generate-source
VERBATIM
MAIN_DEPENDENCY ${GRESOURCE_XML}
DEPENDS window_ui.ui menu_bar.ui
)
# Step 3:
add_custom_target(
dummy-resource
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C}
)
add_executable(${PROJECT_NAME} main.cpp
hello_world.cpp
hello_world.hpp
app_win_2_back.cpp
app_win_2_back.hpp
${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C}
)
set_source_files_properties(
${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C}
PROPERTIES GENERATED TRUE
)
add_dependencies(${PROJECT_NAME} dummy-resource)
set_target_properties(${PROJECT_NAME} spdlog_header_only PROPERTIES
CXX_STANDARD 23
CXX_STANDARD_REQUIRED ON

View file

@ -25,7 +25,7 @@ namespace gui_to_app {
Application::on_startup();
const auto menu_bar = [this]() -> Glib::RefPtr<Gio::Menu> {
try {
menu_builder = Gtk::Builder::create_from_file("menu_bar.ui");
menu_builder = Gtk::Builder::create_from_resource("/org/gtkmm/billy_gui/menu_bar.ui");
if (menu_builder != nullptr) {
return menu_builder->get_object<Gio::Menu>("menu");
} else {
@ -150,7 +150,7 @@ namespace gui_to_app {
window_builder = [] -> Glib::RefPtr<Gtk::Builder> {
try {
return Gtk::Builder::create_from_file("window_ui.ui");
return Gtk::Builder::create_from_resource("/org/gtkmm/billy_gui/window_ui.ui");
} catch (const std::exception &e) {
spdlog::critical("Error occurred while loading Window's UI: {}", e.what());
return nullptr;

7
billy_gui.gresource.xml Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gtkmm/billy_gui">
<file preprocess="xml-stripblanks">window_ui.ui</file>
<file preprocess="xml-stripblanks">menu_bar.ui</file>
</gresource>
</gresources>