ROOT_GENERATE_DICTIONARY include path

Hello,
I am using a CMakeLists, as discussed here: Integrating ROOT into CMake projects - ROOT

In particular, I am following this example from that webpage:

   include_directories(${CMAKE_CURRENT_SOURCE_DIR}/myIncludePath)
   ROOT_GENERATE_DICTIONARY(G__Event Event.h LINKDEF EventLinkDef.h)

My question is if there is a way to pass the include_directories directly within ROOT_GENERATE_DIRECTORY. Otherwise, the build environment gets polluted with the global include_directories.

In particular, I have a target MyLibrary which defines:
set_target_properties(MyLibrary PROPERTIES INTERFACE_INCLUDE_DIRECTORIES myIncludePath)

In all my other targets that depends on this library, I just link against this target and it automatically appends myIncludePath. This is cleaner than using a global include_directories that is then seen by every other target even if they do not depend on it.

If this is not possible, then I would like to suggest a ‘feature improvement’ for the ROOT_GENERATE_DICTIONARY to accept depending targets so that it auto-reads the necessary include directories.

As it is a cmake question may be @bellenot can help.

Calling set_target_properties(MyLibrary PROPERTIES INTERFACE_INCLUDE_DIRECTORIES myIncludePath) before ROOT_GENERATE_DICTIONARY(G__Event Event.h LINKDEF EventLinkDef.h MODULE MyLibrary) will allow the dictionary generation to pick up the library’s include flags. Please let me know if this doesn’t work. And I’d be very happy to get a PR against web/index.md at main · root-project/web · GitHub :slight_smile:

You can actually avoid manually setting target properties if you call things in the “right” order. See here for a working example, and the discussion at ROOT_GENERATE_DICTIONARY is difficult to use correctly · Issue #8308 · root-project/root · GitHub for more context.

Cheers,
Enrico

Thanks for the suggestion Axel, however it is still not working, it does not propagate the include path, not sure why.

Also, answering to eguiraud, I would prefer not to create a Module. (Doing that fills up my compilation step with many warnings about zero-as-nullptr and old-style-cast).

What MODULE MyLibrary.so is doing to the compilation process behind the scenes:
Simplified version:
/opt/root/bin/rootcling -v2 -f G__Event.cxx -s MyLibrary.so -rml MyLibrary.so -rmf MyLibrary.rootmap Event.hpp

What include_directories does, which works fine, (but pollutes later).
/opt/root/bin/rootcling -v2 -f G__Event.cxx -I myIncludePath Event.hpp

The exact version with MODULE is:
Program arguments: /opt/root/bin/rootcling -v2 -f G__ThSFMC01.cxx -s /home/ferhue/zdt-daq/build/gui/libZDTcore.so -rml libZDTcore.so -rmf /home/ferhue/zdt-daq/build/gui/libZDTcore.rootmap -I/opt/CLI11/include -I/home/ferhue/zdt-daq/dptc -I/opt/sis1160-sfmc01/sispcidrv/api -I/opt/sis1160-sfmc01/sispcidrv/driver/common -I/usr/include -I/opt/zstr/src -I/opt/root/include -I/home/ferhue/zdt-daq/gui -I/opt/CLI11/include -I/home/ferhue/zdt-daq/dptc -I/opt/sis1160-sfmc01/sispcidrv/api -I/opt/sis1160-sfmc01/sispcidrv/driver/common -I/usr/include -I/opt/zstr/src /home/ferhue/zdt-daq/gui/ThSFMC01.hpp

By the way, somehow, if I don’t call include_directories, then cling crashes:

/opt/root/bin/rootcling -v2 -f G__ThSFMC01.cxx -s /home/ferhue/zdt-daq/build/gui/libThSFMC01.so -rml libThSFMC01.so -rmf /home/ferhue/zdt-daq/build/gui/libThSFMC01.rootmap -I/opt/CLI11/include -I/home/ferhue/zdt-daq/dptc -I/opt/sis1160-sfmc01/sispcidrv/api -I/opt/sis1160-sfmc01/sispcidrv/driver/common -I/usr/include -I/opt/zstr/src -I/opt/root/include -I/home/ferhue/zdt-daq/gui /home/ferhue/zdt-daq/gui/ThSFMC01.hpp
In file included from input_line_8:3:
/home/ferhue/zdt-daq/gui/ThSFMC01.hpp:9:10: fatal error: 'SFMC01.hpp' file not found
#include "SFMC01.hpp"
         ^~~~~~~~~~~~
/opt/root/lib/libCling.so(+0x35ad353)[0x7f686f5bf353]
/opt/root/lib/libCling.so(+0x35aad6c)[0x7f686f5bcd6c]
/lib/x86_64-linux-gnu/libc.so.6(+0x46210)[0x7f686b8ce210]
/opt/root/lib/libCling.so(+0x3011714)[0x7f686f023714]
/opt/root/lib/libCling.so(+0x17b3f25)[0x7f686d7c5f25]
/opt/root/lib/libCling.so(+0x125531d)[0x7f686d26731d]
/opt/root/lib/libCling.so(+0x125609f)[0x7f686d26809f]
/opt/root/lib/libCling.so(+0xec3753)[0x7f686ced5753]
/opt/root/lib/libCling.so(+0xed6ccc)[0x7f686cee8ccc]
/opt/root/lib/libCling.so(+0xf6acba)[0x7f686cf7ccba]
/opt/root/lib/libCling.so(+0xf6b395)[0x7f686cf7d395]
/opt/root/lib/libCling.so(+0xf714c9)[0x7f686cf834c9]
/opt/root/lib/libCling.so(+0xee8cdc)[0x7f686cefacdc]
/opt/root/lib/libCling.so(+0xef04d1)[0x7f686cf024d1]
/opt/root/lib/libCling.so(+0xed803d)[0x7f686ceea03d]
/opt/root/lib/libCling.so(+0xf70b82)[0x7f686cf82b82]
/opt/root/lib/libCling.so(+0xee8cdc)[0x7f686cefacdc]
/opt/root/lib/libCling.so(+0xef04d1)[0x7f686cf024d1]
/opt/root/lib/libCling.so(+0xed803d)[0x7f686ceea03d]
/opt/root/lib/libCling.so(+0xf70b82)[0x7f686cf82b82]
/opt/root/lib/libCling.so(+0xf718cd)[0x7f686cf838cd]
/opt/root/lib/libCling.so(+0x797480)[0x7f686c7a9480]
/opt/root/lib/libCling.so(+0x7981f1)[0x7f686c7aa1f1]
/opt/root/lib/libCling.so(+0x6f7ee5)[0x7f686c709ee5]
/opt/root/lib/libCling.so(+0x5a457a)[0x7f686c5b657a]
/opt/root/lib/libCling.so(_Z13RootClingMainiPPcb+0x2f3a)[0x7f686c5ca01a]
/opt/root/lib/libCling.so(ROOT_rootcling_Driver+0x11d)[0x7f686c5d3b4d]
/opt/root/bin/rootcling(main+0xa0)[0x562095a00140]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0x7f686b8af0b3]
/opt/root/bin/rootcling(_start+0x2e)[0x562095a001ae]
Stack dump:
0.    Program arguments: /opt/root/bin/rootcling -v2 -f G__ThSFMC01.cxx -s /home/ferhue/zdt-daq/build/gui/libThSFMC01.so -rml libThSFMC01.so -rmf /home/ferhue/zdt-daq/build/gui/libThSFMC01.rootmap -I/opt/CLI11/include -I/home/ferhue/zdt-daq/dptc -I/opt/sis1160-sfmc01/sispcidrv/api -I/opt/sis1160-sfmc01/sispcidrv/driver/common -I/usr/include -I/opt/zstr/src -I/opt/root/include -I/home/ferhue/zdt-daq/gui /home/ferhue/zdt-daq/gui/ThSFMC01.hpp
1.    /usr/include/c++/9/ostream:41:1: parsing namespace 'std'
2.    /usr/include/c++/9/bits/stl_map.h:66:1: parsing namespace 'std::std'

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f686b96ddba in __GI___wait4 (pid=521119, stat_loc=stat_loc
entry=0x7ffe8c3a1828, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:27
#1  0x00007f686b96dd7b in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7ffe8c3a1828, options=options
entry=0) at waitpid.c:38
#2  0x00007f686b8dd0e7 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:172
#3  0x00007f686bda79be in TUnixSystem::StackTrace() () from /opt/root/lib/libCore.so
#4  0x00007f686bda4845 in TUnixSystem::DispatchSignals(ESignals) () from /opt/root/lib/libCore.so
#5  <signal handler called>
#6  0x00007f686f023714 in clang::NestedNameSpecifier::containsUnexpandedParameterPack() const () from /opt/root/lib/libCling.so
#7  0x00007f686d7c5f25 in clang::Sema::DiagnoseUnexpandedParameterPack(clang::CXXScopeSpec const&, clang::Sema::UnexpandedParameterPackContext) () from /opt/root/lib/libCling.so
#8  0x00007f686d26731d in clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) () from /opt/root/lib/libCling.so
#9  0x00007f686d26809f in clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) () from /opt/root/lib/libCling.so
#10 0x00007f686ced5753 in clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) () from /opt/root/lib/libCling.so
#11 0x00007f686cee8ccc in clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) () from /opt/root/lib/libCling.so
#12 0x00007f686cf7ccba in clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) () from /opt/root/lib/libCling.so
#13 0x00007f686cf7d395 in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) [clone .part.0] () from /opt/root/lib/libCling.so
#14 0x00007f686cf834c9 in clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) () from /opt/root/lib/libCling.so
#15 0x00007f686cefacdc in clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) () from /opt/root/lib/libCling.so
#16 0x00007f686cf024d1 in clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) () from /opt/root/lib/libCling.so
#17 0x00007f686ceea03d in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) () from /opt/root/lib/libCling.so
#18 0x00007f686cf82b82 in clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) () from /opt/root/lib/libCling.so
#19 0x00007f686cefacdc in clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) () from /opt/root/lib/libCling.so
#20 0x00007f686cf024d1 in clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) () from /opt/root/lib/libCling.so
#21 0x00007f686ceea03d in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) () from /opt/root/lib/libCling.so
#22 0x00007f686cf82b82 in clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) () from /opt/root/lib/libCling.so
#23 0x00007f686cf838cd in clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) () from /opt/root/lib/libCling.so
#24 0x00007f686c7a9480 in cling::IncrementalParser::ParseInternal(llvm::StringRef) () from /opt/root/lib/libCling.so
#25 0x00007f686c7aa1f1 in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) () from /opt/root/lib/libCling.so
#26 0x00007f686c709ee5 in cling::Interpreter::declare(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Transaction**) () from /opt/root/lib/libCling.so
#27 0x00007f686c5b657a in InjectModuleUtilHeader(char const*, ROOT::TModuleGenerator&, cling::Interpreter&, bool) () from /opt/root/lib/libCling.so
#28 0x00007f686c5ca01a in RootClingMain(int, char**, bool) () from /opt/root/lib/libCling.so
#29 0x00007f686c5d3b4d in ROOT_rootcling_Driver () from /opt/root/lib/libCling.so
#30 0x0000562095a00140 in main ()
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum https://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  0x00007f686f023714 in clang::NestedNameSpecifier::containsUnexpandedParameterPack() const () from /opt/root/lib/libCling.so
#7  0x00007f686d7c5f25 in clang::Sema::DiagnoseUnexpandedParameterPack(clang::CXXScopeSpec const&, clang::Sema::UnexpandedParameterPackContext) () from /opt/root/lib/libCling.so
#8  0x00007f686d26731d in clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) () from /opt/root/lib/libCling.so
#9  0x00007f686d26809f in clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) () from /opt/root/lib/libCling.so
#10 0x00007f686ced5753 in clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) () from /opt/root/lib/libCling.so
#11 0x00007f686cee8ccc in clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) () from /opt/root/lib/libCling.so
#12 0x00007f686cf7ccba in clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) () from /opt/root/lib/libCling.so
#13 0x00007f686cf7d395 in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) [clone .part.0] () from /opt/root/lib/libCling.so
#14 0x00007f686cf834c9 in clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) () from /opt/root/lib/libCling.so
#15 0x00007f686cefacdc in clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) () from /opt/root/lib/libCling.so
#16 0x00007f686cf024d1 in clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) () from /opt/root/lib/libCling.so
#17 0x00007f686ceea03d in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) () from /opt/root/lib/libCling.so
#18 0x00007f686cf82b82 in clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) () from /opt/root/lib/libCling.so
#19 0x00007f686cefacdc in clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) () from /opt/root/lib/libCling.so
#20 0x00007f686cf024d1 in clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) () from /opt/root/lib/libCling.so
#21 0x00007f686ceea03d in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) () from /opt/root/lib/libCling.so
#22 0x00007f686cf82b82 in clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) () from /opt/root/lib/libCling.so
#23 0x00007f686cf838cd in clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) () from /opt/root/lib/libCling.so
#24 0x00007f686c7a9480 in cling::IncrementalParser::ParseInternal(llvm::StringRef) () from /opt/root/lib/libCling.so
#25 0x00007f686c7aa1f1 in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) () from /opt/root/lib/libCling.so
#26 0x00007f686c709ee5 in cling::Interpreter::declare(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Transaction**) () from /opt/root/lib/libCling.so
#27 0x00007f686c5b657a in InjectModuleUtilHeader(char const*, ROOT::TModuleGenerator&, cling::Interpreter&, bool) () from /opt/root/lib/libCling.so
#28 0x00007f686c5ca01a in RootClingMain(int, char**, bool) () from /opt/root/lib/libCling.so
#29 0x00007f686c5d3b4d in ROOT_rootcling_Driver () from /opt/root/lib/libCling.so
#30 0x0000562095a00140 in main ()
===========================================================

It would be great if RootMacros.cmake could be modified so that ROOT_GENERATE_DICTIONARY accepts a flag that is custom INCLUDE_PATHS. There is alraedy the NODEPHEADER argument, so this would go in the same direction, a NODEPHEADERFOLDER.

I have prepared a minimal reproducer, so that it’s easier to explain. See attached:
zdt-daq.zip (32.8 KB)

  • unzip
  • mkdir build && cd build
  • cmake …/ -DROOT_DIR=/opt/root
  • make -j4
  • ./gui/runGUI
  • Go to the last Tab
  • Type fThCont and press enter
  • Class is well recognized by ROOT’s interpreter.
  • So everything works perfect with the dictionaries, and I am just looking for not polluting further targets after this one.

Now to the solution attempts. Open gui/CMakeLists.txt and “comment” line 17:

  • Run make again, build will fail (header not found)
  • Add “MODULE ZDTcore” to line 20
  • Run make again, either cling will crash as before, or header still not found

Ok we are out of my depth, we need @Axel or @bellenot :sweat_smile:

I’ll investigate

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.