How to invoke ROOT_GENERATE_DICTIONARY with several header files

Hi,

In order to build a library, I’m generating a dictionary (only one) from several header files in a Cmake file using ROOT_GENERATE_DICTIONARY.

The following solution works fine, but is very long due to the number of header files to be included:

ROOT_GENERATE_DICTIONARY(
MyCodeClassesDict "${PROJECT_SOURCE_DIR}/inc/Data.h" "${PROJECT_SOURCE_DIR}/inc/DiagnosticFunctions.h" 
...
LINKDEF ${PROJECT_SOURCE_DIR}/inc/LinkDef.h MODULE MyCodeClasses)

What I would like to have is something more compact like this:

ROOT_GENERATE_DICTIONARY(
  MyCodeClassesDict ${headers_list}
  LINKDEF ${PROJECT_SOURCE_DIR}/inc/LinkDef.h
  MODULE MyCodeClasses)

Ideally, I’d like to define the variable ${headers_list} from a loop. I tried using a big string with all file names in quotes, I tried a list. However, I can’t find the proper way to do it so that it works.
Is there a way to do that?

Thanks a lot for your help!

All the best,
Julien


_ROOT Version: 6.24.06
_Platform: Mac OS 11.6.3
_Compiler: clang-1300.0.29.3


Hello,

Here’s an example of how headers are placed in a list:

and then used in a ROOT CMake macro:

Hi,

Thanks for your answer. This solution however seems not to work when used with ROOT_GENERATE_DICTIONARY.
I found a way around by renaming the LinkDef header to LinkDef.hh (with extension hh instead of simply h), and using

file(GLOB header_files ${PROJECT_SOURCE_DIR}/inc/*.h)

ROOT_GENERATE_DICTIONARY(
  LIVlihoodClassesDict ${header_files}
  LINKDEF ${PROJECT_SOURCE_DIR}/inc/LinkDef.hh
  MODULE LIVlihoodClasses)

That way, the LinkDef.hh file is not included in ${header_files}.

The question still remains: how could I build a custom ${header_files} list, possibly using a loop? Or how to build a list of header files which would behave the same way as file(GLOB …)?

All the best,
Julien

Hello,

I’m not sure I understand, why do you need a loop? You would loop over what exactly?

So creating a list like this, with the explicit headers you want:

    list(APPEND ${header_files}
        ${PROJECT_SOURCE_DIR}/inc/fileone.h
        ${PROJECT_SOURCE_DIR}/inc/filetwo.h
        ...)

and then

ROOT_GENERATE_DICTIONARY(
  LIVlihoodClassesDict ${header_files}
  LINKDEF ${PROJECT_SOURCE_DIR}/inc/LinkDef.h
  MODULE LIVlihoodClasses)

does not work?

The point is I don’t want to write all files explicitly like this:

list(APPEND ${header_files}
        ${PROJECT_SOURCE_DIR}/inc/fileone.h
        ${PROJECT_SOURCE_DIR}/inc/filetwo.h
        ...)

If I have 20 header files, it would mean 20 lines in the CMake file, and I don’t want that.

I think now that using different extensions like .h if I want to include the header file in the dictionary generation, and .hh if I don’t is probably the best solution. And contrary to the list(APPEND…) method, I don"t need to modify the CMakeLists file each time I add a new header.

All the best,
Julien

Hi,
this is really a CMake question. You can glob files with CMake, but it is usually recommended to explicitly list source files to avoid “surprises”, see also how to use CMake file (GLOB SRCS *. ) with a build directory - Stack Overflow .

I hope this helps!
Enrico

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