commit dfe1880c0871c21b1c1096dc705400eb2af9c843 Author: Pcornat Date: Thu Oct 24 11:02:04 2024 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d2220e1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +cmake-* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a1d25c3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 3.30) +project(LearnGtk4 LANGUAGES CXX) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTKMM4 REQUIRED IMPORTED_TARGET gtkmm-4.0) + +find_program(CCACHE_FOUND ccache) +if (CCACHE_FOUND) + message(STATUS "ccache found !") + set_property(GLOBAL PROPERTY C_COMPILER_LAUNCHER ccache) + set_property(GLOBAL PROPERTY C_LINKER_LAUNCHER ccache) + set_property(GLOBAL PROPERTY CXX_COMPILER_LAUNCHER ccache) + set_property(GLOBAL PROPERTY CXX_LINKER_LAUNCHER ccache) +else () + message(STATUS "ccache not found") +endif () + +set(COMPILE_FLAGS + -pipe + -march=znver3 # change to native or your architecture. + -mtune=znver3 # same as above + -mrdseed # be careful about this, this is linked to the x86 architecture. + -mrdrnd # same as above + -Wall + -Wextra + -Wpedantic + -pedantic + $<$:-ffunction-sections -fdata-sections> + -fuse-ld=gold + -funroll-loops + -fdevirtualize-at-ltrans +) +set(LINKER_OPTIONS + -Wl,--sort-common,--as-needed$<$:,--gc-sections,--strip-all> + -fuse-ld=gold + -fdevirtualize-at-ltrans +) + +option(ENABLE_COVERAGE "Enabling coverage" OFF) + +if (${ENABLE_COVERAGE}) + message(STATUS "Coverage enabled") + list(APPEND COMPILE_FLAGS --coverage) + list(APPEND LINKER_OPTIONS --coverage) + list(APPEND LINKER_FLAGS gcov) +endif () + +add_executable(LearnGtk4 main.cpp + hello_world.cpp + hello_world.hpp) + +set_target_properties(LearnGtk4 PROPERTIES + CXX_STANDARD 20 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + INTERPROCEDURAL_OPTIMIZATION ON + UNITY_BUILD ON +) + +target_compile_definitions(LearnGtk4 PUBLIC $<$:_GLIBCXX_DEBUG>) +target_compile_options(LearnGtk4 PUBLIC ${COMPILE_OPTIONS}) +target_link_options(LearnGtk4 PUBLIC ${LINKER_OPTIONS}) +target_link_libraries(LearnGtk4 PkgConfig::GTKMM4) diff --git a/hello_world.cpp b/hello_world.cpp new file mode 100644 index 0000000..076b03b --- /dev/null +++ b/hello_world.cpp @@ -0,0 +1,23 @@ +// +// Created by postaron on 27/09/24. +// + +#include "hello_world.hpp" +#include + +namespace learn_gtkmm4 { + HelloWorld::HelloWorld() : m_button("Hello world!") { + set_title("Hello world!"); + set_default_size(720, 1280); + add_action("Open"); + add_action("Quit"); + set_show_menubar(); + m_button.set_margin(10); + m_button.signal_clicked().connect(sigc::mem_fun(*this, &HelloWorld::on_button_clicked)); + set_child(m_button); + } + + void HelloWorld::on_button_clicked() { + std::cout << "Hello World" << std::endl; + } +} // learn_gtkmm4 \ No newline at end of file diff --git a/hello_world.hpp b/hello_world.hpp new file mode 100644 index 0000000..30b01ad --- /dev/null +++ b/hello_world.hpp @@ -0,0 +1,30 @@ +// +// Created by postaron on 27/09/24. +// + +#ifndef LEARNGTK4_HELLO_WORLD_HPP +#define LEARNGTK4_HELLO_WORLD_HPP + +#include +#include +#include +#include + +namespace learn_gtkmm4 { + + class HelloWorld : public Gtk::ApplicationWindow { + public: + HelloWorld(); + ~HelloWorld() override = default; + + protected: + void on_button_clicked(); + + Gtk::Box m_VBox; + Gtk::Button m_button; + Gtk::GLArea gl_area; + }; + +} // learn_gtkmm4 + +#endif //LEARNGTK4_HELLO_WORLD_HPP diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..db02ca1 --- /dev/null +++ b/main.cpp @@ -0,0 +1,7 @@ +#include "hello_world.hpp" +#include + +int main(int argc, char *argv[]) { + auto app = Gtk::Application::create("org.gtkmm.example"); + return app->make_window_and_run(argc, argv); +}