From 73a0229aa3ab6fa32d26ca19c805f734afcbc4d2 Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Sun, 20 Sep 2026 09:57:01 +0200 Subject: [PATCH 1/2] Get rid of wrapper script for creating ROOT dictionaries The sole need for the wrapper was to properly handle warnings and complain on missing options. Since long rootcling is now gracefully handling both, so we remove the wrapper. --- cmake/AddRootDictionary.cmake | 47 +++++++----- cmake/RunRootcling.cmake | 57 ++++++++++++++ cmake/rootcling_wrapper.sh.in | 138 ---------------------------------- packaging/CMakeLists.txt | 11 +-- 4 files changed, 88 insertions(+), 165 deletions(-) create mode 100644 cmake/RunRootcling.cmake delete mode 100755 cmake/rootcling_wrapper.sh.in diff --git a/cmake/AddRootDictionary.cmake b/cmake/AddRootDictionary.cmake index 16cbdec222043..f088a86709910 100644 --- a/cmake/AddRootDictionary.cmake +++ b/cmake/AddRootDictionary.cmake @@ -11,8 +11,7 @@ include_guard() -configure_file(${CMAKE_CURRENT_LIST_DIR}/rootcling_wrapper.sh.in - ${CMAKE_BINARY_DIR}/rootcling_wrapper.sh @ONLY) +set(O2_RUN_ROOTCLING_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/RunRootcling.cmake) # # add_root_dictionary generates one dictionary to be added to a target. @@ -119,7 +118,9 @@ function(add_root_dictionary target) # get the list of compile_definitions set(prop $) - # Build the LD_LIBRARY_PATH required to get rootcling running fine + # Build the LD_LIBRARY_PATH required to get rootcling running fine. It + # REPLACES the inherited value, so RunRootcling.cmake applies it to rootcling + # only: putting it on cmake itself hides cmake's own OpenSSL (see #12683). # # Need at least root core library get_filename_component(LD_LIBRARY_PATH ${ROOT_Core_LIBRARY} DIRECTORY) @@ -132,25 +133,37 @@ function(add_root_dictionary target) set(includeDirs $) set(includeDirs $) - list(LENGTH A_EXTRA_PATCH hasExtraPatch) - # add a custom command to generate the dictionary using rootcling + # the pcm dependencies (-m) are only meaningful where the modules are actually + # loaded from disk, which is not the case on macOS + set(pcmDeps $>) + if(APPLE) + set(pcmDeps) + endif() + + if(A_EXTRA_PATCH) + set(extraPatch -DPATCH=${CMAKE_CURRENT_LIST_DIR}/${A_EXTRA_PATCH}) + else() + set(extraPatch) + endif() + + # the arguments are joined with | so that they reach the script as a single + # argument, see RunRootcling.cmake # cmake-format: off + set(rootclingArgs + -f|${dictionaryFile}|-inlineInputHeader|-noGlobalUsingStd|-rmf|${rootmapFile}|-rml|$|-I$$<$:|-D$>$<$:|-m|$>|$) + + # add a custom command to generate the dictionary using rootcling add_custom_command( OUTPUT ${dictionaryFile} ${pcmFile} ${rootmapFile} VERBATIM COMMAND - ${CMAKE_BINARY_DIR}/rootcling_wrapper.sh - --rootmap_file ${rootmapFile} - --dictionary_file ${dictionaryFile} - --ld_library_path ${LD_LIBRARY_PATH} - --rootmap_library_name $ - --include_dirs -I$-I> - $<$:--compile_defs> - $<$:-D$-D>> - $<$:--extra-patch> - $<$:${CMAKE_CURRENT_LIST_DIR}/${A_EXTRA_PATCH}> - --pcmdeps "$>" - --headers "${headers}" + ${CMAKE_COMMAND} + -DROOTCLING=${ROOT_rootcling_CMD} + -DDICTIONARY=${dictionaryFile} + "-DLD_LIBRARY_PATH=${LD_LIBRARY_PATH}" + ${extraPatch} + "-DARGS=${rootclingArgs}" + -P ${O2_RUN_ROOTCLING_SCRIPT} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${pcmBase} ${pcmFile} DEPENDS ${headers} "$>" ${A_EXTRA_PATCH}) diff --git a/cmake/RunRootcling.cmake b/cmake/RunRootcling.cmake new file mode 100644 index 0000000000000..b2d7d74860f33 --- /dev/null +++ b/cmake/RunRootcling.cmake @@ -0,0 +1,57 @@ +# Copyright 2019-2020 CERN and copyright holders of ALICE O2. +# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +# All rights not expressly granted are reserved. +# +# This software is distributed under the terms of the GNU General Public +# License v3 (GPL Version 3), copied verbatim in the file "COPYING". +# +# In applying this license CERN does not waive the privileges and immunities +# granted to it by virtue of its status as an Intergovernmental Organization +# or submit itself to any jurisdiction. + +# Runs rootcling, optionally appends PATCH to the generated dictionary, and +# turns the "Unused class rule" warning into an error. +# +# rootcling only offers -failOnWarnings, which is all or nothing, so the +# output still has to be inspected to single out that one warning. +# +# ARGS is separated by | rather than ; so that it survives as a single +# argument through add_custom_command. + +if(NOT ROOTCLING OR NOT ARGS OR NOT DICTIONARY) + message(FATAL_ERROR "ROOTCLING, ARGS and DICTIONARY must all be given") +endif() + +# Applied to rootcling only: it replaces rather than extends the inherited +# value, and cmake itself needs libraries it does not list. +if(LD_LIBRARY_PATH) + set(rootclingCmd ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${LD_LIBRARY_PATH} ${ROOTCLING}) +else() + set(rootclingCmd ${ROOTCLING}) +endif() + +string(REPLACE "|" ";" rootclingArgs "${ARGS}") + +execute_process(COMMAND ${rootclingCmd} ${rootclingArgs} + OUTPUT_VARIABLE output + ERROR_VARIABLE output + RESULT_VARIABLE status) + +if(output) + message("${output}") +endif() + +if(NOT status EQUAL 0) + file(REMOVE ${DICTIONARY}) + message(FATAL_ERROR "rootcling failed for ${DICTIONARY} with error code ${status}") +endif() + +if(output MATCHES "Warning: Unused class rule") + file(REMOVE ${DICTIONARY}) + message(FATAL_ERROR "please fix the warnings above about unused class rule") +endif() + +if(PATCH) + file(READ ${PATCH} patchContent) + file(APPEND ${DICTIONARY} "${patchContent}") +endif() diff --git a/cmake/rootcling_wrapper.sh.in b/cmake/rootcling_wrapper.sh.in deleted file mode 100755 index d5417c867bc38..0000000000000 --- a/cmake/rootcling_wrapper.sh.in +++ /dev/null @@ -1,138 +0,0 @@ -#!/bin/bash -e - -# rootcling_wrapper.sh -- wrap call to rootcling to trap some warnings -# we want to treat as errors : -# -# Warning: Unused class rule -# -# - -while [[ $# -gt 0 ]]; do - case "$1" in - --rootmap_library_name) - ROOTMAP_LIBRARY_NAME="$2" - shift 2 - ;; - --include_dirs) - INCLUDE_DIRS="$2" - shift 2 - ;; - --compile_defs) - COMPILE_DEFINITIONS="$2" - shift 2 - ;; - --headers) - HEADERS="$2" - shift 2 - ;; - --ld_library_path) - libpath="$2" - shift 2 - ;; - --dictionary_file) - DICTIONARY_FILE="$2" - shift 2 - ;; - --rootmap_file) - ROOTMAP_FILE="$2" - shift 2 - ;; - --pcmdeps) - PCMDEPS="$2" - shift 2 - ;; - --extra-patch) - EXTRA_PATCH="$2" - shift 2 - ;; - *) - if [[ -z "$1" ]]; then - shift - else - echo "Parameter unknown: $1" >&2 - exit 1 - fi - ;; - esac -done - -if [[ ! $ROOTMAP_LIBRARY_NAME ]]; then - echo "--rootmap_library_name option is mandatory but was not given" >&2 - exit 1 -fi - -if [[ ! $INCLUDE_DIRS ]]; then - echo "--include_dirs option is mandatory but was not given" >&2 - exit 1 -fi - -if [[ ! $DICTIONARY_FILE ]]; then - echo "--dictionary_file option is mandatory but was not given" >&2 - exit 1 -fi - -if [[ ! $ROOTMAP_FILE ]]; then - echo "--rootmap_file option is mandatory but was not given" >&2 - exit 1 -fi - -case $OSTYPE in - darwin*) - unset PCMDEPS - ;; - *) - ;; -esac - -LOGFILE=${DICTIONARY_FILE}.log - -echo @CMAKE_COMMAND@ -E env "LD_LIBRARY_PATH=$libpath" @ROOT_rootcling_CMD@ \ - -f $DICTIONARY_FILE \ - -inlineInputHeader \ - -noGlobalUsingStd \ - -rmf ${ROOTMAP_FILE} \ - -rml ${ROOTMAP_LIBRARY_NAME} \ - ${INCLUDE_DIRS//;/ } \ - ${COMPILE_DEFINITIONS//;/ } \ - ${PCMDEPS:+-m }${PCMDEPS//;/ -m } \ - ${HEADERS//;/ } \ - > ${LOGFILE} 2>&1 || ROOTCLINGRETVAL=$? - -@CMAKE_COMMAND@ -E env "LD_LIBRARY_PATH=$libpath" @ROOT_rootcling_CMD@ \ - -f $DICTIONARY_FILE \ - -inlineInputHeader \ - -noGlobalUsingStd \ - -rmf ${ROOTMAP_FILE} \ - -rml ${ROOTMAP_LIBRARY_NAME} \ - ${INCLUDE_DIRS//;/ } \ - ${COMPILE_DEFINITIONS//;/ } \ - ${PCMDEPS:+-m }${PCMDEPS//;/ -m } \ - ${HEADERS//;/ } \ - > ${LOGFILE} 2>&1 || ROOTCLINGRETVAL=$? - -# Add the extra patch file at the end of the generated dictionary. -# This is needed to inject custom streamers (e.g. for std::vector) -# to our dictionary. -if [ ! X"${EXTRA_PATCH}" = X ]; then - cat $EXTRA_PATCH >> ${DICTIONARY_FILE} -fi - -if [[ ${ROOTCLINGRETVAL:-0} != "0" ]]; then - cat ${LOGFILE} >&2 - rm -f $DICTIONARY_FILE - echo "ROOT CLING Dictionary generation of $DICTIONARY_FILE failed with error code $ROOTCLINGRETVAL" - exit 1 -fi - -MSG="Warning: Unused class rule" -if [[ -s ${LOGFILE} ]]; then - WARNINGS=$(grep -c "${MSG}" ${LOGFILE} || :) - if [[ ! $WARNINGS == 0 ]]; then - echo "ERROR: please fix the warnings below about unused class rule" >&2 - grep "$MSG" ${LOGFILE} >&2 - rm $DICTIONARY_FILE - exit 1 - fi -fi - -exit 0 diff --git a/packaging/CMakeLists.txt b/packaging/CMakeLists.txt index 628f9e895f6ef..c1d5058f7b090 100644 --- a/packaging/CMakeLists.txt +++ b/packaging/CMakeLists.txt @@ -17,16 +17,7 @@ install(EXPORT O2Targets FILE O2Targets.cmake) install(FILES O2Config.cmake ../cmake/AddRootDictionary.cmake + ../cmake/RunRootcling.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/O2) -install(FILES ../cmake/rootcling_wrapper.sh.in - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/O2 - PERMISSIONS OWNER_READ - OWNER_WRITE - OWNER_EXECUTE - GROUP_READ - GROUP_EXECUTE - WORLD_READ - WORLD_EXECUTE) - install(DIRECTORY ../dependencies/ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/O2) From 447dfb8c421369d09ad557f855234e6997a48b04 Mon Sep 17 00:00:00 2001 From: Anton Alkin Date: Thu, 17 Sep 2026 10:19:31 +0200 Subject: [PATCH 2/2] remove useless dictionary --- Detectors/Upgrades/ALICE3/AOD/CMakeLists.txt | 2 -- .../ALICE3/AOD/src/UpgradesAODUtilsLinkDef.h | 18 ------------------ 2 files changed, 20 deletions(-) delete mode 100644 Detectors/Upgrades/ALICE3/AOD/src/UpgradesAODUtilsLinkDef.h diff --git a/Detectors/Upgrades/ALICE3/AOD/CMakeLists.txt b/Detectors/Upgrades/ALICE3/AOD/CMakeLists.txt index e1c59f6a325be..7b54736149e96 100644 --- a/Detectors/Upgrades/ALICE3/AOD/CMakeLists.txt +++ b/Detectors/Upgrades/ALICE3/AOD/CMakeLists.txt @@ -13,5 +13,3 @@ o2_add_library(UpgradesAODUtils SOURCES src/Run2LikeAO2D.cxx PUBLIC_LINK_LIBRARIES ROOT::Core) -o2_target_root_dictionary(UpgradesAODUtils - HEADERS include/UpgradesAODUtils/Run2LikeAO2D.h) diff --git a/Detectors/Upgrades/ALICE3/AOD/src/UpgradesAODUtilsLinkDef.h b/Detectors/Upgrades/ALICE3/AOD/src/UpgradesAODUtilsLinkDef.h deleted file mode 100644 index e5b45bbcd779e..0000000000000 --- a/Detectors/Upgrades/ALICE3/AOD/src/UpgradesAODUtilsLinkDef.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#ifdef __CLING__ - -#pragma link off all globals; -#pragma link off all classes; -#pragma link off all functions; - -#endif \ No newline at end of file