# Very slow CMake O2 installation on macOS

**URL:** <https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68>\
**Category:** O²\
**Created:** [May 14, 2018, 7:49am UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68 "2018-05-14T07:49:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dberzano](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/dberzano/32/7_2.png) [@dberzano](https://alice-talk.web.cern.ch/u/dberzano)\
**Post date:** [May 14, 2018, 7:49am UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/1 "2018-05-14T07:49:13Z")

</div>

At the moment, the installation process on macOS for O2 is painfully slow: a simple `make install`, or `ninja install`, issued in the build directory _when nothing has changed in the source code_ takes around 6 minutes, whereas on my Linux node it takes three seconds.

Apparently, the `install` target, when generated by CMake, cannot run in parallel (so that `-j whatever` has no effect), and quite some time is spent on relocating the binaries using `install_name_tool -delete_rpath ...`: the net result is that the binaries (libraries, executables) in the build directory always differ from the ones in the installation directory, and CMake thinks it’s a good idea to re-relocate and re-copy them every bloody time.

It was (quite correctly, IMHO) pointed out that we have quite a number of binaries and it has to be reduced, but this issue still stands and it has an impact on macOS development.

I’d like it to be fixed possibly without writing a custom `install()` command…

I am wondering if some CMake guru like @deklein has some suggestion here 😉

---

<div class="post-metadata">

**Author:** ![deklein](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/deklein/32/32_2.png) [@deklein](https://alice-talk.web.cern.ch/u/deklein)\
**Post date:** [May 14, 2018, 5:55pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/2 "2018-05-14T17:55:20Z")

</div>

I have looked into the issue and believe I found even two related bugs, which I have filed upstream: [https://gitlab.kitware.com/cmake/cmake/issues/17995](https://gitlab.kitware.com/cmake/cmake/issues/17995). I have no good idea yet for a workaround. Maybe we get an answer soon.

~Dennis

---

<div class="post-metadata">

**Author:** ![dberzano](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/dberzano/32/7_2.png) [@dberzano](https://alice-talk.web.cern.ch/u/dberzano)\
**Post date:** [May 15, 2018, 7:49am UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/3 "2018-05-15T07:49:06Z")

</div>

Thanks for the detailed report! Actually there’s an answer… my issue is that CMake deletes rpath, and a guy says he made its installation faster by using the same rpath on build & install. We might want to have a look into that.

---

<div class="post-metadata">

**Author:** ![deklein](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/deklein/32/32_2.png) [@deklein](https://alice-talk.web.cern.ch/u/deklein)\
**Post date:** [May 15, 2018, 12:24pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/4 "2018-05-15T12:24:49Z")

</div>

I checked the suggestion by Gregor and he is right. You can workaround the installation bug by adding `-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE` in the `o2.sh` recipe for example. But this will render the executables unusable from the build tree unless you explicitely set your `LYLD_LIBRARY_PATH`. It is possible to workaround even that by setting a relative `RPATH`:

On MacOS: `set(CMAKE_INSTALL_RPATH "@loader_path/../lib")`

On Linux (just FYI, because - if you use RPATH on Linux - you should use `RUNPATH` which is enabled as follows):

```auto
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-Wl,--enable-new-dtags")
set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} "-Wl,--enable-new-dtags")
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")

```

If you match the RUNTIME/LIBRARY DESTINATIONS in your build tree with your install tree, then the relative `RPATH` is even correct for both trees.

---

<div class="post-metadata">

**Author:** ![dberzano](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/dberzano/32/7_2.png) [@dberzano](https://alice-talk.web.cern.ch/u/dberzano)\
**Post date:** [May 15, 2018, 12:30pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/5 "2018-05-15T12:30:31Z")

</div>

The point is that we do use executables from the build path (with ctest for  
instance). I’ll have a look at the best way to implement this. Thanks for  
following this up!

---

<div class="post-metadata">

**Author:** ![deklein](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/deklein/32/32_2.png) [@deklein](https://alice-talk.web.cern.ch/u/deklein)\
**Post date:** [May 15, 2018, 12:54pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/6 "2018-05-15T12:54:19Z")

</div>

> [@deklein](#):
>
> If you match the RUNTIME/LIBRARY DESTINATIONS in your build tree with your install tree, then the relative RPATH is even correct for both trees.

I forgot to mention, that this is already the case for the O2 repo.

I recommend putting this [code](https://github.com/FairRootGroup/FairMQ/blob/219487d489efef16b043ed4c1ee02087472432f8/cmake/FairMQLib.cmake#L142-L155) somewhere in your CMake (Replace `${PROJECT_INSTALL_LIBDIR}` with `lib` or some other variable you are currently using and remove the Linux case, if you don’t want it). And add `set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)`. This worked for me in a quick test with O2 on MacOS 10.11.

---

<div class="post-metadata">

**Author:** ![eulisse](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/eulisse/32/19_2.png) [@eulisse](https://alice-talk.web.cern.ch/u/eulisse)\
**Post date:** [May 15, 2018, 1:05pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/7 "2018-05-15T13:05:19Z")

</div>

Ciao,

true, but don’t we always say that if you want to run you need to setup the environment with alienv?

I think we should simply forget about RPATH as it does not match our usecase of “build once, install everywhere”.

---

<div class="post-metadata">

**Author:** ![laphecet](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/laphecet/32/12_2.png) [@laphecet](https://alice-talk.web.cern.ch/u/laphecet)\
**Post date:** [May 15, 2018, 1:20pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/8 "2018-05-15T13:20:42Z")

</div>

@eulisse but the developper usecase is “build frequently, install rarely”, isn’t it ?

---

<div class="post-metadata">

**Author:** ![deklein](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/deklein/32/32_2.png) [@deklein](https://alice-talk.web.cern.ch/u/deklein)\
**Post date:** [May 15, 2018, 1:29pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/9 "2018-05-15T13:29:49Z")

</div>

> [@eulisse](#):
>
> true, but don’t we always say that if you want to run you need to setup the environment with alienv?

How do you invoke `ctest`?

---

<div class="post-metadata">

**Author:** ![eulisse](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/eulisse/32/19_2.png) [@eulisse](https://alice-talk.web.cern.ch/u/eulisse)\
**Post date:** [May 15, 2018, 1:47pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/10 "2018-05-15T13:47:54Z")

</div>

I personally use `alienv setenv O2/latest -c ctest` or a separate tmux pane where I did `alienv enter O2/latest`. Again, our environment is in any case more than just `LD_LIBRARY_PATH` (think for example the G4 environment variables) so you do need to use alienv in anycase.

RPATH is evil.

---

<div class="post-metadata">

**Author:** ![deklein](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/deklein/32/32_2.png) [@deklein](https://alice-talk.web.cern.ch/u/deklein)\
**Post date:** [May 15, 2018, 2:51pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/11 "2018-05-15T14:51:52Z")

</div>

> [@eulisse](#):
>
> RPATH is evil.

I rather conclude `LD_LIBRARY_PATH` is evil 😉 (Isn’t `LD_LIBRARY_PATH` even disabled by default on recent MacOS?)

---

<div class="post-metadata">

**Author:** ![sbinet](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/sbinet/32/16_2.png) [@sbinet](https://alice-talk.web.cern.ch/u/sbinet)\
**Post date:** [May 15, 2018, 9:04pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/12 "2018-05-15T21:04:25Z")

</div>

die `LD_LIBRARY_PATH`!  
die `RPATH`!

gimme good ol’ completely static binaries that are easily deployable 🙂

---

<div class="post-metadata">

**Author:** ![laphecet](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/laphecet/32/12_2.png) [@laphecet](https://alice-talk.web.cern.ch/u/laphecet)\
**Post date:** [May 16, 2018, 1:41pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/13 "2018-05-16T13:41:34Z")

</div>

btw, I also noticed that e.g. ninja install is awfully slow if done under a full env. (i.e. after module load O2/latest…) while reasonable (but still slow) if done without any module loaded. Has someone else observed this ?

---

<div class="post-metadata">

**Author:** ![eulisse](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/eulisse/32/19_2.png) [@eulisse](https://alice-talk.web.cern.ch/u/eulisse)\
**Post date:** [May 17, 2018, 8:05pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/14 "2018-05-17T20:05:38Z")

</div>

So apparently FairMQ 1.2.2 is actually quite an improvement in build speed. When is the new splitted package layout supposed to be ported to O2?

---

<div class="post-metadata">

**Author:** ![eulisse](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/eulisse/32/19_2.png) [@eulisse](https://alice-talk.web.cern.ch/u/eulisse)\
**Post date:** [May 18, 2018, 11:16pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/15 "2018-05-18T23:16:57Z")

</div>

Ok, I did a workaround in the framework code which seems to improve the situation for me. Can you check?

> <https://github.com/AliceO2Group/AliceO2/pull/1092>

?

---

<div class="post-metadata">

**Author:** ![laphecet](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/laphecet/32/12_2.png) [@laphecet](https://alice-talk.web.cern.ch/u/laphecet)\
**Post date:** [May 19, 2018, 5:13pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/16 "2018-05-19T17:13:44Z")

</div>

Did a `shake -j8 --profile` on your PR (top part of image below) vs dev (bottom part).

Not a drastic change but an (unparalleled) gain of 3 minutes still.

 ![07](https://alice-talk.web.cern.ch/uploads/default/original/1X/775c3cbec91944782703c86958098c1f912b1028.png)

I’ve posted the two complete reports at : [https://cernbox.cern.ch/index.php/s/unP84Q06pY7uVmA](https://cernbox.cern.ch/index.php/s/unP84Q06pY7uVmA) (build of PR#1092) and [https://cernbox.cern.ch/index.php/s/jQRqRSAa4AD8q3B](https://cernbox.cern.ch/index.php/s/jQRqRSAa4AD8q3B) (ref build)

---

<div class="post-metadata">

**Author:** ![eulisse](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/eulisse/32/19_2.png) [@eulisse](https://alice-talk.web.cern.ch/u/eulisse)\
**Post date:** [May 19, 2018, 7:50pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/17 "2018-05-19T19:50:05Z")

</div>

Great, thanks for confirming. I will merge this then. There is more work that can be done, at least in the framework, to hide the rest of FairRoot. Hiding ROOT as well would probably help. I suspect we need similar campaigns elsewhere, and I would be all in favour forbidding boost in the APIs.

---

<div class="post-metadata">

**Author:** ![eulisse](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/eulisse/32/19_2.png) [@eulisse](https://alice-talk.web.cern.ch/u/eulisse)\
**Post date:** [May 19, 2018, 9:27pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/18 "2018-05-19T21:27:42Z")

</div>

Could you also try out [https://github.com/AliceO2Group/AliceO2/pull/1094](https://github.com/AliceO2Group/AliceO2/pull/1094)?

---

<div class="post-metadata">

**Author:** ![laphecet](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/laphecet/32/12_2.png) [@laphecet](https://alice-talk.web.cern.ch/u/laphecet)\
**Post date:** [May 20, 2018, 10:15am UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/19 "2018-05-20T10:15:17Z")

</div>

Hum, pending an error on my side (tried the build twice though), it seems actually a bit _slower_, or let’s say not faster at least 😉

[https://cernbox.cern.ch/index.php/s/MVRfStBlUF3cifP](https://cernbox.cern.ch/index.php/s/MVRfStBlUF3cifP)

 ![15](https://alice-talk.web.cern.ch/uploads/default/original/1X/4230c89c08ca0128ee92ad183f92a6fe2de03603.png)

---

<div class="post-metadata">

**Author:** ![eulisse](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/eulisse/32/19_2.png) [@eulisse](https://alice-talk.web.cern.ch/u/eulisse)\
**Post date:** [May 20, 2018, 3:21pm UTC](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68/20 "2018-05-20T15:21:47Z")

</div>

I suspect that’s in the profiling noise. Probably the changes are not enough to hide more stuff, so basically the PR is a no-op. Indeed the deps files seem to be unchanged, so I suspect there is something else bringing in the stuff. Will need a bit more massaging I guess.

[Next page](https://alice-talk.web.cern.ch/t/very-slow-cmake-o2-installation-on-macos/68.md?page=2)
