Using resources instead of .ui files.
This commit is contained in:
parent
0b38380437
commit
a84cace7b6
3 changed files with 40 additions and 3 deletions
|
|
@ -1,10 +1,12 @@
|
||||||
cmake_minimum_required(VERSION 3.30)
|
cmake_minimum_required(VERSION 3.30)
|
||||||
project(BillyGui LANGUAGES CXX)
|
project(BillyGui LANGUAGES C CXX)
|
||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(GTKMM4 REQUIRED IMPORTED_TARGET gtkmm-4.0)
|
pkg_check_modules(GTKMM4 REQUIRED IMPORTED_TARGET gtkmm-4.0)
|
||||||
|
|
||||||
|
find_program(GLIB_COMPILE_RESOURCES NAMES glib-compile-resources REQUIRED)
|
||||||
|
|
||||||
fetchcontent_declare(BillySheet
|
fetchcontent_declare(BillySheet
|
||||||
GIT_REPOSITORY https://gitea.pcornatcloud.fr/Pcornat/BillySheet.git
|
GIT_REPOSITORY https://gitea.pcornatcloud.fr/Pcornat/BillySheet.git
|
||||||
GIT_TAG main
|
GIT_TAG main
|
||||||
|
|
@ -73,13 +75,41 @@ set(SPDLOG_NO_TLS ON)
|
||||||
set(SPDLOG_NO_ATOMIC_LEVELS ON)
|
set(SPDLOG_NO_ATOMIC_LEVELS ON)
|
||||||
fetchcontent_makeavailable(spdlog)
|
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
|
add_executable(${PROJECT_NAME} main.cpp
|
||||||
hello_world.cpp
|
hello_world.cpp
|
||||||
hello_world.hpp
|
hello_world.hpp
|
||||||
app_win_2_back.cpp
|
app_win_2_back.cpp
|
||||||
app_win_2_back.hpp
|
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
|
set_target_properties(${PROJECT_NAME} spdlog_header_only PROPERTIES
|
||||||
CXX_STANDARD 23
|
CXX_STANDARD 23
|
||||||
CXX_STANDARD_REQUIRED ON
|
CXX_STANDARD_REQUIRED ON
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace gui_to_app {
|
||||||
Application::on_startup();
|
Application::on_startup();
|
||||||
const auto menu_bar = [this]() -> Glib::RefPtr<Gio::Menu> {
|
const auto menu_bar = [this]() -> Glib::RefPtr<Gio::Menu> {
|
||||||
try {
|
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) {
|
if (menu_builder != nullptr) {
|
||||||
return menu_builder->get_object<Gio::Menu>("menu");
|
return menu_builder->get_object<Gio::Menu>("menu");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -150,7 +150,7 @@ namespace gui_to_app {
|
||||||
|
|
||||||
window_builder = [] -> Glib::RefPtr<Gtk::Builder> {
|
window_builder = [] -> Glib::RefPtr<Gtk::Builder> {
|
||||||
try {
|
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) {
|
} catch (const std::exception &e) {
|
||||||
spdlog::critical("Error occurred while loading Window's UI: {}", e.what());
|
spdlog::critical("Error occurred while loading Window's UI: {}", e.what());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
||||||
7
billy_gui.gresource.xml
Normal file
7
billy_gui.gresource.xml
Normal 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>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue