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