LoginSignup
6
3

More than 1 year has passed since last update.

cmake から meson へのビルドシステム移行のメモ

Last updated at Posted at 2019-07-06

cmake の次と名高い meson https://mesonbuild.com/ へビルドシステムを移行するメモです.

前提条件

  • cmake に精通している

meson の特徴

python で拡張ができる(cmake スクリプトに悩まずに済む!)

Ubuntu などでは apt で入ります.

Windows では meson, ninja と libpython も含んだパッケージが用意されていますので, 既存 python 環境と切り分けてスタンドアローンで meson を動作させる環境を構築することができます.

設定例

だいたいは https://mesonbuild.com/ を見ればわかりそうですが, single page ではないので機能確認がやりづらいですね.

How do I do X in Meson?
https://mesonbuild.com/howtox.html

Address sanitizer を使いたい.

meson では標準で対応しています.

meson build -Db_sanitize=address

などとします. 環境によっては -Db_lundef=false も設定するとより確実かもしれません(Ubuntu では b_lundef を false にしないと warning が出ました)

C/C++ コンパイラを指定したい.

CXX=clang++-8 meson build

という風にして CXX でコンパイラを指定して bootstrap します.

meson.build を変えたので再構築したい

一応 ninja で変更があったら再構築してくれますが,

meson --reconfigure build

でもいけます.

C++ のバージョンを指定したい.

project('myproj', 'c', 'cpp',
        default_options : ['c_std=c11', 'cpp_std=c++11'])

CMake では set(CMAKE_CXX_STANDARD 11) とかで指定でした.

ninja ではなく make を使いたい.

T.B.D.

コンパイラごとに CXX flag を変えたい

if meson.get_compiler('c').get_id() == 'clang'
  extra_args = ['-fclang-flag']
else
  extra_args = []
endif

executable(..., c_args : extra_args)

meson.get_compiler('c').get_id() で判断します.

ファイルごとに cxxflags 設定を変えたい

T.B.W.

cmake でいう set_source_files_properties.

クロスコンパイルしたい

T.B.W.

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3