From 0f3283943c808078d8bd686c26439b8ee9070f20 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Fri, 19 Jun 2026 22:25:21 +0200 Subject: [PATCH] [CMake] Link only what is used: drop unused explicit library deps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Address #20731 by removing explicitly-linked-but-unused libraries reported by `ldd -u`. The recurring offenders all came from foundational libraries exporting internal-only dependencies through their PUBLIC link interface (CMake DEPENDENCIES), so every consumer inherited them. These are now PRIVATE (CMake LIBRARIES), and genuinely-spurious links dropped: * RIO: Thread -> `PRIVATE` (TFilePrefetch only holds a TThread* member) * Tree: Imt/Net/MathCore -> `PRIVATE`, declares its own Thread (RIO stays PUBLIC: TBufferSQL/TTreeCache derive from RIO types) * RHTTP/HistPainter/RooStats/RooFitMore/RCsg: internal deps -> PRIVATE * Hbook/Spectrum/HistFactory: spurious Matrix/Foam removed * ntuple_merger/stressRooFit tests: declare the deps they actually use RIO -> Thread alone cuts Thread over-linking from 62 reports to 2; in total the tree drops from 510 reports (77 libs) to 422 (69), and every library still links cleanly under `-Wl`, `--no-undefined`. This closes #20731: the remaining reports are not over-linking and PUBLIC/PRIVATE cannot remove them. They are either inline-header dependencies (e.g. Tree using TMath: a real compile dependency with no exported symbol, which `ldd -u` mis-flags) or deliberate public API (Hist exposes TVectorD/TMatrixD; TMessage derives from TBufferFile). Closes #20731. 🤖 Done with the help of AI. --- graf3d/csg/CMakeLists.txt | 4 ++-- gui/webgui6/CMakeLists.txt | 3 ++- hist/hbook/CMakeLists.txt | 1 - hist/histpainter/CMakeLists.txt | 1 + hist/spectrum/CMakeLists.txt | 1 - io/io/CMakeLists.txt | 2 +- net/http/CMakeLists.txt | 2 +- roofit/histfactory/CMakeLists.txt | 1 - roofit/roofitcore/test/CMakeLists.txt | 2 +- roofit/roofitmore/CMakeLists.txt | 5 ++--- roofit/roostats/CMakeLists.txt | 5 +++-- tree/ntuple/test/CMakeLists.txt | 2 +- tree/tree/CMakeLists.txt | 7 ++++--- 13 files changed, 18 insertions(+), 18 deletions(-) diff --git a/graf3d/csg/CMakeLists.txt b/graf3d/csg/CMakeLists.txt index 6cf61aba4b084..d3348977eac08 100644 --- a/graf3d/csg/CMakeLists.txt +++ b/graf3d/csg/CMakeLists.txt @@ -9,6 +9,6 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RCsg CsgOps.h SOURCES CsgOps.cxx - DEPENDENCIES - MathCore + LIBRARIES + MathCore ) diff --git a/gui/webgui6/CMakeLists.txt b/gui/webgui6/CMakeLists.txt index 0540870b27119..405209853bce1 100644 --- a/gui/webgui6/CMakeLists.txt +++ b/gui/webgui6/CMakeLists.txt @@ -26,7 +26,8 @@ ROOT_STANDARD_LIBRARY_PACKAGE(WebGui6 src/TWebSnapshot.cxx DEPENDENCIES Core - RIO Gpad + RIO ROOTWebDisplay + Thread ) diff --git a/hist/hbook/CMakeLists.txt b/hist/hbook/CMakeLists.txt index 75ca4b0b2c2b9..c276a441018d1 100644 --- a/hist/hbook/CMakeLists.txt +++ b/hist/hbook/CMakeLists.txt @@ -25,7 +25,6 @@ ROOT_STANDARD_LIBRARY_PACKAGE(Hbook minicern DEPENDENCIES Hist - Matrix Tree Graf TreePlayer diff --git a/hist/histpainter/CMakeLists.txt b/hist/histpainter/CMakeLists.txt index 07d51440d01aa..30a6718bc2acc 100644 --- a/hist/histpainter/CMakeLists.txt +++ b/hist/histpainter/CMakeLists.txt @@ -29,5 +29,6 @@ ROOT_STANDARD_LIBRARY_PACKAGE(HistPainter Graf Hist MathCore + LIBRARIES Matrix ) diff --git a/hist/spectrum/CMakeLists.txt b/hist/spectrum/CMakeLists.txt index b38736124e624..d82dca45eb155 100644 --- a/hist/spectrum/CMakeLists.txt +++ b/hist/spectrum/CMakeLists.txt @@ -29,5 +29,4 @@ ROOT_STANDARD_LIBRARY_PACKAGE(Spectrum -writeEmptyRootPCM DEPENDENCIES Hist - Matrix ) diff --git a/io/io/CMakeLists.txt b/io/io/CMakeLists.txt index 4318f1ee8af5e..6f30d2d9ac96a 100644 --- a/io/io/CMakeLists.txt +++ b/io/io/CMakeLists.txt @@ -60,9 +60,9 @@ ROOT_LINKER_LIBRARY(RIO $ LIBRARIES ${CMAKE_DL_LIBS} + Thread DEPENDENCIES Core - Thread ) target_include_directories(RIO PRIVATE ${CMAKE_SOURCE_DIR}/core/clib/res) diff --git a/net/http/CMakeLists.txt b/net/http/CMakeLists.txt index 5c8e81346399a..8dd5988a84f1b 100644 --- a/net/http/CMakeLists.txt +++ b/net/http/CMakeLists.txt @@ -54,9 +54,9 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RHTTP ${_civetweb_libs} ${FASTCGI_LIBRARY} ${CMAKE_DL_LIBS} + Thread DEPENDENCIES RIO - Thread ) if(builtin_civetweb) diff --git a/roofit/histfactory/CMakeLists.txt b/roofit/histfactory/CMakeLists.txt index 242f206971f4a..99420cb075e23 100644 --- a/roofit/histfactory/CMakeLists.txt +++ b/roofit/histfactory/CMakeLists.txt @@ -60,7 +60,6 @@ ROOT_STANDARD_LIBRARY_PACKAGE(HistFactory Tree RIO Hist - Matrix MathCore Graf Gpad diff --git a/roofit/roofitcore/test/CMakeLists.txt b/roofit/roofitcore/test/CMakeLists.txt index def1fa324c837..53f47d8a0cb5e 100644 --- a/roofit/roofitcore/test/CMakeLists.txt +++ b/roofit/roofitcore/test/CMakeLists.txt @@ -98,7 +98,7 @@ if (roofit_multiprocess) endif() if(mathmore) - list(APPEND ROOFITMORE_LIBRARIES RooFitMore) + list(APPEND ROOFITMORE_LIBRARIES RooFitMore MathMore) endif() #--stressRooFit---------------------------------------------------------------------------------- diff --git a/roofit/roofitmore/CMakeLists.txt b/roofit/roofitmore/CMakeLists.txt index 1130797b255b0..7bbb9762d34ce 100644 --- a/roofit/roofitmore/CMakeLists.txt +++ b/roofit/roofitmore/CMakeLists.txt @@ -40,16 +40,15 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFitMore LINKDEF LinkDef.h DEPENDENCIES - ${ROOT_MATHMORE_LIBRARY} Core RooFitCore RooFit Hist - Matrix Tree RIO + LIBRARIES + ${ROOT_MATHMORE_LIBRARY} MathCore - Foam ${EXTRA_DICT_OPTS} ) diff --git a/roofit/roostats/CMakeLists.txt b/roofit/roostats/CMakeLists.txt index b51d6b718a8c8..9b940eab3b130 100644 --- a/roofit/roostats/CMakeLists.txt +++ b/roofit/roostats/CMakeLists.txt @@ -128,10 +128,11 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooStats Hist Matrix MathCore - Minuit - Foam Graf Gpad + LIBRARIES + Minuit + Foam ${EXTRA_DICT_OPTS} ) diff --git a/tree/ntuple/test/CMakeLists.txt b/tree/ntuple/test/CMakeLists.txt index 96b080a35f1ee..407d9d185e1d7 100644 --- a/tree/ntuple/test/CMakeLists.txt +++ b/tree/ntuple/test/CMakeLists.txt @@ -47,7 +47,7 @@ endif() ROOT_ADD_GTEST(ntuple_field_name ntuple_field_name.cxx LIBRARIES ROOTNTuple) ROOT_ADD_GTEST(ntuple_join_table ntuple_join_table.cxx LIBRARIES ROOTNTuple) ROOT_ADD_GTEST(ntuple_merger ntuple_merger.cxx ntuple_test.cxx - LIBRARIES ROOTNTuple CustomStruct ZLIB::ZLIB Tree xxHash::xxHash + LIBRARIES ROOTNTuple CustomStruct ZLIB::ZLIB Tree MathCore xxHash::xxHash INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/tree/tree/inc) ROOT_ADD_GTEST(ntuple_metrics ntuple_metrics.cxx LIBRARIES ROOTNTuple) ROOT_ADD_GTEST(ntuple_model ntuple_model.cxx LIBRARIES ROOTNTuple CustomStruct) diff --git a/tree/tree/CMakeLists.txt b/tree/tree/CMakeLists.txt index 5fe4978a94ac2..9efa075d0a137 100644 --- a/tree/tree/CMakeLists.txt +++ b/tree/tree/CMakeLists.txt @@ -10,7 +10,7 @@ ############################################################################ if (imt) - list(APPEND TREE_EXTRA_DEPENDENCIES Imt) + list(APPEND TREE_EXTRA_LIBRARIES Imt) endif(imt) ROOT_STANDARD_LIBRARY_PACKAGE(Tree @@ -124,12 +124,13 @@ ROOT_STANDARD_LIBRARY_PACKAGE(Tree DICTIONARY_OPTIONS -writeEmptyRootPCM DEPENDENCIES - ${TREE_EXTRA_DEPENDENCIES} Net RIO - MathCore LIBRARIES ${ROOT_ATOMIC_LIBS} + ${TREE_EXTRA_LIBRARIES} + Thread + MathCore ) ROOT_ADD_TEST_SUBDIRECTORY(test)