# Download Meson and Mesa to local repo and build

**URL:** https://discourse.cmake.org/t/download-meson-and-mesa-to-local-repo-and-build/9674
**Category:** Code
**Tags:** os:linux, gen:ninja
**Created:** [December 18, 2023, 9:48pm UTC](https://discourse.cmake.org/t/download-meson-and-mesa-to-local-repo-and-build/9674 "2023-12-18T21:48:04Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![john](https://discourse.cmake.org/user_avatar/discourse.cmake.org/john/32/4097_2.png) [@john](https://discourse.cmake.org/u/john)
#### Post date: [December 18, 2023, 9:48pm UTC](https://discourse.cmake.org/t/download-meson-and-mesa-to-local-repo-and-build/9674/1 "2023-12-18T21:48:05Z")

</div>

Good afternoon,

I am trying to create a repository that will build and install `Mesa 3D` in a local directory. I have read that `Mesa 3D` needs to be configured using `Meson` but I would like _both_ of these downloaded and built in the local directory of my repository. I am using `CMake 3.22` and `ninja` instead of `make`.

I think the way to accomplish this would be to use `CPMAddPackage` or `ExternalProject_Add` (I am not picky) ?

I have been going around with this for a few days and am hoping one of you **CMake** experts has some direction to point me to. I am hoping there is a _single_ **CMakeLists.txt** file that I could create that could do this so that all I would need to do is run something like the following in the current directory of the local directory I am building:

```auto
$ mkdir build && cd build
$ cmake -GNinja ../

```

Thank you in advance for any help.

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [December 19, 2023, 2:22am UTC](https://discourse.cmake.org/t/download-meson-and-mesa-to-local-repo-and-build/9674/2 "2023-12-19T02:22:35Z")

</div>

In general that command sequence isn’t necessary for CMake projects. Just

```auto
cmake -GNinja -Bbuild

```

Is equivalent.

You could define external project using meson for mesa. First using find\_package(Python) and execute\_command to pip install meson.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 19, 2023, 4:02am UTC](https://discourse.cmake.org/t/download-meson-and-mesa-to-local-repo-and-build/9674/3 "2023-12-19T04:02:39Z")

</div>

It’s not trivial to extract, but Mesa and Meson are part of the [common-superbuild](https://gitlab.kitware.com/paraview/common-superbuild/) which relies on `ExternalProject_Add` under the hood. The quick thing to do would be to just take the logic around `superbuild_add_project`, replace that call with `ExternalProject_Add` and include the relevant bits from `versions.cmake` then tweak from there. Other bits may break, but maybe you don’t need them (the superbuild does…other things to do some package management stuff).

---

<div class="post-metadata">

### Author: ![john](https://discourse.cmake.org/user_avatar/discourse.cmake.org/john/32/4097_2.png) [@john](https://discourse.cmake.org/u/john)
#### Post date: [December 19, 2023, 11:25am UTC](https://discourse.cmake.org/t/download-meson-and-mesa-to-local-repo-and-build/9674/4 "2023-12-19T11:25:52Z")

</div>

Thank you @scivision and @ben.boeckel for the replys.

It sounds like common-superbuild might be what I am looking for.

Please excuse an ignorant question, @ben.boeckel , but can you tell me where the `superbuild_add_project` call is located?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 19, 2023, 12:09pm UTC](https://discourse.cmake.org/t/download-meson-and-mesa-to-local-repo-and-build/9674/5 "2023-12-19T12:09:47Z")

</div>

Look under the `projects/` directory for `meson.cmake` and `*mesa*.cmake`.

---

<div class="post-metadata">

### Author: ![john](https://discourse.cmake.org/user_avatar/discourse.cmake.org/john/32/4097_2.png) [@john](https://discourse.cmake.org/u/john)
#### Post date: [December 19, 2023, 12:13pm UTC](https://discourse.cmake.org/t/download-meson-and-mesa-to-local-repo-and-build/9674/6 "2023-12-19T12:13:14Z")

</div>

Thank you.
