The next thing we need is a build system. The build system that we're going to be using is called Meson. We already installed the
meson program at the beginning of this book when we installed
elementary-sdk. What we're going to do in this step is create the files that tell Meson how to install your program. This includes all the rules for building your source code as well as correctly installing your .desktop and appdata files and the binary app that results from the build process.
Create a new file in your project's root folder called "meson.build". We've included some comments along the way to explain what each section does. You don't have to copy those, but type the rest into that file:
# project name and programming languageproject('com.github.yourusername.yourrepositoryname', 'vala', 'c')# Create a new executable, list the files we want to compile, list the dependencies we need, and installexecutable(meson.project_name(),'src/Application.vala',dependencies: [dependency('gtk+-3.0')],install: true)# Install our .desktop file so the Applications Menu will see itinstall_data(join_paths('data', 'hello-again.desktop'),install_dir: join_paths(get_option('datadir'), 'applications'),rename: meson.project_name() + '.desktop')# Install our .appdata.xml file so AppCenter will see itinstall_data(join_paths('data', 'hello-again.appdata.xml'),install_dir: join_paths(get_option('datadir'), 'metainfo'),rename: meson.project_name() + '.appdata.xml')
Notice that in each of our
install_data methods, we rename our files using our project name. By using our project name—and its RDNN scheme—we will ensure that our files are installed under a unique name that won't cause conflicts with other apps.
And you're done! Your app now has a real build system. This is a major milestone in your app's development!
Now that we have a build system, let's try it out. Configure the build directory using the Meson command in Terminal:
meson build --prefix=/usr
This command tells Meson to get ready to build our app using the prefix "/usr" and that we want to build our app in a clean directory called "build". The
meson command defaults to installing our app locally, but we want to install our app for all users on the computer.
Change into the build directory and use
ninja to build. Then, if the build is successful, install with
cd buildninjaninja install
If all went well, you should now be able to open your app from the Applications Menu and pin it to the Dock. We'll revisit Meson again later to add some more complicated behavior, but for now this is all you need to know to give your app a proper build system. If you want to explore Meson a little more on your own, you can always check out Meson's documentation.
Let's review all we've learned to do:
Create a new Gtk app using
Keep our projects organized into branches
License our app under the GPL and declare our app's authors in a standardized manner
Create a .desktop file using RDNN that tells the computer how to display our app in the Applications Menu and the Dock
Set up a Meson build system that contains all the rules for building our app and installing it cleanly
That's a lot! You're well on your way to becoming a bonified app developer for elementary OS. Give yourself a pat on the back, then take some time to play around with this example. Change the names of files and see if you can still build and install them properly. Ask another developer to clone your repo from GitHub and see if it builds and installs cleanly on their computer. If so, you've just distributed your first app! When you're ready, we'll move onto the next section: Translations.