ROOT_GENERATE_DICTIONARY always rebuilds

This is a follow-up to a question I asked about ROOT_GENERATE_DICTIONARY.

I have a project that builds a shared library using ROOT_GENERATE_DICTIONARY, which is then linked into a number of programs in other directories. The compilation, linking, and execution all work.

However, every time I type make, the shared library is always rebuilt, even if no changes have been made to any of the files on which ROOT_GENERATE_LIBRARY depends. Here’s a typical excerpt from the build output:

[  1%] Generating DataObjDict.cxx, DataObjDict.h
[ 27%] Building CXX object GramsDataObj/CMakeFiles/GramsSimProjectDataObj.dir/DataObjDict.cxx.o
[ 28%] Linking CXX shared library libGramsSimProjectDataObj.so
[ 36%] Built target GramsSimProjectDataObj

This would be fine, except that there should be no reason to regenerate DataObjDict.cxx or libGramsSimProjectDataObj.so if none of the files in GramsDataObj change.

Here’s the contents of CMakeLists.txt in GramsDataObj, the directory that contains the data objects used to create the shared dictionary library:

file(GLOB headerList ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
file(GLOB DataObjSrc src/*.cc
                    ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc
    )

set(LinkDef ${CMAKE_CURRENT_SOURCE_DIR}/include/LinkDef.hh)
set(Dictionary ${CMAKE_CURRENT_BINARY_DIR}/DataObjDict)
set(LibName ${CMAKE_PROJECT_NAME}DataObj)

ROOT_GENERATE_DICTIONARY ( ${Dictionary} ${headerList} LINKDEF ${LinkDef} )

add_library (${LibName} SHARED ${Dictionary}.cxx ${DataObjSrc})
target_include_directories (${LibName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

In other directories that depend on the dictionary, I have this in their CMakeLists.txt:

   target_link_libraries(${_prog} ${CMAKE_PROJECT_NAME}DataObj)
   target_link_options(${_prog} PRIVATE "LINKER:-no-as-needed")

This isn’t a fatal problem. However, if I do development work on ProgramA, and every make causes a fresh libGramsSimProjectDataObj.so to be built, then every program in the project gets re-linked. This makes the rebuild process take longer. It’s also somewhat against the principle of using cmake and make in the first place.

Am I overlooking something?


ROOT Version: 6.24/06
Platform: AlmaLinux 9
Compiler: gcc 9.5.0


Hello,

The CMake snippet looks well done, but we might need an expert in the loop. Have you tried not using globs?

Cheers,
Danilo

I have not, but GLOB has worked in my other cmake scripts up until now. I understand the reasons for not liking them, but they do work. A cmake expert would have to explain to me why they fail to generate the correct dependencies with ROOT_GENERATE_DICTIONARY but do generate the correct behavior in every other sub-directory of my project.

I use GLOB because, in the unlikely event that one of my users wants to create a new data product or something similar, I know they’d fail to understand how cmake works or how to add their new program/script to CMakeLists.txt.

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