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.
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.
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.
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/) 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?
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)
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. 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!
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/ 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?