From ca856f3e994f155374293ccfa64b485ffe551067 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Mon, 10 Aug 2026 13:55:46 +0200 Subject: [PATCH 1/5] experimental use of file sets for library generation --- cmake/modules/RootMacros.cmake | 42 +++++++++- roofit/xroofit/CMakeLists.txt | 136 ++++++++++++++++++++------------- 2 files changed, 124 insertions(+), 54 deletions(-) diff --git a/cmake/modules/RootMacros.cmake b/cmake/modules/RootMacros.cmake index 858a0e550dbb2..c1e14e4c62fe0 100644 --- a/cmake/modules/RootMacros.cmake +++ b/cmake/modules/RootMacros.cmake @@ -288,11 +288,51 @@ function(ROOT_REPLACE_BUILD_INTERFACE include_dir_var include_dir) set(${include_dir_var} ${include_dir} PARENT_SCOPE) endfunction(ROOT_REPLACE_BUILD_INTERFACE) +#--------------------------------------------------------------------------------------------------- +#---ROOT_GENERATE_TARGET_DICTIONARY( target OPTIONS opt1 opt2 ...) +# +# Creates the dictionary of a predefined CMake target +# is the CMake target on which header file sets and link libraries have been defined +# The output dictionary will be another CMake target called G__ prepended.; +# the macro creates (among other files) the dictionary source as G__.cxx +#--------------------------------------------------------------------------------------------------- +function(ROOT_GENERATE_TARGET_DICTIONARY target ) + CMAKE_PARSE_ARGUMENTS(ARG "OPTIONS" ${ARGN}) + # Check if OPTIONS start with a dash. + if (ARG_OPTIONS) + foreach(ARG_O ${ARG_OPTIONS}) + if (NOT ARG_O MATCHES "^-*") + message(FATAL_ERROR "Wrong rootcling option: ${ARG_OPTIONS}") + endif() + endforeach() + endif(ARG_OPTIONS) + + get_target_property(type ${target} TYPE) + if(NOT ${type} STREQUAL "INTERFACE_LIBRARY") + get_target_property(SrcList ${target} SOURCES) + get_target_property(SrcDir ${target} SOURCE_DIR) + list(TRANSFORM SrcList PREPEND ${SrcDir}/) + endif() + get_target_property(HeaderList ${target} HEADER_SET) + get_target_property(LinkdefList ${target} HEADER_SET_linkDefs) + # get_target_property(ModuleList ${target} CXX_MODULE_SET) needs 3.28 + if("HeaderList-NOTFOUND" IN_LIST HeaderList) + message(SEND_ERROR "ROOT_GENERATE_TARGET_DICTIONARY: Missing header file set in ${target}") + endif() + if("LinkdefList-NOTFOUND" IN_LIST LinkdefList) + message(SEND_ERROR "ROOT_GENERATE_TARGET_DICTIONARY: Missing Linkdef file set in ${target}") + endif() + get_target_property(LinkedLibraries ${target} LINK_LIBRARIES) + ROOT_GENERATE_DICTIONARY(G__${target} ${HeaderList} LINKDEF ${LinkdefList} DEPENDENCIES ${LinkedLibraries} OPTIONS ${ARG_OPTIONS}) + # TODO: Probably one could directly call rootcling without all the shenanigan inside ROOT_GENERATE_DICTIONARY with include dirs, now that file_sets are used +endfunction(ROOT_GENERATE_TARGET_DICTIONARY) + #--------------------------------------------------------------------------------------------------- #---ROOT_GENERATE_DICTIONARY( dictionary headerfiles NODEPHEADERS ghdr1 ghdr2 ... # MODULE module DEPENDENCIES dep1 dep2 +# EXTRA_DEPENDENCIES # BUILTINS dep1 dep2 -# STAGE1 LINKDEF linkdef OPTIONS opt1 opt2 ...) +# STAGE1 LINKDEF linkdef OPTIONS opt1 opt2 ... NO_CXXMODULE MULTIDICT NOINSTALL) # # is the dictionary stem; the macro creates (among other files) the dictionary source as # .cxx diff --git a/roofit/xroofit/CMakeLists.txt b/roofit/xroofit/CMakeLists.txt index f23690d89d805..b938664afd6e4 100644 --- a/roofit/xroofit/CMakeLists.txt +++ b/roofit/xroofit/CMakeLists.txt @@ -1,60 +1,90 @@ -set (XROOFIT_HEADERS - RooBrowser.h - XRooFit.h - RooFit/xRooFit/xRooFit.h - RooFit/xRooFit/xRooNode.h - RooFit/xRooFit/xRooNLLVar.h - RooFit/xRooFit/xRooHypoSpace.h - RooFit/xRooFit/xRooBrowser.h -) - -ROOT_STANDARD_LIBRARY_PACKAGE(RooFitXRooFit - HEADERS - ${XROOFIT_HEADERS} - SOURCES - src/Asymptotics.cxx - src/xRooBrowser.cxx - src/xRooFit.cxx - src/xRooHypoSpace.cxx - src/xRooNLLVar.cxx - src/xRooNode.cxx - src/xRooNode_interactive.cxx - src/PythonInterface.cxx - DICTIONARY_OPTIONS - "-writeEmptyRootPCM" - DEPENDENCIES - HistFactory - RooFit - RooFitHS3 - RooStats - FitPanel - Gui - Ged - RooFitCore - FitPanel - LINKDEF - inc/LinkDef.h -) - -target_include_directories(RooFitXRooFit PRIVATE inc/RooFit) +if(CMAKE_VERSION VERSION_LESS "3.23.0") + ROOT_STANDARD_LIBRARY_PACKAGE(RooFitXRooFit + HEADERS + RooBrowser.h + XRooFit.h + RooFit/xRooFit/xRooFit.h + RooFit/xRooFit/xRooNode.h + RooFit/xRooFit/xRooNLLVar.h + RooFit/xRooFit/xRooHypoSpace.h + RooFit/xRooFit/xRooBrowser.h + SOURCES + src/Asymptotics.cxx + src/xRooBrowser.cxx + src/xRooFit.cxx + src/xRooHypoSpace.cxx + src/xRooNLLVar.cxx + src/xRooNode.cxx + src/xRooNode_interactive.cxx + src/PythonInterface.cxx + DICTIONARY_OPTIONS + "-writeEmptyRootPCM" + DEPENDENCIES + HistFactory + RooFit + RooFitHS3 + RooStats + FitPanel + Gui + Ged + RooFitCore + FitPanel + LINKDEF + inc/LinkDef.h + ) -set(RELATIVE_INC_HEADERS ${XROOFIT_HEADERS}) -list(TRANSFORM RELATIVE_INC_HEADERS PREPEND inc/) -if(NOT CMAKE_VERSION VERSION_LESS "3.23.0") + target_include_directories(RooFitXRooFit PRIVATE inc/RooFit) +else() + add_library(RooFitXRooFit SHARED) target_sources( - RooFitXRooFit - PRIVATE - FILE_SET private_header_files - TYPE HEADERS - BASE_DIRS inc/ src/ - FILES - ${RELATIVE_INC_HEADERS} + RooFitXRooFit + PRIVATE + src/Asymptotics.cxx + src/xRooBrowser.cxx + src/xRooFit.cxx + src/xRooHypoSpace.cxx + src/xRooNLLVar.cxx + src/xRooNode.cxx + src/xRooNode_interactive.cxx + src/PythonInterface.cxx + # These below could be also a PRIVATE header file_set if wanted + src/PythonInterface.h + src/coutCapture.h + src/xRooFitVersion.h + PUBLIC + FILE_SET HEADERS + TYPE HEADERS + BASE_DIRS inc/ + FILES + inc/RooBrowser.h + inc/XRooFit.h + inc/RooFit/xRooFit/xRooFit.h + inc/RooFit/xRooFit/xRooNode.h + inc/RooFit/xRooFit/xRooNLLVar.h + inc/RooFit/xRooFit/xRooHypoSpace.h + inc/RooFit/xRooFit/xRooBrowser.h + inc/RooFit/xRooFit/Config.h # was not part of XROOFIT_HEADERS earlier + PUBLIC + FILE_SET linkDefs + TYPE HEADERS + BASE_DIRS inc/ + FILES inc/LinkDef.h - inc/RooFit/xRooFit/Config.h # was not part of XROOFIT_HEADERS - src/PythonInterface.h - src/coutCapture.h - src/xRooFitVersion.h ) + target_link_libraries(RooFitXRooFit + PUBLIC + HistFactory + RooFit + RooFitHS3 + RooStats + FitPanel + Gui + Ged + RooFitCore + FitPanel + ) + ROOT_GENERATE_TARGET_DICTIONARY(RooFitXRooFit + DICTIONARY_OPTIONS "-writeEmptyRootPCM") endif() ROOT_ADD_TEST_SUBDIRECTORY(test) From a34a97da1cb20091b10dd95dd66bba881a730e15 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Mon, 10 Aug 2026 14:12:55 +0200 Subject: [PATCH 2/5] install step --- roofit/xroofit/CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/roofit/xroofit/CMakeLists.txt b/roofit/xroofit/CMakeLists.txt index b938664afd6e4..6c557f8190648 100644 --- a/roofit/xroofit/CMakeLists.txt +++ b/roofit/xroofit/CMakeLists.txt @@ -85,6 +85,18 @@ else() ) ROOT_GENERATE_TARGET_DICTIONARY(RooFitXRooFit DICTIONARY_OPTIONS "-writeEmptyRootPCM") + install(TARGETS RooFitXRooFit + EXPORT ${CMAKE_PROJECT_NAME}Exports + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT applications + + # with this we no longer need the moveheader target etc + FILE_SET HEADERS + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # add /ROOT to make Debian happy + + FILE_SET linkDefs + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # add /ROOT to make Debian happy + ) endif() ROOT_ADD_TEST_SUBDIRECTORY(test) From 961abd9523284e762ad7d2992d555d5bcec27ec8 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Mon, 10 Aug 2026 14:19:21 +0200 Subject: [PATCH 3/5] libstuff --- roofit/xroofit/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/roofit/xroofit/CMakeLists.txt b/roofit/xroofit/CMakeLists.txt index 6c557f8190648..1c13f04519cf0 100644 --- a/roofit/xroofit/CMakeLists.txt +++ b/roofit/xroofit/CMakeLists.txt @@ -87,6 +87,7 @@ else() DICTIONARY_OPTIONS "-writeEmptyRootPCM") install(TARGETS RooFitXRooFit EXPORT ${CMAKE_PROJECT_NAME}Exports + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT applications From d8a1718c9b016a8c741adce9f26ec8a80aed9e77 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Mon, 10 Aug 2026 14:24:24 +0200 Subject: [PATCH 4/5] Update CMakeLists.txt --- roofit/xroofit/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roofit/xroofit/CMakeLists.txt b/roofit/xroofit/CMakeLists.txt index 1c13f04519cf0..3974eb21fdd72 100644 --- a/roofit/xroofit/CMakeLists.txt +++ b/roofit/xroofit/CMakeLists.txt @@ -84,7 +84,7 @@ else() FitPanel ) ROOT_GENERATE_TARGET_DICTIONARY(RooFitXRooFit - DICTIONARY_OPTIONS "-writeEmptyRootPCM") + OPTIONS "-writeEmptyRootPCM") install(TARGETS RooFitXRooFit EXPORT ${CMAKE_PROJECT_NAME}Exports LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} From ee6709a6aed7e0f2f4b215bd5a589961d51e7762 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Tue, 18 Aug 2026 16:57:38 +0200 Subject: [PATCH 5/5] fix headers by split --- cmake/modules/RootMacros.cmake | 13 ++++++------- roofit/xroofit/CMakeLists.txt | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/cmake/modules/RootMacros.cmake b/cmake/modules/RootMacros.cmake index c1e14e4c62fe0..52b39aee63a7d 100644 --- a/cmake/modules/RootMacros.cmake +++ b/cmake/modules/RootMacros.cmake @@ -296,16 +296,15 @@ endfunction(ROOT_REPLACE_BUILD_INTERFACE) # The output dictionary will be another CMake target called G__ prepended.; # the macro creates (among other files) the dictionary source as G__.cxx #--------------------------------------------------------------------------------------------------- -function(ROOT_GENERATE_TARGET_DICTIONARY target ) - CMAKE_PARSE_ARGUMENTS(ARG "OPTIONS" ${ARGN}) +function(ROOT_GENERATE_TARGET_DICTIONARY target options) # Check if OPTIONS start with a dash. - if (ARG_OPTIONS) - foreach(ARG_O ${ARG_OPTIONS}) + if (options) + foreach(ARG_O ${options}) if (NOT ARG_O MATCHES "^-*") - message(FATAL_ERROR "Wrong rootcling option: ${ARG_OPTIONS}") + message(FATAL_ERROR "Wrong rootcling option: ${options}") endif() endforeach() - endif(ARG_OPTIONS) + endif(options) get_target_property(type ${target} TYPE) if(NOT ${type} STREQUAL "INTERFACE_LIBRARY") @@ -323,7 +322,7 @@ function(ROOT_GENERATE_TARGET_DICTIONARY target ) message(SEND_ERROR "ROOT_GENERATE_TARGET_DICTIONARY: Missing Linkdef file set in ${target}") endif() get_target_property(LinkedLibraries ${target} LINK_LIBRARIES) - ROOT_GENERATE_DICTIONARY(G__${target} ${HeaderList} LINKDEF ${LinkdefList} DEPENDENCIES ${LinkedLibraries} OPTIONS ${ARG_OPTIONS}) + ROOT_GENERATE_DICTIONARY(G__${target} ${HeaderList} LINKDEF ${LinkdefList} DEPENDENCIES ${LinkedLibraries} OPTIONS ${options}) # TODO: Probably one could directly call rootcling without all the shenanigan inside ROOT_GENERATE_DICTIONARY with include dirs, now that file_sets are used endfunction(ROOT_GENERATE_TARGET_DICTIONARY) diff --git a/roofit/xroofit/CMakeLists.txt b/roofit/xroofit/CMakeLists.txt index 3974eb21fdd72..25bc4d9bc2402 100644 --- a/roofit/xroofit/CMakeLists.txt +++ b/roofit/xroofit/CMakeLists.txt @@ -54,10 +54,8 @@ else() PUBLIC FILE_SET HEADERS TYPE HEADERS - BASE_DIRS inc/ + BASE_DIRS inc/RooFit FILES - inc/RooBrowser.h - inc/XRooFit.h inc/RooFit/xRooFit/xRooFit.h inc/RooFit/xRooFit/xRooNode.h inc/RooFit/xRooFit/xRooNLLVar.h @@ -65,6 +63,12 @@ else() inc/RooFit/xRooFit/xRooBrowser.h inc/RooFit/xRooFit/Config.h # was not part of XROOFIT_HEADERS earlier PUBLIC + FILE_SET extraHEADERS + TYPE HEADERS + BASE_DIRS inc/ + FILES + inc/RooBrowser.h + inc/XRooFit.h FILE_SET linkDefs TYPE HEADERS BASE_DIRS inc/ @@ -83,8 +87,7 @@ else() RooFitCore FitPanel ) - ROOT_GENERATE_TARGET_DICTIONARY(RooFitXRooFit - OPTIONS "-writeEmptyRootPCM") + ROOT_GENERATE_TARGET_DICTIONARY(RooFitXRooFit "-writeEmptyRootPCM") install(TARGETS RooFitXRooFit EXPORT ${CMAKE_PROJECT_NAME}Exports LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -92,7 +95,10 @@ else() COMPONENT applications # with this we no longer need the moveheader target etc - FILE_SET HEADERS + FILE_SET HEADERS + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # add /ROOT to make Debian happy + + FILE_SET extraHEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # add /ROOT to make Debian happy FILE_SET linkDefs