Adding a class to ROOT still an issue

Exactly one year later in version 6.26, this is still an issue.

I thought that it was/is a key feature in ROOT/CLING.

Yup, and I found out and since forgot why this doesn’t work. I’ll revive this, thanks for the ping!

But Axel, could it be that nobody else bugs you because creating your own classes and linking them to ROOT with dictionaries etc has become a very difficult task. There is as was pointed out by Maarten Ballintijn in 2018 no decent documentation about cmake.
For instance, how can you access/include the ROOT modules. I asked that question also a year ago on the forum and no solution. So I resort to hacks like:
set (CMAKE_MODULE_PATH “/Users/eddyo/src/root-6.26.00/cmake/modules”)

That we have an answer on! We have rewritten large parts of the ROOT manual, and it should now have exactly what you’re after: Integrating ROOT into CMake projects - ROOT

Can you let me know if anything is unclear or doesn’t work?

It took the ROOT team about 10 years to get a cmake environment going and now a ROOT user gets all this knowledge condensed in barely one page …

Let’s start by saying that I am very grateful to Henry Schreiner for putting those tutorial pages together, it was a life saver but also these pages have not kept up with
the changes/ additions that were made in the root package. For instance no
mention of the “ROOT_STANDARD_LIBRARY_PACKAGE” macro that takes
care of many things.

The one-page ROOT with cmake explainer refers to the “Full example”. It turns out
to be a screen shot of a CMakeLists.txt file in the ROOT test directory. I could
not find any reference to it and the actual file in the test directory has changed
(I must definitely have missed here something ?!).

So if this CMakeLists.txt file is to help a user to create an external project
using ROOT libraries, it should at least survive the following test. Copy the
test directory completely out of the ROOT directory and run cmake. To be
fair I removed all the other projects and left just “Event”:

# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.
# All rights reserved.
#
# For the licensing terms see $ROOTSYS/LICENSE.
# For the list of contributors see $ROOTSYS/README/CREDITS.

# CMakeLists.txt for the ROOT test programs.
# This shows nicely how to compile and link applications
# using the ROOT libraries on all supported platforms.
#
# Author: Pere Mato, 25/10/2010
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)

project(test)

# Sergey: make no sence while CMakeLists.txt file cannot be used separately from ROOT
# but variables like ROOT_asimage_FOUND used here and produced in ROOTConfig.cmake
find_package(ROOT REQUIRED)

#---Copy the CTestCustom.cmake file into the build directory---------------------------------
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
enable_testing()

if(CMAKE_SYSTEM_NAME MATCHES Darwin)
  # To avoid to set ld_Library_path to locate the test libraries
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,@loader_path/.")
endif()

if(DEFINED ROOT_SOURCE_DIR)
  # Testing using the binary tree
  set(ROOT_root_CMD ${ROOT_BINDIR}/root.exe)
else()
  # Testing using an installation (assuming access to ROOT CMake modules)
  include_directories(${ROOT_INCLUDE_DIRS})
  include_directories(${ROOT_INCLUDE_DIRS}/../tutorials)
  add_definitions(${ROOT_DEFINITIONS})
  include(RootMacros)
endif()

#---environment-------------------------------------------------------------------------------
ROOT_ADD_TEST(show-environment COMMAND ${CMAKE_COMMAND} -E environment)

#---event-------------------------------------------------------------------------------------
ROOT_STANDARD_LIBRARY_PACKAGE(Event
                              NO_INSTALL_HEADERS
                              HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Event.h
                              SOURCES Event.cxx LINKDEF EventLinkDef.h
                              DEPENDENCIES Hist MathCore)
if(MSVC)
  if(NOT runtime_cxxmodules)
    add_custom_command(TARGET Event POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/libEvent_rdict.pcm
                                       ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/libEvent_rdict.pcm)
  else()
    add_custom_command(TARGET Event POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/Event.pcm
                                     ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/Event.pcm)
  endif()
endif()
ROOT_EXECUTABLE(eventexe MainEvent.cxx LIBRARIES Event RIO Tree TreePlayer Hist Net)
ROOT_ADD_TEST(test-event COMMAND eventexe)

That does not work

eddyo@MacBook-Pro-2019 root-test % cmake -S . -B build
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:37 (include):
  include could not find requested file:

    RootMacros

And looking at my original module path question, this error is not helpful :wink:

The other part of the one-pager is a list of cmake ROOT variables, most of them are not
used in the event example.

As a user I would like to know whether I should use

include(CheckCompiler)

to make sure that I am using the same compiler/linker etc.

In summary, I really would like ROOT/cmake documentation

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