# New at using CMake - unable to run O2/Examples

**URL:** <https://alice-talk.web.cern.ch/t/new-at-using-cmake-unable-to-run-o2-examples/461>\
**Category:** O²\
**Tags:** cmake\
**Created:** [January 20, 2020, 6:00pm UTC](https://alice-talk.web.cern.ch/t/new-at-using-cmake-unable-to-run-o2-examples/461 "2020-01-20T18:00:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![alandou](https://alice-talk.web.cern.ch/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@alandou](https://alice-talk.web.cern.ch/u/alandou)\
**Post date:** [January 20, 2020, 6:00pm UTC](https://alice-talk.web.cern.ch/t/new-at-using-cmake-unable-to-run-o2-examples/461/1 "2020-01-20T18:00:35Z")

</div>

Hi,

I am starting to look at how to use cmake.  
As I found the examples available in O2/Examples I decided to try to follow the CmakeInstructions.md documentation.

Thus, I enter “CMake/latest” using alienv (after realising I couldn’t use cmake commands inside “O2/latset”, then type the command `cmake --build .` inside the “~/O2/Examples/Ex1” directory.  
I am met with a “Error: could not load cache” message.  
From what I’ve gathered looking up this error message, I might need to run another command before the build one.  
After looking at some tutorials, here is the sequence I end up trying to type inside the O2/Examples/Ex1 directory:

> ```
> mkdir build
> cd build
> cmake ..
> make
> 
> ```

Unfortunately, I am met with an error message telling me the o2\_add\_library command in the CMakeLists.txt is unknown:

```
[CMake/latest] ~/O2/Examples/Ex1 $> mkdir build
[CMake/latest] ~/O2/Examples/Ex1 $> cd build
[CMake/latest] ~/O2/Examples/Ex1/build $> cmake ..
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /persist/sw/slc7_x86-64/GCC-Toolchain/v7.3.0-alice1-9/bin/cc
-- Check for working C compiler: /persist/sw/slc7_x86-64/GCC-Toolchain/v7.3.0-alice1-9/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /persist/sw/slc7_x86-64/GCC-Toolchain/v7.3.0-alice1-9/bin/c++
-- Check for working CXX compiler: /persist/sw/slc7_x86-64/GCC-Toolchain/v7.3.0-alice1-9/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:11 (o2_add_library):
  Unknown CMake command "o2_add_library".

CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present. A line of code such as

cmake_minimum_required(VERSION 3.13)

  should be added at the top of the file. The version specified may be lower
  if you wish to support older CMake versions for this project. For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.

-- Configuring incomplete, errors occurred!
See also "/home/alidock/O2/Examples/Ex1/build/CMakeFiles/CMakeOutput.log".
[CMake/latest] ~/O2/Examples/Ex1/build $> 

```

Maybe cmake doesn’t recognise O2 commands because I am entered CMake/latest with alienv and not O2/latest? But make commands were not recognised inside O2/latest.  
Or is there something else I should be doing differently?  
Additionally, is there a standard sequence of cmake commands in use in O2?

I am running this on an O2 installation made using alidock, on a macOS Mojave machine.

Best,  
Aimeric

---

<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:** [January 20, 2020, 8:36pm UTC](https://alice-talk.web.cern.ch/t/new-at-using-cmake-unable-to-run-o2-examples/461/2 "2020-01-20T20:36:07Z")

</div>

Hi Aimeric,

Indeed, a CMake build is always a two phase process : you first configure (using cmake srcdir … from a build directory) and then build.

When you are developing some code the configure stage (the one which is actually setting up the underlying build system) is typically (manually, at least) done only once while the building is done repeatedly (each time you change source code) (if you change some `CMakeLists.txt` during development, the build stage will trigger first an update of the configure stage, but that is mostly automatic)

For O2, the configure (and first build) is usually done with `aliBuild` (e.g. `aliBuild --defaults o2 build O2`).

Once this is done, you can go to the `sw/BUILD/O2-latest/O2` which contains the configured cmake system, in which you can do `cmake --build .`. For this you of course need the `cmake` executable to be in your path somehow (either it’s installed on your system, or you can use something like `alienv enter CMake/latest` to use the one built by aliBuild)

What you miss to realize I guess is that the examples in AliceO2 are _not_ meant to be used “standalone” : the `CMakeLists.txt` in the O2/Examples directories are part of a `CMakeLists.txt` hierarchy that starts at the root of the AliceO2 source directory. That’s for instance at the root of that hierarchy that the custom o2\_xxx function are defined. Attempting a cmake configure “in the middle” on the hierarchy can _not_ work.

Hope this helps,

Cheers,

---

<div class="post-metadata">

**Author:** ![alandou](https://alice-talk.web.cern.ch/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@alandou](https://alice-talk.web.cern.ch/u/alandou)\
**Post date:** [January 23, 2020, 11:01am UTC](https://alice-talk.web.cern.ch/t/new-at-using-cmake-unable-to-run-o2-examples/461/3 "2020-01-23T11:01:11Z")

</div>

Thank you for your detailed answer!  
Unfortunately I cannot try right now as I am having issues re-building O2. Once I have solved this issue, I will put this to the test.

Best,  
Aimeric

---

<div class="post-metadata">

**Author:** ![alandou](https://alice-talk.web.cern.ch/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@alandou](https://alice-talk.web.cern.ch/u/alandou)\
**Post date:** [February 6, 2020, 3:22pm UTC](https://alice-talk.web.cern.ch/t/new-at-using-cmake-unable-to-run-o2-examples/461/4 "2020-02-06T15:22:25Z")

</div>

Hi,

I now have a working O2 build on my alidock container.  
I am trying to follow this O2 tutorial: ([http://alisw.github.io/o2-tutorial/](http://alisw.github.io/o2-tutorial/)) and am trying to compile the code I wrote.  
If I understand correctly your post, once I edit a source file or add some of my own inside my `alidock/O2` repository, I can have it build by typing `cmake --build .` inside the `/persist/sw/BUILD/O2-latest/O2/` directory (which I think is the `sw/BUILD/O2-latest/O2` directory you mention?).  
Unfortunately, when I try that command line (after entering CMake/latest), I get the following message:

> `ninja: no work to do`

Obviously I am missing a step. Maybe I haven’t put my files in the right folder, maybe there is one more CMakeLists.txt file I have to edit, not mentioned in the tutorial. Or maybe the tutorial is too old and is misleading me? The command line they suggest is `make -j 10 install` instead of `cmake --build .` What is the difference?

Best,  
Aimeric

---

<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:** [February 7, 2020, 10:15am UTC](https://alice-talk.web.cern.ch/t/new-at-using-cmake-unable-to-run-o2-examples/461/5 "2020-02-07T10:15:32Z")

</div>

is the code you are trying to compile visible on GitHub ?

Concerning the `make -j 10 install` vs `cmake --build .` difference.

The second one will build, whatever build system has been generated, while the first one will only work if cmake has generated Makefiles (i.e. it won’t work if you’re trying it in a build directory configured for ninja).

The second one will only build, while the first one builds and installs. So the cmake equivalent to the make command would be `cmake --build . --target install` (or, starting with CMake version 3.15 `cmake --install .`simply)

---

<div class="post-metadata">

**Author:** ![alandou](https://alice-talk.web.cern.ch/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@alandou](https://alice-talk.web.cern.ch/u/alandou)\
**Post date:** [February 7, 2020, 11:54am UTC](https://alice-talk.web.cern.ch/t/new-at-using-cmake-unable-to-run-o2-examples/461/6 "2020-02-07T11:54:06Z")

</div>

After looking into it a bit more, it appears this tutorial is more than 2-year old: you can find it here [https://github.com/alisw/o2-tutorial](https://github.com/alisw/o2-tutorial). And is not actually really using O2 at all, but FairRoot packages only.  
I had been directed to this earlier this year to get a feel at some of O2 processes, but it might now be a bit too old to use.  
I was partly using it now to have a working set of files and a working CMakeFile.txt to try and compile it. But I now realise the CMakeFile is using a different set of functions, like `add_executable` instead `o2_add_executable`, so it was not going to work.

Sorry for those question, I’m still trying to wrap my head around those things.  
Thank you for your time!

---

<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:** [February 7, 2020, 12:29pm UTC](https://alice-talk.web.cern.ch/t/new-at-using-cmake-unable-to-run-o2-examples/461/7 "2020-02-07T12:29:21Z")

</div>

Yes, the tutorial is rather obsolete. We should probably remove it.

---

<div class="post-metadata">

**Author:** ![saarodri](https://alice-talk.web.cern.ch/letter_avatar_proxy/v4/letter/s/ce7236/32.png) [@saarodri](https://alice-talk.web.cern.ch/u/saarodri)\
**Post date:** [February 18, 2020, 9:32pm UTC](https://alice-talk.web.cern.ch/t/new-at-using-cmake-unable-to-run-o2-examples/461/8 "2020-02-18T21:32:53Z")

</div>

Hi  
I’m new at ALICE and I will have to use O2 . I was trying to follow the same tutorial [http://alisw.github.io/o2-tutorial/](http://alisw.github.io/o2-tutorial/) and I think I got stuck in the same part. If it’s too old now, does anyone know of any other O2 tutorial for begginers?

---

<div class="post-metadata">

**Author:** ![bvonhall](https://alice-talk.web.cern.ch/user_avatar/alice-talk.web.cern.ch/bvonhall/32/8_2.png) [@bvonhall](https://alice-talk.web.cern.ch/u/bvonhall)\
**Post date:** [February 19, 2020, 7:40am UTC](https://alice-talk.web.cern.ch/t/new-at-using-cmake-unable-to-run-o2-examples/461/9 "2020-02-19T07:40:38Z")

</div>

Hi,

Please head to [https://aliceo2group.github.io/](https://aliceo2group.github.io/) for a newcomers’ guide.

It would be nice of you to give us feedback on it, or even to contribute via a PR if some things are not clear or outdated.

Best regards,  
Barth
