CMake variable ROOT_CXX_STANDARD not set


ROOT Version: 6.08.06 - 6.30.06
Platform: Ubuntu 22.04
Compiler: gcc


According to Integrating ROOT into CMake projects - ROOT "Calling find_package(ROOT) makes the following variables available

Variable Type Description
ROOT_INCLUDE_DIRS PATH Include directories for the ROOT installation.
ROOT_LIBRARIES LIST Libraries to link against. The actual list of libraries is composed using the COMPONENTS listed in the find_package(…) command.
ROOT_DEFINITIONS STRING Compile definitions needed to use ROOT.
ROOT_CXX_FLAGS STRING C++ compiler flags used to build ROOT.
ROOT_CC_FLAGS STRING C compiler flags used to build ROOT.
ROOT_CXX_STANDARD STRING C++ standard used to build ROOT.
ROOT__LIBRARY PATH Full path for each of the ROOT libraries listed in COMPONENTS.
ROOT__CMD PATH Full path for each ROOT executable (rootcling, root, hadd, etc.).
ROOT__FOUND BOOL TRUE for each enabled build option (e.g. cocoa, python, xrootd, etc.).
ROOT_FOUND BOOL TRUE if the ROOT package has been found.
ROOT_USE_FILE PATH Path to a CMake module, which makes use of the previous variables and loads modules with useful macros or functions such as ROOT_GENERATE_DICTIONARY

But using a simple test with this CMakeLists.txt file:

#----------------------------------------------------------------------------
# Setup the project
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
project(tmp)

#----------------------------------------------------------------------------
# find the root package (and add COMPONENTS)
find_package(ROOT REQUIRED)

message("ROOT_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}")
message("ROOT_LIBRARIES    ${ROOT_LIBRARIES}")
message("ROOT_CXX_FLAGS    ${ROOT_CXX_FLAGS}")
message("ROOT_CC_FLAGS     ${ROOT_CC_FLAGS}")
if(DEFINED ROOT_CXX_STANDARD)
message("ROOT_CXX_STANDARD ${ROOT_CXX_STANDARD}")
else()
message("ROOT_CXX_STANDARD undefined")
endif()
message("ROOT_FOUND        ${ROOT_FOUND}")
message("ROOT_USE_FILE     ${ROOT_USE_FILE}")

I get the output

ROOT_INCLUDE_DIRS /opt/cern/root/root_v6.30.06/include
ROOT_LIBRARIES    /opt/cern/root/root_v6.30.06/lib/libCore.so;/opt/cern/root/root_v6.30.06/lib/libImt.so;/opt/cern/root/root_v6.30.06/lib/libRIO.so;/opt/cern/root/root_v6.30.06/lib/libNet.so;/opt/cern/root/root_v6.30.06/lib/libHist.so;/opt/cern/root/root_v6.30.06/lib/libGraf.so;/opt/cern/root/root_v6.30.06/lib/libGraf3d.so;/opt/cern/root/root_v6.30.06/lib/libGpad.so;/opt/cern/root/root_v6.30.06/lib/libROOTDataFrame.so;/opt/cern/root/root_v6.30.06/lib/libTree.so;/opt/cern/root/root_v6.30.06/lib/libTreePlayer.so;/opt/cern/root/root_v6.30.06/lib/libRint.so;/opt/cern/root/root_v6.30.06/lib/libPostscript.so;/opt/cern/root/root_v6.30.06/lib/libMatrix.so;/opt/cern/root/root_v6.30.06/lib/libPhysics.so;/opt/cern/root/root_v6.30.06/lib/libMathCore.so;/opt/cern/root/root_v6.30.06/lib/libThread.so;/opt/cern/root/root_v6.30.06/lib/libMultiProc.so;/opt/cern/root/root_v6.30.06/lib/libROOTVecOps.so
ROOT_CXX_FLAGS     -std=c++17 -pipe -fsigned-char -pthread
ROOT_CC_FLAGS     
ROOT_CXX_STANDARD undefined
ROOT_FOUND        1
ROOT_USE_FILE     /opt/cern/root/root_v6.30.06/ROOTUseFile.cmake

So ROOT_CXX_STANDARD is not set. I actually went back to ROOT 6.08.06 and it’s not set there either. I don’t know at which point that variable was removed, but the documentation should be updated to reflect this I think.

Dear @vaubee ,

Thanks for reaching out to the forum!

I am seeing the variable properly populated, i.e.

# I built ROOT beforehand and I sourced it in my environment
$: mkdir tmp && cd tmp
$: cmake . # Using your own example CMakeLists.txt from the first post
[...]
ROOT_INCLUDE_DIRS /home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/include
ROOT_LIBRARIES    /home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libCore.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libImt.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libRIO.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libNet.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libHist.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libGraf.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libGraf3d.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libGpad.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libROOTDataFrame.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libTree.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libTreePlayer.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libRint.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libPostscript.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libMatrix.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libPhysics.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libMathCore.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libThread.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libMultiProc.so;/home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/lib/libROOTVecOps.so
ROOT_CXX_FLAGS     -fdiagnostics-color=always -pipe -fsigned-char -pthread
ROOT_CC_FLAGS     
ROOT_CXX_STANDARD 17
ROOT_FOUND        1
ROOT_USE_FILE     /home/vpadulan/Programs/rootproject/rootinstall/master-e83e0e94a5-relwithdebinfo/cmake/ROOTUseFile.cmake

I went to search for where this variable is being set, and in this file I see it’s just an alias to CMAKE_CXX_STANDARD root/cmake/modules/RootConfiguration.cmake at ffc2cdf94eaa432e42c8a79070abd3d2d391fd2c · root-project/root · GitHub

Can it be that in your case the other variable is not set?

Cheers,
Vincenzo

Hi Vincenzo,

that variable is not set I think, at least I didn’t set it on the command line when I compiled ROOT. And I believe this variable isn’t set automatically by cmake or ROOT’s CMakeLists.txt.

I’m currently trying to re-compile ROOT using the -DCMAKE_CXX_STANDARD=17 flag, to see if that sets it.

Since I can’t control how users compile their ROOT installation, what would be the best way to determine the standard used by the ROOT package found by cmake? I do notice that while for the the ROOT_CXX_FLAGS contain the standard but they do not for your installation.

Cheers,

Vinzenz

Dear @vaubee ,

I did the following reproducible steps, both on a Linux and a MacOS machine, both times I got the variable populated correctly. Please see if you can also reproduce:

$: git clone https://github.com/root-project/root.git rootsrc
$: cmake -S rootsrc -B mybuild
$: cmake --build mybuild -j12
$: source mybuild/bin/thisroot.sh
$: mkdir tmp && cd tmp && vim CMakeLists.txt # with your example from the first post
$: cmake .
ROOT_INCLUDE_DIRS /Users/vpadulan/Programs/rootproject/mybuild/include
ROOT_LIBRARIES    /Users/vpadulan/Programs/rootproject/mybuild/lib/libCore.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libImt.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libRIO.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libNet.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libHist.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libGraf.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libGraf3d.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libGpad.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libROOTDataFrame.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libTree.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libTreePlayer.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libRint.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libPostscript.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libMatrix.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libPhysics.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libMathCore.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libThread.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libMultiProc.so;/Users/vpadulan/Programs/rootproject/mybuild/lib/libROOTVecOps.so
ROOT_CXX_FLAGS     -m64 -pipe -fsigned-char -fno-common -Qunused-arguments -pthread -stdlib=libc++
ROOT_CC_FLAGS
ROOT_CXX_STANDARD 17
ROOT_FOUND        1
ROOT_USE_FILE     /Users/vpadulan/Programs/rootproject/mybuild/ROOTUseFile.cmake

Note that I did not specify the CMAKE_CXX_STANDARD variable anywhere.

Cheers,
Vincenzo

I tried following these steps, but compiling fails with

CMake Error at /opt/cern/root/root-build/interpreter/cling/tools/plugins/clad/clad-prefix/src/clad-stamp/clad-build-Release.cmake:37 (message):
  Command failed: 2

   '/usr/bin/cmake' '--build' '.' '--config' '.'

  See also

    /opt/cern/root/root-build/interpreter/cling/tools/plugins/clad/clad-prefix/src/clad-stamp/clad-build-*.log

And the log file is saying something about a wrong file descriptor.

So instead I tried

git clone https://github.com/root-project/root.git root-latest
cmake -S root-latest -B root-build -Dall=ON -Dcuda=OFF -Dclad=OFF
cmake --build root-build -j12
source root-build/bin/thisroot.sh
mkdir tmp && cd tmp && vim CMakeLists.txt # with your example from the first post
cmake .

and got

ROOT_INCLUDE_DIRS /opt/cern/root/root-build/include
ROOT_LIBRARIES    /opt/cern/root/root-build/lib/libCore.so;/opt/cern/root/root-build/lib/libImt.so;/opt/cern/root/root-build/lib/libRIO.so;/opt/cern/root/root-build/lib/libNet.so;/opt/cern/root/root-build/lib/libHist.so;/opt/cern/root/root-build/lib/libGraf.so;/opt/cern/root/root-build/lib/libGraf3d.so;/opt/cern/root/root-build/lib/libGpad.so;/opt/cern/root/root-build/lib/libROOTDataFrame.so;/opt/cern/root/root-build/lib/libTree.so;/opt/cern/root/root-build/lib/libTreePlayer.so;/opt/cern/root/root-build/lib/libRint.so;/opt/cern/root/root-build/lib/libPostscript.so;/opt/cern/root/root-build/lib/libMatrix.so;/opt/cern/root/root-build/lib/libPhysics.so;/opt/cern/root/root-build/lib/libMathCore.so;/opt/cern/root/root-build/lib/libThread.so;/opt/cern/root/root-build/lib/libMultiProc.so;/opt/cern/root/root-build/lib/libROOTVecOps.so
ROOT_CXX_FLAGS     -pipe -fsigned-char -pthread
ROOT_CC_FLAGS     
ROOT_CXX_STANDARD 17
ROOT_FOUND        1
ROOT_USE_FILE     /opt/cern/root/root-build/ROOTUseFile.cmake

So that works. I’m now going to try the exact same approach using

wget https://root.cern/download/root_v6.30.06.source.tar.gz
tar -xzf root_v6.30.06.source.tar.gz
cmake -S root-6.30.06 -B root_v6.30.06 -Dall=ON -Dcuda=OFF -Dclad=OFF
cmake -S root-6.30.06 -B root_v6.30.06 -Dall=ON -Dcuda=OFF -Dclad=OFF
cmake --build root_v6.30.06 -j12

and will report back once that is done.
In this case for some reason the cmake configuration step has to be done twice, since the first one fails with

-- Enabled support for:  arrow asimage builtin_clang builtin_cling builtin_cppzmq builtin_davix builtin_gl2ps builtin_llvm builtin_openui5 builtin_tbb builtin_unuran builtin_vdt builtin_veccore builtin_xxhash builtin_zeromq cefweb cuda dataframe davix fftw3 fitsio fortran gdml gviz http imt mathmore mlp mysql opengl proof pyroot qt5web roofit roofit_multiprocess webgui root7 rpath runtime_cxxmodules shadowpw shared ssl tmva tmva-cpu tmva-pymva spectrum unuran vdt veccore x11 xml xrootd
-- Configuring done (35.6s)
CMake Error: CMake can not determine linker language for target: RooBatchCompute_CUDA
CMake Error in roofit/batchcompute/CMakeLists.txt:
  Exporting the target "RooBatchCompute_CUDA" is not allowed since its linker
  language cannot be determined


CMake Error: Cannot determine link language for target "RooBatchCompute_CUDA".
CMake Error in roofit/batchcompute/CMakeLists.txt:
  Exporting the target "RooBatchCompute_CUDA" is not allowed since its linker
  language cannot be determined


-- Generating done (4.8s)
CMake Generate step failed.  Build files cannot be regenerated correctly.

Notice the enable support for cuda despite the -Dcuda=OFF flag. Running the same command again resolves the issue (no more enabled support for cuda).

Dear @vaubee ,

Ok so my understanding is that you confirm the ROOT_CXX_FLAGS variable works as expected, that is good to know.

The problems related to clad and cuda are not related to your initial question in this post (e.g. it would have been equivalent to run cmake -Dminimal=ON). For the part related to RooFit, I believe @jonas will be able to give some more information. Since it is a different problem, I would suggest to move the conversation to a separate post. I suspect there is something unique to your system that is causing this issue, could you give us more information about it?

Cheers,
Vincenzo

Hi!

Better don’t use -Dall=ON. It will enable cuda=ON implicitly and even override your choice of setting it to OFF! I have fixed this behavior for the upcoming ROOT 6.32, but unfortunately we have to live with it in the old releases.

Avoid clad: it’s okay to disable it, you’re probably not using it anyway, right?

Sorry, yes, I agree that the issues using cmake should maybe in another issue, but since I wanted to check if your approach would work for me as well, I thought it best to document these issues in case someone else stumbles across this.
I have now tried the same approach with the downloaded tar-file and it does not work:

ROOT_INCLUDE_DIRS /opt/cern/root/root_v6.30.06/include
ROOT_LIBRARIES    /opt/cern/root/root_v6.30.06/lib/libCore.so;/opt/cern/root/root_v6.30.06/lib/libImt.so;/opt/cern/root/root_v6.30.06/lib/libRIO.so;/opt/cern/root/root_v6.30.06/lib/libNet.so;/opt/cern/root/root_v6.30.06/lib/libHist.so;/opt/cern/root/root_v6.30.06/lib/libGraf.so;/opt/cern/root/root_v6.30.06/lib/libGraf3d.so;/opt/cern/root/root_v6.30.06/lib/libGpad.so;/opt/cern/root/root_v6.30.06/lib/libROOTDataFrame.so;/opt/cern/root/root_v6.30.06/lib/libTree.so;/opt/cern/root/root_v6.30.06/lib/libTreePlayer.so;/opt/cern/root/root_v6.30.06/lib/libRint.so;/opt/cern/root/root_v6.30.06/lib/libPostscript.so;/opt/cern/root/root_v6.30.06/lib/libMatrix.so;/opt/cern/root/root_v6.30.06/lib/libPhysics.so;/opt/cern/root/root_v6.30.06/lib/libMathCore.so;/opt/cern/root/root_v6.30.06/lib/libThread.so;/opt/cern/root/root_v6.30.06/lib/libMultiProc.so;/opt/cern/root/root_v6.30.06/lib/libROOTVecOps.so
ROOT_CXX_FLAGS     -std=c++17 -pipe -fsigned-char -pthread
ROOT_CC_FLAGS     
ROOT_CXX_STANDARD undefined
ROOT_FOUND        1
ROOT_USE_FILE     /opt/cern/root/root_v6.30.06/ROOTUseFile.cmake

So is this something that has been changed since v6.30.06? Or does it something have to do with being a tar-file instead of a git-repositiory? I’ve checked out tag v6-30-06 and am now compiling that, once that’s done I will post the result.

@jonas, thanks for the explanation, I didn’t know that an earlier -Dall=ON overwrites the later flags. I’m guessing this happens only for the first pass, that’s why it works when running it twice? Listing all components by hand instead of using -Dall=ON is a bit annoying, but it only has to be done once, so that’s not too bad. Thanks for fixing it in the upcoming versions.

So I after compiling the git repository with git tag v6-30-06 checked out, I get the same result I get using the downloaded tar-file, ROOT_CXX_STANDARD undefined. So it seems this is something that has been changed between v6-30-06 and the current head of the repository.
One difference I see is in cmake/scripts/ROOTConfig.cmake.in where the current version has the lines

  #-----------------------------------------------------------------------                               |  -------------------------------------------------------------------------------------------------------
  # Provide the C++ standard used by this build of ROOT                                                  |  -------------------------------------------------------------------------------------------------------
  #                                                                                                      |  -------------------------------------------------------------------------------------------------------
  set(ROOT_CXX_STANDARD @CMAKE_CXX_STANDARD@)                                                            |  -------------------------------------------------------------------------------------------------------

added.
So it seems this issue has been addressed in the newer versions. I checked and this was brought up on github (Provide in the cmake configuration the C++ standard which was used to compile ROOT · Issue #7644 · root-project/root · GitHub) which seems to have prompted the fix.

I guess the lesson is to not just check the root forum but also the github issues.