FindROOT.cmake not found by old (5.34) ROOT versions

Dear ROOTers,

I am experiencing an issue with cmake’s find_package command when using two different ROOT versions.
I wrote a CMakeLists.txt file to build a project relying on ROOT, you can find it here (the project is in the same git repository).

If I use ROOT v6.20.04 I can build successfully both on Ubuntu 20.04 and on macOS Catalina 10.15.5.
If I instead use SL7 or macOS 10.13.6 with an older ROOT version 5.34.36 I get this complaint:

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

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

    ROOTConfig.cmake
    root-config.cmake

it seems that for old root versions cmake is not able to locate the root-config.cmake or ROOTConfig.cmake within ROOT.
I also tried to set explicitly

set(CMAKE_MODULE_PATH $ENV{ROOTSYS})

or

set(CMAKE_MODULE_PATH $ENV{ROOTSYS}/cmake)

but it does not work.
Could you help me? Is there some cmake feature related to this that was modified in the latest versions?

Thanks a lot,

Cosimo

Can you check that there is a ROOTConfig.cmake file in the ${ROOTSYS}/cmake directory of ROOT v5.34.36?

There is a ROOTConfig.cmake.in within $ROOTSYS/cmake/scripts.

OK, I’ll check if I find something…

So it works for me (on Windows) if I simply properly set ${ROOTSYS} in the environment, before calling CMake

Thanks a lot for trying,
which root version are you using?
I think the problem might be that the old root versions that I was using were NOT compiled with cmake and therefore the ROOTConfig.cmake.in was never turned in a proper ROOTConfig.cmake with all the cmake variables between @variable@ explicited.

Both ROOT 6 (master) and ROOT 5 (latest)

That might well be…

I can confirm that the problem was due to ROOT not being compiled with cmake.
If you do so the ROOTConfig.cmake will be generated in the ROOTSYS directory itself.
The error I am getting now is

-- Required ROOT components are: Minuit
CMake Error at CMakeLists.txt:21 (root_generate_dictionary):
  Unknown CMake command "root_generate_dictionary".


-- Configuring incomplete, errors occurred!

But now I am sure find_package has worked.
Any hint on why root_generate_dictionary is not recognised, it was already there in ROOT 5.34.36 right?

I tried both to
export ROOT_DIR=$ROOTSYS
before compiling and also to use the extra argument
-DCMAKE_MODULE_PATH=$ROOTSYS
but still the command root_generate_dictionary is not found.

Sorry to keep annoying you, now I managed to perform the configuring step with

[cnigro@mic01 gLike_build]$ cmake ../gLike -DCMAKE_MODULE_PATH=$ROOTSYS/etc/cmake
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /bin/cc
-- Check for working C compiler: /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: /bin/c++
-- Check for working CXX compiler: /bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ROOT: /nfs/magic-ifae01/cnigro/software/root_v5.34.36/root_build/bin/root-config  
-- Required ROOT components are: Minuit
-- Configuring done
-- Generating done
-- Build files have been written to: /nfs/magic-ifae01/cnigro/work/gLike_build

but the building fails with

[cnigro@mic01 gLike_build]$ make
make[2]: *** No rule to make target `linkFile-NOTFOUND', needed by `gLikeDict.cxx'.  Stop.
make[1]: *** [CMakeFiles/gLike.dir/all] Error 2
make: *** [all] Error 2

which exact ROOT 5 version were you using @bellenot?
And thanks again for your help.

HEAD of v5-34-00-patches, configured and built with CMake on Windows

Hi @bellenot can I abuse of your patience and ask you if you have any hint on the errors I described in my 2 previous posts?
I have re-built root 5.34.36 with cmake.
If I simply do

[cnigro@mic03 gLike_build]$ cmake ../gLike 
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /bin/cc
-- Check for working C compiler: /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: /bin/c++
-- Check for working CXX compiler: /bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Required ROOT components are: Minuit
CMake Error at CMakeLists.txt:21 (root_generate_dictionary):
  Unknown CMake command "root_generate_dictionary".


-- Configuring incomplete, errors occurred!
See also "/nfs/magic-ifae01/cnigro/work/gLike_build/CMakeFiles/CMakeOutput.log".

I get stuck at configuration.

If I instead specify `-DCMAKE_MODULE_PATH=$ROOTSYS/etc/cmake the configuration goes well

[cnigro@mic03 gLike_build]$ cmake ../gLike -DCMAKE_MODULE_PATH=$ROOTSYS/etc/cmake
-- Found ROOT: /nfs/magic-ifae01/cnigro/software/root_v5.34.36/root_build/bin/root-config  
-- Required ROOT components are: Minuit
-- Configuring done
-- Generating done
-- Build files have been written to: /nfs/magic-ifae01/cnigro/work/gLike_build

but the compilation fails

[cnigro@mic03 gLike_build]$ make
make[2]: *** No rule to make target `linkFile-NOTFOUND', needed by `gLikeDict.cxx'.  Stop.
make[1]: *** [CMakeFiles/gLike.dir/all] Error 2
make: *** [all] Error 2

Sorry and thanks a lot for having checked, if you cannot help anymore I’ll close the issue.

Cosimo

I’ll check Tomorrow on a Linux node, but this will take some time. I’ll keep you updated

So it works just fine for me with ROOT v5-34-00-patches on CentOS 7:
My CMakeLists.txt:

# Check if cmake has the required version
CMAKE_MINIMUM_REQUIRED(VERSION 3.16.4 FATAL_ERROR)

set(PROJECT_NAME sclock)
project(${PROJECT_NAME})

find_package(ROOT REQUIRED)

set(CMAKE_CXX_FLAGS "${ROOT_CXX_FLAGS}")

if(MSVC)
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -SUBSYSTEM:WINDOWS -ENTRY:mainCRTStartup")
  set(RC_FILE ${PROJECT_NAME}.rc)
  set(EXTRA_LIBS Winmm.lib)
else()
  set(EXTRA_LIBS -lThread -L/usr/X11R6/lib -lX11)
endif()

include(${ROOT_USE_FILE})
include_directories(${ROOT_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR})
link_directories(${ROOT_LIBRARY_DIR})

configure_file(${CMAKE_SOURCE_DIR}/bell.wav     ${CMAKE_BINARY_DIR}/bell.wav COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/cenobyte.ttf ${CMAKE_BINARY_DIR}/cenobyte.ttf COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/clock1.png   ${CMAKE_BINARY_DIR}/clock1.png COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/toll_a.mp3   ${CMAKE_BINARY_DIR}/toll_a.mp3 COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/toll_b.mp3   ${CMAKE_BINARY_DIR}/toll_b.mp3 COPYONLY)

# create dictonary
ROOT_GENERATE_DICTIONARY(${PROJECT_NAME}Dict TGShapedClock.h LINKDEF LinkDef.h)

add_executable(${PROJECT_NAME} TGShapedClock.cxx ${PROJECT_NAME}Dict.cxx ${RC_FILE})
set_target_properties(${PROJECT_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
target_link_libraries(${PROJECT_NAME} ${ROOT_LIBRARIES} Gui Thread ${EXTRA_LIBS})

And the CMake configure/make result:

[bellenot@bbcc7x64 build]$ cmake -DCMAKE_VERBOSE_MAKEFILE=ON ../
-- The C compiler identification is GNU 6.2.0
-- The CXX compiler identification is GNU 6.2.0
-- Check for working C compiler: /cvmfs/sft.cern.ch/lcg/releases/gcc/6.2.0-b9934/x86_64-centos7/bin/gcc
-- Check for working C compiler: /cvmfs/sft.cern.ch/lcg/releases/gcc/6.2.0-b9934/x86_64-centos7/bin/gcc - 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: /cvmfs/sft.cern.ch/lcg/releases/gcc/6.2.0-b9934/x86_64-centos7/bin/g++
-- Check for working CXX compiler: /cvmfs/sft.cern.ch/lcg/releases/gcc/6.2.0-b9934/x86_64-centos7/bin/g++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found GCC. Major version 6, minor version 2
-- CMAKE_BUILD_TYPE: RelWithDebInfo
-- Performing Test CXX_HAS_Wno-array-bounds
-- Performing Test CXX_HAS_Wno-array-bounds - Success
-- Performing Test CXX_HAS_Wno-strict-aliasing
-- Performing Test CXX_HAS_Wno-strict-aliasing - Success
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found a 64bit system
-- Found GNU compiler collection
-- Performing Test CXX_HAS_Wno_deprecated_declarations
-- Performing Test CXX_HAS_Wno_deprecated_declarations - Success
-- ROOT Platform: linux
-- ROOT Architecture: linuxx8664gcc
-- Build Type: RelWithDebInfo
-- Compiler Flags:  -pipe -m64 -Wall -W -Woverloaded-virtual -fPIC -pthread -Wno-deprecated-declarations -pipe -m64 -Wall -W -Woverloaded-virtual -fPIC -pthread -Wno-deprecated-declarations -O2 -g -DNDEBUG
-- Configuring done
-- Generating done
-- Build files have been written to: /home/bellenot/rootdev/test_cmake/SClock/build
[bellenot@bbcc7x64 build]$
[bellenot@bbcc7x64 build]$ make
/usr/bin/cmake -S/home/bellenot/rootdev/test_cmake/SClock -B/home/bellenot/rootdev/test_cmake/SClock/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/bellenot/rootdev/test_cmake/SClock/build/CMakeFiles /home/bellenot/rootdev/test_cmake/SClock/build/CMakeFiles/progress.marks
make  -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/bellenot/rootdev/test_cmake/SClock/build'
make  -f CMakeFiles/sclock.dir/build.make CMakeFiles/sclock.dir/depend
make[2]: Entering directory `/home/bellenot/rootdev/test_cmake/SClock/build'
[ 25%] Generating sclockDict.cxx, sclockDict.h
/home/bellenot/bin/root/v5-34-00-patches/bin/rootcint -cint -f sclockDict.cxx -c -I/home/bellenot/rootdev/test_cmake/SClock/inc -I/home/bellenot/rootdev/test_cmake/SClock -I/home/bellenot/bin/root/v5-34-00-patches/include TGShapedClock.h /home/bellenot/rootdev/test_cmake/SClock/LinkDef.h
cd /home/bellenot/rootdev/test_cmake/SClock/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/bellenot/rootdev/test_cmake/SClock /home/bellenot/rootdev/test_cmake/SClock /home/bellenot/rootdev/test_cmake/SClock/build /home/bellenot/rootdev/test_cmake/SClock/build /home/bellenot/rootdev/test_cmake/SClock/build/CMakeFiles/sclock.dir/DependInfo.cmake --color=
Scanning dependencies of target sclock
make[2]: Leaving directory `/home/bellenot/rootdev/test_cmake/SClock/build'
make  -f CMakeFiles/sclock.dir/build.make CMakeFiles/sclock.dir/build
make[2]: Entering directory `/home/bellenot/rootdev/test_cmake/SClock/build'
[ 50%] Building CXX object CMakeFiles/sclock.dir/TGShapedClock.cxx.o
/cvmfs/sft.cern.ch/lcg/releases/gcc/6.2.0-b9934/x86_64-centos7/bin/g++   -I/home/bellenot/rootdev/test_cmake/SClock -I/home/bellenot/bin/root/v5-34-00-patches/include  -pipe -m64 -Wall -W -Woverloaded-virtual -fPIC -pthread -Wno-deprecated-declarations -pipe -m64 -Wall -W -Woverloaded-virtual -fPIC -pthread -Wno-deprecated-declarations -O2 -g -DNDEBUG   -o CMakeFiles/sclock.dir/TGShapedClock.cxx.o -c /home/bellenot/rootdev/test_cmake/SClock/TGShapedClock.cxx
/home/bellenot/rootdev/test_cmake/SClock/TGShapedClock.cxx: In member function ‘virtual Bool_t TGShapedClock::HandleKey(Event_t*)’:
/home/bellenot/rootdev/test_cmake/SClock/TGShapedClock.cxx:413:11: warning: variable ‘n’ set but not used [-Wunused-but-set-variable]
    Int_t  n;
           ^
/home/bellenot/rootdev/test_cmake/SClock/TGShapedClock.cxx: In member function ‘virtual void TGShapedClock::Sound(const char*, Long_t)’:
/home/bellenot/rootdev/test_cmake/SClock/TGShapedClock.cxx:538:39: warning: unused parameter ‘fname’ [-Wunused-parameter]
 void TGShapedClock::Sound(const char *fname, Long_t ntimes)
                                       ^~~~~
[ 75%] Building CXX object CMakeFiles/sclock.dir/sclockDict.cxx.o
/cvmfs/sft.cern.ch/lcg/releases/gcc/6.2.0-b9934/x86_64-centos7/bin/g++   -I/home/bellenot/rootdev/test_cmake/SClock -I/home/bellenot/bin/root/v5-34-00-patches/include  -pipe -m64 -Wall -W -Woverloaded-virtual -fPIC -pthread -Wno-deprecated-declarations -pipe -m64 -Wall -W -Woverloaded-virtual -fPIC -pthread -Wno-deprecated-declarations -O2 -g -DNDEBUG   -Wno-strict-aliasing -o CMakeFiles/sclock.dir/sclockDict.cxx.o -c /home/bellenot/rootdev/test_cmake/SClock/build/sclockDict.cxx
[100%] Linking CXX executable sclock
/usr/bin/cmake -E cmake_link_script CMakeFiles/sclock.dir/link.txt --verbose=1
/cvmfs/sft.cern.ch/lcg/releases/gcc/6.2.0-b9934/x86_64-centos7/bin/g++   -pipe -m64 -Wall -W -Woverloaded-virtual -fPIC -pthread -Wno-deprecated-declarations -pipe -m64 -Wall -W -Woverloaded-virtual -fPIC -pthread -Wno-deprecated-declarations -O2 -g -DNDEBUG   CMakeFiles/sclock.dir/TGShapedClock.cxx.o CMakeFiles/sclock.dir/sclockDict.cxx.o  -o sclock   -L/home/bellenot/bin/root/v5-34-00-patches/lib  -Wl,-rpath,/home/bellenot/bin/root/v5-34-00-patches/lib /home/bellenot/bin/root/v5-34-00-patches/lib/libCore.so /home/bellenot/bin/root/v5-34-00-patches/lib/libCint.so /home/bellenot/bin/root/v5-34-00-patches/lib/libRIO.so /home/bellenot/bin/root/v5-34-00-patches/lib/libNet.so /home/bellenot/bin/root/v5-34-00-patches/lib/libHist.so /home/bellenot/bin/root/v5-34-00-patches/lib/libGraf.so /home/bellenot/bin/root/v5-34-00-patches/lib/libGraf3d.so /home/bellenot/bin/root/v5-34-00-patches/lib/libGpad.so /home/bellenot/bin/root/v5-34-00-patches/lib/libTree.so /home/bellenot/bin/root/v5-34-00-patches/lib/libRint.so /home/bellenot/bin/root/v5-34-00-patches/lib/libPostscript.so /home/bellenot/bin/root/v5-34-00-patches/lib/libMatrix.so /home/bellenot/bin/root/v5-34-00-patches/lib/libPhysics.so /home/bellenot/bin/root/v5-34-00-patches/lib/libMathCore.so /home/bellenot/bin/root/v5-34-00-patches/lib/libThread.so /home/bellenot/bin/root/v5-34-00-patches/lib/libGui.so -lThread -L/usr/X11R6/lib -lX11 /home/bellenot/bin/root/v5-34-00-patches/lib/libGpad.so /home/bellenot/bin/root/v5-34-00-patches/lib/libGraf.so /home/bellenot/bin/root/v5-34-00-patches/lib/libHist.so /home/bellenot/bin/root/v5-34-00-patches/lib/libMatrix.so /home/bellenot/bin/root/v5-34-00-patches/lib/libRIO.so /home/bellenot/bin/root/v5-34-00-patches/lib/libThread.so /home/bellenot/bin/root/v5-34-00-patches/lib/libMathCore.so /home/bellenot/bin/root/v5-34-00-patches/lib/libCore.so /home/bellenot/bin/root/v5-34-00-patches/lib/libCint.so
make[2]: Leaving directory `/home/bellenot/rootdev/test_cmake/SClock/build'
[100%] Built target sclock
make[1]: Leaving directory `/home/bellenot/rootdev/test_cmake/SClock/build'
/usr/bin/cmake -E cmake_progress_start /home/bellenot/rootdev/test_cmake/SClock/build/CMakeFiles 0
[bellenot@bbcc7x64 build]$

Note that I installed ROOT (with make install) after building it, and then executed: source ~/bin/root/v5-34-00-patches/bin/thisroot.csh

And here is the content of ${ROOTSYS}/cmake:

[bellenot@bbcc7x64 build]$ ls ${ROOTSYS}/cmake/
modules           ROOTConfig-targets.cmake                 ROOTConfig-version.cmake
ROOTConfig.cmake  ROOTConfig-targets-relwithdebinfo.cmake  ROOTUseFile.cmake
[bellenot@bbcc7x64 build]$
1 Like

Thanks a lot for your help @bellenot.
I added this line to my CMakeLists.txt

(that points to $ROOTSYS/ROOTUseFile.cmake), and the compilation with ROOT 5.34.36 worked fine.
Maybe in the new ROOT versions this file is automatically found by CMAKE.
I am marking your previous answer as solution!
Cheers,

Cosimo

1 Like

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