Skip to content

Commit 4e7c44f

Browse files
committed
GH-47565: [C++] Document how to use Arrow in Meson build system
1 parent eb6b637 commit 4e7c44f

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

docs/source/cpp/build_system.rst

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ The recommended way to integrate the Arrow C++ libraries in your own
3131
C++ project is to use CMake's `find_package
3232
<https://cmake.org/cmake/help/latest/command/find_package.html>`_
3333
function for locating and integrating dependencies. If you don't use
34-
CMake as a build system, you can use `pkg-config
34+
CMake as a build system, you can try the `Meson build system
35+
<https://mesonbuild.com/>`_ or use `pkg-config
3536
<https://www.freedesktop.org/wiki/Software/pkg-config/>`_ to find
3637
installed the Arrow C++ libraries.
3738

@@ -144,6 +145,85 @@ For example, to use the ``ArrowCompute`` package:
144145
.. seealso::
145146
A Docker-based :doc:`minimal build example <examples/cmake_minimal_build>`.
146147

148+
Meson
149+
=====
150+
151+
Basic usage
152+
-----------
153+
154+
This minimal ``meson.build`` file compiles a ``my_example.cc`` source file
155+
into an executable linked with the Arrow C++ shared library:
156+
157+
.. code-block:: meson
158+
159+
project('my-example-project', 'cpp')
160+
161+
arrow_dep = dependency('arrow')
162+
163+
executable(
164+
'my_example',
165+
sources: ['my_example.cc'],
166+
dependencies: [arrow_dep],
167+
)
168+
169+
To setup and compile, run the following commands from your project root:
170+
171+
.. code-block:: shell
172+
173+
meson setup builddir
174+
meson compile -C builddir
175+
176+
Using Meson's wrap system
177+
-------------------------
178+
179+
By default, a call to ``dependency('arrow')`` will search for Arrow
180+
on your system, using a variety of heuristics built into Meson (typically
181+
using pkg-config, but potentially also using CMake and other logic). If you
182+
are working on a system where Arrow is not available, you can use Meson's
183+
wrap system to automatically fetch a copy and build Arrow as a subproject.
184+
185+
To do so, run the following from the root of your project:
186+
187+
.. code-block:: shell
188+
189+
mkdir -p subprojects
190+
meson wrap install arrow-cpp
191+
meson wrap install gflags # can skip if you have a system install of gflags
192+
193+
No changes to your ``meson.build`` configuration are required.
194+
195+
Linking Against Optional Dependencies
196+
-------------------------------------
197+
198+
By default, the Arrow project builds and distributes a single core library.
199+
However, Arrow can build and distribute many optional libraries, which can
200+
still be linked via Meson.
201+
202+
As an example, let's look at the compute library, which is distributed via
203+
pkg-config as ``arrow-compute``. Meson will first search for this library
204+
on the system, and when it is not found it will fall back to building a
205+
local copy of Arrow. However, the local copy must be instructed to enable
206+
to compile the optional compute library.
207+
208+
To do this, we are going to modify the aforementioned configuration to
209+
add a ``default_options`` argument to the ``dependency`` call, which instructs
210+
Meson to build the compute library while compiling a local copy of Arrow:
211+
212+
.. code-block:: meson
213+
214+
project('my-example-project', 'cpp')
215+
216+
arrow_compute_dep = dependency(
217+
'arrow-compute',
218+
default_options: ['compute=enabled'],
219+
)
220+
221+
executable(
222+
'my_example',
223+
sources: ['my_example.cc'],
224+
dependencies: [arrow_compute_dep],
225+
)
226+
147227
pkg-config
148228
==========
149229

0 commit comments

Comments
 (0)