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 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.
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
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.
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.
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,