Building dependencies as Meson subprojects














































Building dependencies as Meson subprojects



Building dependencies as Meson subprojects

Almost no application is fully self-contained, rather everyone uses external libraries and frameworks. Meson makes it very easy to find and use external dependencies.

Here is how one would use the zlib compression library.

dep = dependency('zlib', version : '>=1.2.8') exe = executable('zlibprog', 'prog.cpp', dependencies : dep)

In the above code first Meson is told to find the external library zlib and error out if it is not found. The version keyword is optional and specifies a version requirement for the dependency. Then an executable is built using the specified dependency.

If we have multiple dependencies we can pass them as an array like this

executable('manydeps', 'file.cpp', dependencies : [dep1, dep2, dep3, dep4])

Now we will create a Meson subproject, for this we will use SDL as an example.

All subprojects must be inside the %u2018subprojects%u2019 directory. The subprojects directory must be at the top level of the project. Subproject declaration must be in the top level %u2018meson.build%u2019.

The %u2018meson.build%u2019 file for creating the subproject will look like this

project('SDL test', 'cpp', version: '1.0.0', default_options : ['default_library=static', 'cpp_std=c++17', 'buildtype=debugoptimized']) sdl2_dep = dependency('sdl2') sdl2_image_dep = dependency('sdl2_image') sdl2_mixer_dep = dependency('sdl2_mixer') executable('sdltestapp', 'main.cpp', dependencies : [sdl2_image_dep, sdl2_mixer_dep, sdl2_dep], win_subsystem: 'windows')

The contents of the .wrap files created consist mostly of download links, hashes and build meta info.


More Articles of Aniket Sharma:

Name Views Likes
Pyperclip: Installation and Working 990 2
Number Guessing Game using Python 683 2
Pyperclip: Not Implemented Error 1026 2
Hangman Game using Python 16785 2
Using Databases with CherryPy application 1672 2
nose: Working 506 2
pytest: Working 510 2
Open Source and Hacktoberfest 867 2
Managing Logs of CherryPy applications 1001 2
Top 20 Data Science Tools 684 2
Ajax application using CherryPy 798 2
REST application using CherryPy 663 2
On Screen Keyboard using Python 5508 2
Elastic Net Regression 815 2
US Presidential Election 2020 Prediction using Python 794 2
Sound Source Separation 1164 2
URLs with Parameters in CherryPy 1632 2
Testing CherryPy application 635 2
Handling HTML Forms with CherryPy 1448 2
Applications of Natural Language Processing in Businesses 508 2
NetworkX: Multigraphs 648 2
Tracking User Activity with CherryPy 1396 2
CherryPy: Handling Cookies 820 2
Introduction to NetworkX 633 2
TorchServe - Serving PyTorch Models 1301 2
Fake News Detection Model using Python 734 2
Keeping Home Routers secure while working remotely 483 2
Email Slicer using Python 2996 2
NetworkX: Creating a Graph 1108 2
Best Mathematics Courses for Machine Learning 551 2
Hello World in CherryPy 680 2
Building dependencies as Meson subprojects 978 2
Vehicle Detection System 1081 2
NetworkX: Examining and Removing Graph Elements 607 2
Handling URLs with CherryPy 536 2
PEP 8 - Guide to Beautiful Python Code 757 2
NetworkX: Drawing Graphs 623 2
Mad Libs Game using Python 643 2
Hosting Cherry applications 612 2
Top 5 Free Online IDEs of 2020 866 2
pytest: Introduction 534 2
Preventing Pwned and Reused Passwords 581 2
Contact Book using Python 2095 2
Introduction to CherryPy 546 2
nose: Introduction 505 2
Text-based Adventure Game using Python 3000 2
NetworkX: Adding Attributes 2278 2
NetworkX: Directed Graphs 1021 2
Dice Simulator using Python 560 2
Decorating CherryPy applications using CSS 833 2

Comments