Skip to content

Commit eae3117

Browse files
committed
GH-46215: [C++][Docs] Add README for Meson subprojects directory
1 parent cdc3e5a commit eae3117

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

cpp/subprojects/README.md

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<!---
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# Meson Subprojects
21+
22+
The contents of this directory are exclusively used by the Meson build configuration to
23+
manage project dependencies. The Meson documentation for this functionality can be found
24+
at https://mesonbuild.com/Subprojects.html
25+
26+
To summarize, Arrow relies upon other projects to successfully compile and link. In
27+
the case that those dependencies cannot be found on the host system, Meson by convention
28+
forces users to place those dependencies in the `subprojects` directory at the root
29+
of the project.
30+
31+
The easiest way to populate subprojects is to use Meson's
32+
[WrapDB system](https://mesonbuild.com/Wrapdb-projects.html). To illustrate how this
33+
works, let's take a look at the `googletest` library that Arrow depends upon for
34+
its test system. To create that as a subproject, a developer once ran:
35+
36+
```bash
37+
meson wrap install gtest
38+
```
39+
40+
From the project root directory. From that invocation, Meson creates the
41+
`subprojects/gtest.wrap` file which instructs the build system where it can
42+
get the source for gtest (if required), optionally alongside any "patch files"
43+
required to build gtest. If a project uses Meson natively, there is no need for
44+
patch files. However, if the project uses another build system (in the case of gtest
45+
, Bazel or CMake), then the patch files are user-created Meson configuration files
46+
that still expose the required build targets, without being a full rewrite of the
47+
native build generator. For an example of a user-created patch file for googletest,
48+
check out
49+
https://github.com/mesonbuild/wrapdb/tree/9e3862083a250680061aa46e8746499c419ad43c/subprojects/packagefiles/gtest
50+
51+
If you depend upon a project that is not available in Meson's WrapDB system,
52+
you may still be able to have Meson auto-generate a wrapper for it. An example
53+
of this is the `subprojects/azure.wrap`, which looks like:
54+
55+
```
56+
[wrap-file]
57+
source_url = https://github.com/Azure/azure-sdk-for-cpp/archive/azure-identity_1.9.0.tar.gz
58+
source_filename = azure-sdk-for-cpp-azure-identity_1.9.0.tar.gz
59+
source_hash = 97065bfc971ac8df450853ce805f820f52b59457bd7556510186a1569502e4a1
60+
directory = azure-sdk-for-cpp-azure-identity_1.9.0
61+
method = cmake
62+
```
63+
64+
The `method = cmake` line is important here; it instructs Meson to inspect any
65+
CMakeLists.txt files from the downloaded source and auto generate Meson configuration
66+
files therefrom. The generated meson.build configuration(s) will be placed in
67+
`<build_directory>/subprojects/<subproject_name>` at project configuration time.
68+
69+
In the default case, Meson will use the wrap file as a fallback. If a dependency
70+
can be satisfied by the system, then it will not use the wrap file to download
71+
any sources. However, you can toggle the behavior of the wrap system via the
72+
`--wrap-mode=` configuration option. `--wrap-mode=forcefallback` will always
73+
download and use the source defined in a wrap file, even if the depdendency could
74+
be satisfied by the system. By contrast, `--wrap-mode=nofallback` will require
75+
that the system satisfies dependencies. For more ways to handle wrap dependencies,
76+
see https://mesonbuild.com/Subprojects.html#commandline-options
77+
78+
For more information on Meson's wrap system, see also
79+
https://mesonbuild.com/Wrap-dependency-system-manual.html
80+
81+
In the majority of cases you will be using wrap files to describe subprojects, although
82+
it is not always required. You could alternatively place a copy of the third party
83+
project into the subprojects directory, if your preference is to completely vendor it.

0 commit comments

Comments
 (0)