Skip to content

Commit 0633fd7

Browse files
committed
[CMake] Improve ROOT_GENERATE_DICTIONARY
- In case ROOT_GENERATE_DICTIONARY is invoked with a dependency that doesn't have a dictionary itself, the for loop through dependencies now just continue()s. Before, this would raise a CMake error. - The object library with the dictionary file is now linked into the main library using target_link_libraries(). - When the list of include directories for the dictionary is generated, the INTERFACE_SYSTEM_INCLUDE_DIRECTORIES of the dependencies is now honoured. Before, system includes would decay to normal includes. Unfortunately, PRIVATE includes still decay to normal -I includes. This can lead header conflicts when ROOT is built while another ROOT is installed in system include directories, but only for the dictionary files. Since ROOT include directories are very generously prepended to all targets, I wasn't able to provoke a header conflict.
1 parent 873b5f8 commit 0633fd7

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

cmake/modules/RootMacros.cmake

+14-3
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,11 @@ function(ROOT_GENERATE_DICTIONARY dictionary)
562562
#---Get the library and module dependencies-----------------
563563
if(ARG_DEPENDENCIES)
564564
foreach(dep ${ARG_DEPENDENCIES})
565+
if(NOT TARGET G__${dep})
566+
# This is a library that doesn't come with dictionary/pcm
567+
continue()
568+
endif()
569+
565570
set(dependent_pcm ${libprefix}${dep}_rdict.pcm)
566571
if (runtime_cxxmodules)
567572
set(dependent_pcm ${dep}.pcm)
@@ -648,7 +653,7 @@ function(ROOT_GENERATE_DICTIONARY dictionary)
648653
if(TARGET "${ARG_MODULE}" AND NOT "${ARG_MODULE}" STREQUAL "${dictionary}")
649654
add_library(${dictionary} OBJECT ${dictionary}.cxx)
650655
set_target_properties(${dictionary} PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
651-
target_sources(${ARG_MODULE} PRIVATE $<TARGET_OBJECTS:${dictionary}>)
656+
target_link_libraries(${ARG_MODULE} PRIVATE ${dictionary})
652657

653658
target_compile_options(${dictionary} PRIVATE
654659
$<TARGET_PROPERTY:${ARG_MODULE},COMPILE_OPTIONS>)
@@ -659,8 +664,14 @@ function(ROOT_GENERATE_DICTIONARY dictionary)
659664
target_compile_features(${dictionary} PRIVATE
660665
$<TARGET_PROPERTY:${ARG_MODULE},COMPILE_FEATURES>)
661666

662-
target_include_directories(${dictionary} PRIVATE
663-
${incdirs} $<TARGET_PROPERTY:${ARG_MODULE},INCLUDE_DIRECTORIES>)
667+
target_include_directories(${dictionary} PRIVATE ${incdirs} $<TARGET_PROPERTY:${ARG_MODULE},INCLUDE_DIRECTORIES>)
668+
669+
# Above we are copying all include directories of the module, irrespective of whether they are system includes.
670+
# CMake copies them as -I even when they should be -isystem.
671+
# We can fix this for INTERFACE includes by also copying the respective property.
672+
# For PRIVATE includes this doesn't work, but since all ROOT includes are prepended, it didn't do harm yet.
673+
set_property(TARGET ${dictionary} APPEND PROPERTY
674+
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:${ARG_MODULE},INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>)
664675
else()
665676
get_filename_component(dictionary_name ${dictionary} NAME)
666677
add_custom_target(${dictionary_name} DEPENDS ${dictionary}.cxx ${pcm_name} ${rootmap_name} ${cpp_module_file})

0 commit comments

Comments
 (0)