# Managing built-in and dnf versions of XRootD in CMake project

**URL:** <https://root-forum.cern.ch/t/managing-built-in-and-dnf-versions-of-xrootd-in-cmake-project/59335>\
**Category:** ROOT\
**Tags:** cmake\
**Created:** [May 14, 2024, 2:30pm UTC](https://root-forum.cern.ch/t/managing-built-in-and-dnf-versions-of-xrootd-in-cmake-project/59335 "2024-05-14T14:30:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ako\_b](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@Ako\_b](https://root-forum.cern.ch/u/Ako_b)\
**Post date:** [May 14, 2024, 2:30pm UTC](https://root-forum.cern.ch/t/managing-built-in-and-dnf-versions-of-xrootd-in-cmake-project/59335/1 "2024-05-14T14:30:50Z")

</div>

### Short description

Hello!  
I have a problem with location of headers like `XrdCl/XrdClFileSystem.hh`: they are in `${ROOTSYS}/include` with built-in XRootD and elsewhere with external XRootD installation.  
How to deal with both cases in CMake?

I am asking this here because I think this is more ROOT-specific question.

### Long Description

I am working on a CMake project which depends in particular on XRootD.  
There are two setups to deal with: one with ROOT built from source and the other with ROOT installed via dnf.

On machines with ROOT built from source the project compiles normally.  
I’ve started experimenting with ROOT shipped via dnf and discovered that project doesn’t compile with it, showing errors like this:

```auto
/usr/include/root/TNetXNGFile.h:27:10: fatal error: XrdCl/XrdClFileSystem.hh: No such file or directory
   27 | #include <XrdCl/XrdClFileSystem.hh>

```

Apparently, this is because ROOT from dnf requires external XRootD (see setup descriptions in the end of message).  
I have fixed this by adding following lines to CMakeFiles.txt:

```auto
find_package(XRootD REQUIRED)
if (NOT XROOTD_FOUND)
    message(SEND_ERROR "Failed to find XRootD")
    return()
endif()
include_directories(${XROOTD_INCLUDE_DIRS})

```

However, it breaks compilation with ROOT built from source, featuring built-in XRootD:

```auto
CMake Error at CMakeLists.txt:7 (find_package):
  By not providing "FindXRootD.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "XRootD", but
  CMake did not find one.

  Could not find a package configuration file provided by "XRootD" with any
  of the following names:

    XRootDConfig.cmake
    xrootd-config.cmake

  Add the installation prefix of "XRootD" to CMAKE_PREFIX_PATH or set
  "XRootD_DIR" to a directory containing one of the above files. If "XRootD"
  provides a separate development package or SDK, be sure it has been
  installed.

```

So in order to handle both cases, it seems that I have to check if XRootD is built-in.  
I couldn’t find any information on this.

Or is there another approach?

### Setup built from source

ROOT built from source on AlmaLinux 9.  
`root-config --features` yields both `builtin_xrootd` and `xrootd`.

```auto
ROOT v6.30/06
Built for linuxx8664gcc on May 14 2024, 12:41:16
From tags/v6.30.06-0-g4f4e716372@v6.30.06-0-g4f4e716372
With c++ (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3)
Binary directory: /usr/local/bin

```

### Setup via dnf

ROOT installed on AlmaLinux 9 via `dnf install root xrootd` (I don’t remember exact command).  
`root-config --features` yields only `xrootd`.

```auto
ROOT v6.30/06
Built for linuxx8664gcc on Apr 25 2024, 00:00:00
From heads/master@tags/v6-30-06
With g++ (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2)
Binary directory: /usr/bin

```

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [May 15, 2024, 7:37am UTC](https://root-forum.cern.ch/t/managing-built-in-and-dnf-versions-of-xrootd-in-cmake-project/59335/2 "2024-05-15T07:37:48Z")

</div>

Adding @bellenot in the loop.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [May 15, 2024, 8:05am UTC](https://root-forum.cern.ch/t/managing-built-in-and-dnf-versions-of-xrootd-in-cmake-project/59335/3 "2024-05-15T08:05:22Z")

</div>

So `root-config --features` is correct in both cases and you can use it to determine if Xrootd used by ROOT is builtin or not. Note also that `ROOTConfig.cmake` contains this information. I don’t think this can be handled in ROOT itself, but I can try if you want, though I would need some time to set-up a Virtual Machine with the full environment and make some tests…

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [May 15, 2024, 8:12am UTC](https://root-forum.cern.ch/t/managing-built-in-and-dnf-versions-of-xrootd-in-cmake-project/59335/4 "2024-05-15T08:12:29Z")

</div>

P.S. I think you can use `if(ROOT_builtin_xrootd_FOUND)` in your `CMakeLists.txt`

---

<div class="post-metadata">

**Author:** ![Ako\_b](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@Ako\_b](https://root-forum.cern.ch/u/Ako_b)\
**Post date:** [May 15, 2024, 8:50am UTC](https://root-forum.cern.ch/t/managing-built-in-and-dnf-versions-of-xrootd-in-cmake-project/59335/5 "2024-05-15T08:50:45Z")

</div>

> [@bellenot](#):
>
> if(ROOT\_builtin\_xrootd\_FOUND)

That works, thank you! I’ve ended up with

```auto
if (NOT ROOT_builtin_xrootd_FOUND)
    find_package(XRootD REQUIRED)
    if (NOT XROOTD_FOUND)
        message(SEND_ERROR "Failed to find XRootD")
        return()
    endif()
endif()
include_directories(${XROOTD_INCLUDE_DIRS})

```

Also I’ve looked into [`ROOTConfig.cmake`](https://github.com/root-project/root/blob/master/cmake/modules/RootConfiguration.cmake), and then in [`ROOTConfig.cmake.in`](https://github.com/root-project/root/blob/master/cmake/scripts/ROOTConfig.cmake.in). I’ve found

```auto
foreach(_opt ${_root_enabled_options})
  set(ROOT_${_opt}_FOUND TRUE)
endforeach()

```

So clause like `if(ROOT_${_opt}_FOUND)` should be applicable for any enabled [ROOT build option](https://root.cern/install/build_from_source/#all-build-options). Thanks for the insight!

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [May 15, 2024, 8:52am UTC](https://root-forum.cern.ch/t/managing-built-in-and-dnf-versions-of-xrootd-in-cmake-project/59335/6 "2024-05-15T08:52:18Z")

</div>

You’re very welcome!

---

<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:** [May 29, 2024, 8:53am UTC](https://root-forum.cern.ch/t/managing-built-in-and-dnf-versions-of-xrootd-in-cmake-project/59335/7 "2024-05-29T08:53:05Z")

</div>

Closed on May 29, 2024, 8:53am UTC

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