Skip to content

[Build System] Replace IMPLICIT_DEPENDS with DEPFILE_Fixes #21203#21346

Open
DhanashreePetare wants to merge 2 commits intoroot-project:masterfrom
DhanashreePetare:feature/depfile-rootcling
Open

[Build System] Replace IMPLICIT_DEPENDS with DEPFILE_Fixes #21203#21346
DhanashreePetare wants to merge 2 commits intoroot-project:masterfrom
DhanashreePetare:feature/depfile-rootcling

Conversation

@DhanashreePetare
Copy link

This Pull request:

Replaces the broken IMPLICIT_DEPENDS with modern DEPFILE support in ROOT_GENERATE_DICTIONARY macro to enable cross-generator compatibility and proper dependency tracking.

Changes or fixes:

Modified cmake/modules/RootMacros.cmake:

  • Removed IMPLICIT_DEPENDS usage (only works with Unix Makefiles, broken for cross-directory deps)
  • Added DEPFILE parameter pointing to ${CMAKE_CURRENT_BINARY_DIR}/${dictionary}.d
  • Passes -MF ${depfile_path} flag to rootcling

Modified core/dictgen/src/rootcling_impl.cxx:

  • Added -MF command-line option to rootcling
  • Implemented dependency file generation using Clang's FileManager API
  • Writes Makefile-format dependency files listing all included headers
  • Proper error handling for file operations

Implementation flow:

  1. CMake creates depfile path: build/dir/G__Dict.d
  2. CMake invokes: rootcling ... -MF build/dir/G__Dict.d
  3. rootcling parses headers using Clang and tracks all included files
  4. rootcling writes: G__Dict.cxx: header1.h header2.h ...
  5. CMake reads the depfile for dependency tracking
  6. Incremental builds only rebuild when dependencies actually change

Benefits:

  • ✅ Works with Ninja generator (faster builds)
  • ✅ Works with Visual Studio generator
  • ✅ Works with Unix Makefiles
  • ✅ Proper cross-directory dependency tracking
  • ✅ Follows CMake best practices (DEPFILE is recommended over IMPLICIT_DEPENDS)
  • ✅ Backward compatible (no interface changes to ROOT_GENERATE_DICTIONARY)

References:

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

This PR fixes #21203

# make the dictionary generation command depend on the C++ standard, ensuring that the
# dictionaries will be rebuilt if the C++ standard is changed in an incremental build.
-DR__DUMMY_CXX_STANDARD_${CMAKE_CXX_STANDARD}
IMPLICIT_DEPENDS ${_implicitdeps}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider also removing the creation of the _implicitdeps list.

@pcanal pcanal requested review from aaronj0 and guitargeek February 22, 2026 16:02
@github-actions
Copy link

Test Results

    22 files      22 suites   3d 6h 12m 37s ⏱️
 3 798 tests  3 749 ✅   0 💤 49 ❌
76 400 runs  76 041 ✅ 304 💤 55 ❌

For more details on these failures, see this check.

Results for commit 7da1877.

@guitargeek
Copy link
Contributor

That is pretty cool! By better tracking of the dictionary dependencies, we'll be able to also avoid some unnecessary rebuilds of the dictionaries later, so this is an important change. @DhanashreePetare, can you please look at the CI failures and fix the implementation also for Windows and Ninja? Thanks!

# NOTE: DEPFILE is used instead of IMPLICIT_DEPENDS because IMPLICIT_DEPENDS
# only works with Unix Makefiles and has issues with cross-directory dependencies.
# DEPFILE works with all generators (Ninja, Unix Makefiles, etc.)
set(depfile_path ${CMAKE_CURRENT_BINARY_DIR}/${dictionary}.d)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the file ending in .d is leading to it being used 'also' in different context.

@pcanal
Copy link
Member

pcanal commented Feb 24, 2026

Were you able to run the test locally successfully?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ROOT_GENERATE_DICTIONARY needs to be updated to use DEPFILE instead of IMPLICIT_DEPENDS with add_custom_command

4 participants