Skip to content

Commit 9916067

Browse files
committed
[CMake] Make dictionary module dependencies independent of config order
For each entry in DEPENDENCIES, ROOT_GENERATE_DICTIONARY passes rootcling a `-m <dep>.pcm` flag and a dependency on the dependency's module file, so that the prebuilt module is loaded instead of being built implicitly. This was wired up by inspecting the target graph while the macro runs (`if(NOT TARGET G__${dep})` / `get_target_property(... ROOT_PCM_FILENAME)`), which only works if <dep> is configured before the dictionaries using it. That breaks for core/multiproc: libMultiProc depends on Net (via TSocket), but it lives under core/, configured long before net/. So when G__MultiProc is generated, G__Net does not exist yet, the dependency is silently dropped, and rootcling can build Net implicitly, failing with "Building module 'Net' implicitly ... 'G__MultiProc.cxx' depends on 'Net'". The same shape affects every dictionary depending on a module configured later (Tree -> Net, ...). Decide this at generation time instead, when all targets exist: guard the flag and the module-file dependency with $<TARGET_EXISTS:G__<dep>>. They are emitted whenever <dep> provides a dictionary and expand to nothing otherwise (e.g. a plain library such as TBB::tbb), regardless of configuration order. Closes #21673. 🤖 Problem identified by AI, then the human guided the AI to write the solution that the human wanted to apply.
1 parent b56c913 commit 9916067

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

cmake/modules/RootMacros.cmake

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -623,22 +623,17 @@ function(ROOT_GENERATE_DICTIONARY dictionary)
623623
#---Get the library and module dependencies-----------------
624624
if(ARG_DEPENDENCIES)
625625
foreach(dep ${ARG_DEPENDENCIES})
626-
if(NOT TARGET G__${dep})
627-
# This is a library that doesn't come with dictionary/pcm
628-
continue()
629-
endif()
630-
626+
# Whether <dep> provides a dictionary/pcm is decided at generation time
627+
# via $<TARGET_EXISTS:G__<dep>>, so the '-m' flag and the module-file
628+
# dependency below are independent of configuration order and expand to
629+
# nothing for a dictionary-less library.
630+
set(dep_has_dict "$<TARGET_EXISTS:G__${dep}>")
631631
set(dependent_pcm ${libprefix}${dep}_rdict.pcm)
632632
if (runtime_cxxmodules AND NOT dep IN_LIST local_no_cxxmodules)
633633
set(dependent_pcm ${dep}.pcm)
634-
if(TARGET ${dep})
635-
get_target_property(_dep_pcm_filename ${dep} ROOT_PCM_FILENAME)
636-
if(_dep_pcm_filename)
637-
list(APPEND pcm_dependencies ${_dep_pcm_filename})
638-
endif()
639-
endif()
634+
list(APPEND pcm_dependencies "$<${dep_has_dict}:$<TARGET_PROPERTY:${dep},ROOT_PCM_FILENAME>>")
640635
endif()
641-
set(newargs ${newargs} -m ${dependent_pcm})
636+
set(newargs ${newargs} "$<${dep_has_dict}:-m>" "$<${dep_has_dict}:${dependent_pcm}>")
642637
endforeach()
643638
endif()
644639

0 commit comments

Comments
 (0)