# Building ROOT v6-28-06 with cmake toolchain file

**URL:** <https://root-forum.cern.ch/t/building-root-v6-28-06-with-cmake-toolchain-file/56548>\
**Category:** ROOT\
**Tags:** build\
**Created:** [September 30, 2023, 4:43am UTC](https://root-forum.cern.ch/t/building-root-v6-28-06-with-cmake-toolchain-file/56548 "2023-09-30T04:43:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jade2](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/ac91a4/32.png) [@jade2](https://root-forum.cern.ch/u/jade2)\
**Post date:** [September 30, 2023, 4:43am UTC](https://root-forum.cern.ch/t/building-root-v6-28-06-with-cmake-toolchain-file/56548/1 "2023-09-30T04:43:38Z")

</div>

Hi,  
I downloaded root source code from the root git repository with git tag `v6-28-06`. I initially build it with gcc version 9.4.0 (that’s the default compiler for ubuntu 20.04). When first configuring cmake against the root source code, initially it complained about not finding LZ4 and X11. Once I installed both LZ4 and X11, the configuration passed (having no problems finding LZ4 and X11) and the build was successful. I initially wanted to at least build root with the default compiler I had on my ubuntu, before attempting to build it against the desired toolchain (a newer gcc compiler (10.0.2) with a tailored sysroot).

So when I finally tried to build it with a specified cmake toolchain file (e.g. `cmake -DCMAKE_TOOLCHAIN_FILE=<my-toolchain.cmake> <root-src-dir>`), I get an error during its cmake configuration:

```auto
-- Looking for LZ4
-- Could NOT find LZ4 (missing: LZ4_LIBRARY) (found version "1.9.2")
-- LZ4 not found. Switching on builtin_lz4 option
-- Looking for X11
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
  Could NOT find X11 (missing: X11_X11_LIB)
Call Stack (most recent call first):
  /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.16/Modules/FindX11.cmake:366 (find_package_handle_standard_args)
  cmake/modules/SearchInstalledSoftware.cmake:18 (_find_package)
  cmake/modules/SearchInstalledSoftware.cmake:366 (find_package)
  CMakeLists.txt:254 (include)

```

In my cmake toolchain file, I specified the location of the desired C/C++ compiler via `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER` and the desired sysroot directory via `CMAKE_SYSROOT`. I did also set the root path to look at both the targeted and host directories:

```auto
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
SET(CMAKE_SYSTEM_PROCESSOR x86_64)

```

The goal here is, to use the specified C/C++ compliler and compiling/linking against the std libs found at the specified sysroot directory. But I want it to pick up packages like LZ4 and X11 at the host directories, where it had no problem finding it earlier, when I did not configure cmake with the CMAKE\_TOOLCHAIN\_FILE option. There are other libraries in the sysroot directory other than the std libs but LZ4 and X11 libraries are not among them.

So why is it failing to find LZ4 and X11 only when specifying a cmake toolchain file? The only difference here is a newer gcc compiler and specified sysroot, which shouldn’t impact its ability to find those packages.

* * *

_Please read [tips for efficient and successful posting](https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292) and [posting code](https://root-forum.cern.ch/t/posting-code-read-this-first/28293)_

_Please fill also the fields below. Note that **`root -b -q`** will tell you this info, and starting from 6.28/06 upwards, you can call **`.forum bug`** from the ROOT prompt to pre-populate a topic._

\_ROOT Version:v6-28-06  
\_Platform:linux, ubuntu 20.04  
\_Compiler:GCC 10.0.2

* * *

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [October 2, 2023, 1:14pm UTC](https://root-forum.cern.ch/t/building-root-v6-28-06-with-cmake-toolchain-file/56548/2 "2023-10-02T13:14:52Z")

</div>

Hi! Can you maybe put here the content of your full `toolchain.cmake` file? I can’t reproduce the problem with only the information provided here.

By the way, I’m not sure is the cmake toolchain file is really the appropriate solution to your problem. It seems that it’s intended for [cross compiling](https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html), which you’re not really doing. Your are compiling on Ubuntu 20.04 for Ubuntu 20.40, right?

I think in this situation, it’s more appropriate to use a CMake cache configuration file, like `cmake -C <my-settings.cmake> <root-src-dir>`. Then you don’t need to deal with these host/target subtleties but still have full control over all CMake variables, like `CMAKE_CXX_COMPILER` etc.

```plaintext
set (CMAKE_CXX_STANDARD 20 CACHE STRING "" FORCE)
set (CMAKE_CUDA_STANDARD 20 CACHE STRING "" FORCE)
set (CMAKE_CUDA_COMPILER "/opt/cuda/bin/nvcc" CACHE STRING "" FORCE)
set (CMAKE_CUDA_ARCHITECTURES "75" CACHE STRING "" FORCE)
set (CMAKE_CXX_FLAGS "-fno-omit-frame-pointer" CACHE STRING "" FORCE)
#set (CMAKE_CXX_COMPILER "/bin/clang++" CACHE STRING "" FORCE)
set (LLVM_CXX_STD c++20 CACHE STRING "" FORCE)
set (LLVM_BUILD_TYPE Release CACHE STRING "" FORCE)
# ... long list to switch ROOT features on and off

```

Another CMake variable that could be useful to you is [CMAKE\_PREFIX\_PATH](https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html).

I hope these ideas help you a bit to solve the problem!

Cheers,  
Jonas

---

<div class="post-metadata">

**Author:** ![jade2](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/ac91a4/32.png) [@jade2](https://root-forum.cern.ch/u/jade2)\
**Post date:** [October 9, 2023, 7:17pm UTC](https://root-forum.cern.ch/t/building-root-v6-28-06-with-cmake-toolchain-file/56548/3 "2023-10-09T19:17:10Z")

</div>

Hi @jonas,  
You’re probably right that the toolchain option is not quite the correct choice to do this in, since it’s still building for Ubuntu 20.04 but just using a different version of compiler and sysroot. So initially I tried the following option, where I specified those:

```auto
$ cmake -DCMAKE_C_COMPILER=/home/jade/external/x86_64-linux-gcc-10.2.0/bin/gcc -DCMAKE_CXX_COMPILER=/home/jade/external/x86_64-linux-gcc-10.2.0/bin/g++ -DCMAKE_SYSROOT=/home/jade/external/x86_64-linux-gcc-10.2.0/x86_64-linux-gnu/sysroot ..

```

But I still get the same cmake configuration error:

```auto
-- Looking for LZ4
-- Could NOT find LZ4 (missing: LZ4_LIBRARY) (found version "1.9.2")
-- LZ4 not found. Switching on builtin_lz4 option
-- Looking for X11
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
  Could NOT find X11 (missing: X11_X11_LIB)
Call Stack (most recent call first):
  /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.16/Modules/FindX11.cmake:366 (find_package_handle_standard_args)
  cmake/modules/SearchInstalledSoftware.cmake:18 (_find_package)
  cmake/modules/SearchInstalledSoftware.cmake:366 (find_package)
  CMakeLists.txt:254 (include)

```

So I tried your suggestion of putting those options into a cmake file and passing this file to cmake via `cmake -C my-settings.cmake` and oddly enough the configuration succeeded (wonder why putting those settings into a file makes a difference).

But building seem to have failed on several issues. To show just a few:

```auto
/home/jade/root/gcc10-build/etc/cling/std.modulemap:69:12: error: header 'compare' not found
    header "compare"
           ^
input_line_1:1:10: note: submodule of top-level module 'std' implicitly imported here
#include <new>
         ^
Warning in cling::IncrementalParser::CheckABICompatibility():
  Failed to extract C++ standard library version.
While building module 'Core':
While building module 'Cling_Runtime' imported from input_line_2:1:
While building module 'Cling_Runtime_Extra' imported from /home/jade/root/gcc10-build/etc/cling/Interpreter/RuntimeUniverse.h:27:
/home/jade/root/gcc10-build/etc/cling/std.modulemap:69:12: error: header 'compare' not found
    header "compare"
           ^
/home/jade/root/gcc10-build/etc/cling/Interpreter/DynamicExprInfo.h:13:10: note: submodule of top-level module 'std' implicitly imported here
#include <string>
         ^
/home/jade/root/gcc10-build/etc/cling/Interpreter/DynamicExprInfo.h:40:7: error: use of undeclared identifier 'std'
      std::string m_Result;

```

Looking at a more verbose build for details, it doesn’t look like it’s picking up the standard library headers at the specified sysroot directory I provided (it’s set to look at the default places like at `/usr`, which is not what I want it to do, but to look for the headers/libs in the specified sysroot). I don’t see the `--sysroot` compilation option being passed at all.

My my-settings.cmake file looks like this:

```auto
set(CMAKE_C_COMPILER /home/jade/external/x86_64-linux-gcc-10.2.0/bin/gcc)
set(CMAKE_CXX_COMPILER /home/jade/external/x86_64-linux-gcc-10.2.0/bin/g++)
set(CMAKE_CXX_STANDARD 20 CACHE STRING "" FORCE)
set(CMAKE_SYSROOT /home/jade/external/x86_64-linux-gcc-10.2.0/x86_64-linux-gnu/sysroot)

```

It seems to be ignoring the `CMAKE_SYSROOT` that I specified in `my-settings.cmake` file. [I looked this up](https://cmake.org/cmake/help/latest/variable/CMAKE_SYSROOT.html) and it seems `CMAKE_SYSROOT` will only work in a `CMAKE_TOOLCHAIN_FILE`, which is why I originally thought I needed to pass in a cmake toolchain file.

How can I get around this? The reason that I need to specify the `CMAKE_SYSROOT` is to specify where to pick up stdlibs (consistent to the specified compiler), among other libs (later, I’ll need to to set a cuda compiler and its libs which is located at this sysroot directory).

---

<div class="post-metadata">

**Author:** ![jade2](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/ac91a4/32.png) [@jade2](https://root-forum.cern.ch/u/jade2)\
**Post date:** [October 10, 2023, 12:08am UTC](https://root-forum.cern.ch/t/building-root-v6-28-06-with-cmake-toolchain-file/56548/4 "2023-10-10T00:08:35Z")

</div>

Hi @jonas  
So I removed setting `CMAKE_SYSROOT` and instead tried adding --sysroot as a c/cxx compiler and linker flag instead:

```auto
set(CMAKE_C_COMPILER /home/jade/external/x86_64-linux-gcc-10.2.0/bin/gcc)

set(CMAKE_CXX_COMPILER /home/jade/external/x86_64-linux-gcc-10.2.0/bin/g++)

set(CMAKE_CXX_STANDARD 20 CACHE STRING "" FORCE)

set(MYSYSROOT /home/jade/external/x86_64-linux-gcc-10.2.0/x86_64-linux-gnu/sysroot)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --no-sysroot-suffix --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE)
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --no-sysroot-suffix --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --no-sysroot-suffix --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE)
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} --no-sysroot-suffix --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE)

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --no-sysroot-suffix --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --no-sysroot-suffix --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE)

# pick up openssl at /usr and not at specified sysroot
set(OPENSSL_ROOT_DIR /usr)
set(OPENSSL_INCLUDE_DIR /usr/include)
set(OPENSSL_LIBRARIES /usr/lib/x86_64-linux-gnu)

```

I’ve also set it up to loop for openssl in the usual place of `/usr`.

So when I run the cmake config, I see this:

```auto
-- Compiler Flags: --no-sysroot-suffix --sysroot=/home/jade/external/x86_64-linux-gcc-10.2.0/x86_64-linux-gnu/sysroot -std=c++2a -Wno-implicit-fallthrough -Wno-noexcept-type -pipe -Wshadow -Wall -W -Woverloaded-virtual -fsigned-char -pthread 
...
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.1f")  
...
System Linux-5.15.0-84-generic
Processor 8 core 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz (x86_64)
Build type      
Install path /usr/local
Compiler GNU 9.4.0
Compiler flags:
C --no-sysroot-suffix --sysroot=/home/jade/external/x86_64-linux-gcc-10.2.0/x86_64-linux-gnu/sysroot -Wno-implicit-fallthrough -pipe -Wall -W -pthread 
C++ --no-sysroot-suffix --sysroot=/home/jade/external/x86_64-linux-gcc-10.2.0/x86_64-linux-gnu/sysroot -std=c++2a -Wno-implicit-fallthrough -Wno-noexcept-type -pipe -Wshadow -Wall -W -Woverloaded-virtual -fsigned-char -pthread 
Linker flags:
Executable --no-sysroot-suffix --sysroot=/home/jade/external/x86_64-linux-gcc-10.2.0/x86_64-linux-gnu/sysroot -rdynamic
Module          
Shared --no-sysroot-suffix --sysroot=/home/jade/external/x86_64-linux-gcc-10.2.0/x86_64-linux-gnu/sysroot -Wl,--no-undefined -Wl,--hash-style="both"

```

So it looks like the sysroot option is getting passed in, but _I don’t quite understand why it’s not correctly picking up the compiler specified in `my-settings.cmake`_ (which is version 10.2.0):

```auto
$ /home/jade/external/x86_64-linux-gcc-10.2.0/bin/gcc --version
gcc (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

```

In any case I attempted to run the build and it failed building XROOTD. It referred the XROOTD-build-err.log file to look at:

```auto
[I] No git repository info found. Trying to interpret VERSION_INFO
[I] Using the user supplied version: v5.5.2
[I] src/XrdVersion.hh successfully generated
/home/jade/root/gcc10-build/builtins/xrootd/XROOTD-prefix/src/XROOTD/src/XrdTls/XrdTls.cc:32:10: fatal error: openssl/err.h: No such file or directory
   32 | #include <openssl/err.h>
      | ^ ~~~~~~~~~~~~~~
compilation terminated.
make[5]: *** [src/CMakeFiles/XrdUtils.dir/build.make:297: src/CMakeFiles/XrdUtils.dir/XrdTls/XrdTls.cc.o] Error 1
make[4]: *** [CMakeFiles/Makefile2:870: src/CMakeFiles/XrdUtils.dir/all] Error 2
make[3]: *** [Makefile:130: all] Error 2

```

I tried to run the build with `make -j8 VERBOSE=1` to see if it would at least show me the compilation command so I can see what header includes were being passed to the compiler, but it still wouldn’t show any details of the compilation for XROOTD beyond what is shown above.

If you’ll notice I added this to `my-settings.cmake` at the bottom:

```auto
set(OPENSSL_ROOT_DIR /usr)
set(OPENSSL_INCLUDE_DIR /usr/include)
set(OPENSSL_LIBRARIES /usr/lib/x86_64-linux-gnu)

```

My earlier versions of `my-settings.cmake` didn’t have the above and was getting similar errors about failing to find those openssl headers, despite the cmake config results found the openssl library at the correct place (`/usr/lib/x86_64-linux-gnu`). So I thought being explicit about it would help it find the openssl includes. But alas, it’s still failed to find the openssl headers despite being there as specified:

```auto
$ ls /usr/include/openssl
aes.h bio.h cmac.h cryptoerr.h dsa.h engine.h kdf.h objects.h pem.h rc2.h sha.h storeerr.h ui.h
asn1err.h blowfish.h cmserr.h crypto.h dtls1.h e_os2.h lhash.h obj_mac.h pkcs12err.h rc4.h srp.h store.h whrlpool.h
asn1.h bnerr.h cms.h cterr.h ebcdic.h err.h md2.h ocsperr.h pkcs12.h rc5.h srtp.h symhacks.h x509err.h
asn1_mac.h bn.h comperr.h ct.h ecdh.h evperr.h md4.h ocsp.h pkcs7err.h ripemd.h ssl2.h tls1.h x509.h
asn1t.h buffererr.h comp.h des.h ecdsa.h evp.h md5.h opensslv.h pkcs7.h rsaerr.h ssl3.h tserr.h x509v3err.h
asyncerr.h buffer.h conf_api.h dherr.h ecerr.h hmac.h mdc2.h ossl_typ.h rand_drbg.h rsa.h sslerr.h ts.h x509v3.h
async.h camellia.h conferr.h dh.h ec.h idea.h modes.h pem2.h randerr.h safestack.h ssl.h txt_db.h x509_vfy.h
bioerr.h cast.h conf.h dsaerr.h engineerr.h kdferr.h objectserr.h pemerr.h rand.h seed.h stack.h uierr.h

```

Do you know how I can get the build to show me the actual compilation command that was used to build `Xrd*.cc`? I tried `make -j8 VERBOSE=1` but it still doesn’t display the compilation command used. I want to see if `/usr/include` is one of the include paths in that compilation command, where it should find the openssl headers.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [October 24, 2023, 12:08am UTC](https://root-forum.cern.ch/t/building-root-v6-28-06-with-cmake-toolchain-file/56548/5 "2023-10-24T00:08:47Z")

</div>

Closed on October 24, 2023, 12:08am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
