Meson安装

Meson出现的原因:

  C++需要一个仓库管理系统,用于管理依赖包。类似于Java里的Maven。Maven可以做什么呢?Maven是Java的项目构建工具+仓库管理工具。

  由此需求下,CargoMeson应运而生。它们相比之前的CMake来说,自然要更加的有用。它不仅仅支持C/C++,还支持多种语言。如今,很多项目都由CMake转向到了Meson,例如DPDK和Mapnik。

收录时间2013-11-26

开发语言:Python

开发单位:Apache基金会

Meson使用:https://my.oschina.net/u/4349408/blog/3295014

ninja:一个简单的构建方式:https://my.oschina.net/u/4292686/blog/4708023

从CMake转Meson:https://www.bilibili.com/video/BV1D5411H7F5

Meson跨平台吗?https://www.ctolib.com/meson.html 

Meson® is a project to create the best possible next-generation build system.

扫描二维码关注公众号,回复: 12587660 查看本文章

Status:

Dependencies

  • Python (version 3.5 or newer)
  • Ninja (version 1.7 or newer)

Installing from source

Meson is available on PyPi, so it can be installed with pip3 install meson. The exact command to type to install with pip can vary between systems, be sure to use the Python 3 version of pip.

If you wish you can install it locally with the standard Python command:

python3 -m pip install meson

For builds using Ninja, Ninja can be downloaded directly from Ninja GitHub release page or via PyPi

python3 -m pip install ninja

More on Installing Meson build can be found at the getting meson page.

Running

Meson requires that you have a source directory and a build directory and that these two are different. In your source root must exist a file called meson.build. To generate the build system run this command:

meson setup <source directory> <build directory>

Depending on how you obtained Meson the command might also be called meson.py instead of plain meson. In the rest of this document we are going to use the latter form.

You can omit either of the two directories, and Meson will substitute the current directory and autodetect what you mean. This allows you to do things like this:

cd <source root>
meson setup builddir

To compile, cd into your build directory and type ninja. To run unit tests, type ninja test.

More on running Meson build system commands can be found at the running meson page or by typing meson --help.

Contributing

We love code contributions. See the contribution page on the website for details.

IRC

The irc channel for Meson is #mesonbuild over at Freenode.

You can use FreeNode's official webchat to connect to this channel.

Further info

More information about the Meson build system can be found at the project's home page.

Meson is a registered trademark of Jussi Pakkanen.

GitHub:https://github.com/mesonbuild/meson

官网:https://mesonbuild.com/

The Absolute Beginner's Guide to Installing and Using Meson

This page is meant for people who are new to using Meson and possibly even to compiling C and/or C++ code in general. It is meant to contain one simple way of getting your build environment up and running. If you are more experienced and have your own preferred way of installing and using development software, feel free to use that instead. This guide only deals with Linux, Windows and macOS platforms. If you use some other platform, such as one of the BSDs, you probably already know how to install development tools on it (probably better than we do, even).

There are three phases to getting a development environment running.

  1. Installing a compiler toolchain
  2. Installing Meson
  3. Creating a project and building it

1. Installing a compiler toolchain安装编译器工具链

Linux

All Linux distributions provide easy access to development tools. Typically you need to open a terminal and execute one command, which depends on your distro.

  • Debian, Ubuntu and derivatives: sudo apt install build-essential
  • Fedora, Centos, RHEL and derivatives: sudo dnf install gcc-c++
  • Arch: sudo pacman -S gcc

Windows

The most common development toolchain on Windows is Visual Studio, which can be downloaded from the Visual Studio web site. Select the Community version unless you have bought a license.

Download page of Visual Studio

Download the installer and run it. When you are given a list of things to install, select Desktop development with C++. This installs both a C and a C++ compiler.

Installing the Visual Studio compilers

Once the installer finishes the compiler toolchain is ready to use.

macOS

On macOS the development toolchain must be installed via the Mac app store. Search for an app called XCode and install it.

App store page for XCode

Note: Installing XCode is not sufficient by itself. You also need to start XCode' GUI application once. This will make XCode download and install more files that are needed for compilation.

2. Installing Meson

Linux

Installing Meson is just as simple as installing the compiler toolchain.

  • Debian, Ubuntu and derivatives: sudo apt install meson ninja-build
  • Fedora, Centos, RHEL and derivatives: sudo dnf install meson ninja-build
  • Arch: sudo pacman -S meson

Windows

Meson provides a standard Windows .msi installer that can be downloaded from the Releases page.

Meson installed download

Download and run it to install all the necessary bits. You can verify that your installation is working by running the Visual Studio developer tools command prompt that can be found in the start menu.

Devtool prompt

You should be able to run both meson and ninja and query their versions.

A working Windows install

macOS

Due to the way Apple has set things up, getting macOS working is a bit more complicated. The first thing you need to do is to install the newest version of Python 3 from the project's web site.

Downloading the Python for macOS installer

Once you have a working Python you can install the necessary bits using Python's Pip package manager.

pip install --user meson ninja

This will install the necessary files in your home directory, but sadly they are not directly usable. You need to add the directory they are written to in the system's PATH environment variable so the programs can be used directly from the terminal. This requires editing a text configuration file.

The correct file to edit depends on which shell you are currently using. If you have an old macOS install it is probably Bash and the file you need to edit is .bash_profile. If, on the other hand, you have a new macOS install then you are probably using Zsh and the file to edit is .zshrc. In either case the file should be in your home directory.

For Bash the line you need to add is this:

PATH=$PATH:/Users/username/Library/Python/3.9/bin

whereas for Zsh it is this:

export PATH=$PATH:/Users/username/Library/Python/3.9/bin

In both case you need to change the values for username and 3.9. The former needs to be substituted with your Unix username while the latter needs to contain the actual Python version you installed.

Once this is done close the terminal application and start it again. Now you should be able to run the meson command.

A working macOS install

3. Running Meson

Start a terminal application. On Windows you have to use the Visual Studio Developer Tools Command Prompt as discussed above, because the compilers are only available in that terminal. You also need to change into your home directory (Linux and macOS terminals start in the home directory by default).

cd \users\username

Create a new directory to hold your project.

mkdir testproject
cd testproject

Use Meson to create and build a new sample project.

meson init --name testproject --build

This will create a project skeleton for you and compile it. The result is put in the build subdirectory and can be run directly from there.

build/testproject

All finished and ready to go

The project is now ready for development. You can edit the code with any editor and it is rebuilt by going in the build subdirectory and executing the meson compile command. If your version of Meson is too old, you can compile the project by running the command ninja instead.

https://mesonbuild.com/SimpleStart.html

猜你喜欢

转载自blog.csdn.net/nmj2008/article/details/114234797