====== Un script bash che crea lo scheletro di un'applicazione gtkmm con meson======
Autore: **//Fabio Di Matteo//** \\ Ultima revisione: **// 26/04/2023 - 13:00 //** // //
Avviare lo script come segue:
./auto-gtkmm
viene creato lo scheletro dell'applicazione.
meson setup build
viene configurato il progetto nella cartella "build"
cd build
ninja
viene compilato il progetto
**auto-gtkmm**
#!/bin/bash
AUTHOR="Fabio Di Matteo"
VERSION="0.1.1"
#Controllo se e' stato fornito il nome del progetto
if [ "$1" = "" ];then
echo "E' necessario fornire il nome del progetto come parametro."
exit 1 ;
fi
#Se la directory del progetto esiste gia' esco.
mkdir $1 2>/dev/null
if [ "$?" != 0 ];then
echo "Il progetto esiste."
exit 1 ;
fi
cd $1
echo "Make resorces folder..."
mkdir res
echo "Make main.cc..."
echo "
#include
#include \"mainwindow.hpp\"
int main(int argc, char *argv[])
{
auto app = Gtk::Application::create(argc, argv, \"org.gtkmm.example\");
mainWindow mainw;
return app->run(*mainw.window1);
}
" > main.cc ;
echo "Make mainwindow.hpp..."
echo "
#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP
#include
class mainWindow
{
public:
Glib::RefPtr builder;
Gtk::Window *window1;
Gtk::Button *button1;
Gtk::Label *label1;
mainWindow();
protected:
void on_button_clicked();
private:
/* add your private declarations */
};
#endif /* MAINWINDOW_HPP */
" > mainwindow.hpp ;
echo "Make mainwindow.cpp..."
echo "
#include \"mainwindow.hpp\"
#include
mainWindow::mainWindow()
{
auto builder = Gtk::Builder::create();
try
{
builder->add_from_resource(\"/app/res/gui.ui\");
}
catch(const Glib::FileError& ex)
{
std::cerr << \"FileError: \" << ex.what() << std::endl;
}
catch(const Glib::MarkupError& ex)
{
std::cerr << \"MarkupError: \" << ex.what() << std::endl;
}
catch(const Gtk::BuilderError& ex)
{
std::cerr << \"BuilderError: \" << ex.what() << std::endl;
}
builder->get_widget(\"window1\", window1);
builder->get_widget(\"button1\", button1);
builder->get_widget(\"label1\", label1);
button1->signal_clicked().connect( sigc::mem_fun(*this, &mainWindow::on_button_clicked) );
}
void mainWindow::on_button_clicked()
{
static int c;
c++;
label1->set_text(\"You have clicked \"+std::to_string(c)+\" times!\");
}
" > mainwindow.cpp ;
echo "Make meson.build"
echo "
project('GTKmm', 'cpp')
gtkmm = dependency('gtkmm-3.0')
gnome = import('gnome')
myresources = gnome.compile_resources(
'my-resources', 'res/resources.xml',
source_dir: 'res',
c_name: 'myresources'
)
os=build_machine.system()
if os == 'linux'
executable('simple-meson', 'main.cc',myresources,'mainwindow.cpp', dependencies : gtkmm)
endif
if os == 'windows'
executable('simple-meson', 'main.cc',myresources,'mainwindow.cpp', dependencies : gtkmm, link_args : ['-mwindows'])
endif
" > meson.build;
echo "Make resources"
echo "
gui.ui
" > res/resources.xml;
echo "
" > res/gui.ui ;
echo "#!/bin/bash
cd res
echo 'Building resources.c ...'
glib-compile-resources --generate-source resources.xml
mv resources.c ../resources.cpp
" > compile_resources.sh;
chmod +x compile_resources.sh