Skip to content

Commit 9bc5328

Browse files
committed
[CMake] Build rootcint and genreflex as separate targets
This makes the CMake code more robust. Right now, we use some `install(CODE "execute_process(COMMAND ln -f ...` solution on unix to install `rootcint` and `genreflex`. This does not work in all cases, either because of the usage of `\$ENV{DESTDIR}` when `DESTDIR` is not set, or because hard links are not allowed. Always copying `rootcling` - already in the build tree - would avoid that problem, but by copying we risk sidestepping the CMake mechanisms to set the RPath correctly when installing the copies, which are not actual targets. To make makes things simpler and more robust, this commit suggests to build the `rootcing` and `genreflex` executables as separate targets from the same source. The cost is very little cost in memory (`rootcling` is only 31K, so copying two times only increases the size of ROOTs `bin` directory by 1.5 %) and little in compile time (the extra compile time is less than a second, not noticable in parallel builds).
1 parent 8551484 commit 9bc5328

File tree

1 file changed

+24
-46
lines changed

1 file changed

+24
-46
lines changed

main/CMakeLists.txt

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -94,52 +94,30 @@ set_source_files_properties(src/rootcling.cxx PROPERTIES
9494
VISIBILITY_INLINES_HIDDEN "ON"
9595
)
9696

97-
ROOT_EXECUTABLE(rootcling src/rootcling.cxx LIBRARIES RIO Cling Core Rint)
98-
99-
# rootcling includes the ROOT complex header which would build the complex
100-
# dictionary with modules. To make sure that rootcling_stage1 builds this
101-
# dict before we use it, we add a dependency here.
102-
add_dependencies(rootcling complexDict)
103-
104-
target_include_directories(rootcling PRIVATE
105-
${CMAKE_SOURCE_DIR}/core/metacling/res
106-
${CMAKE_SOURCE_DIR}/core/dictgen/res
107-
${CMAKE_SOURCE_DIR}/io/rootpcm/res)
108-
set_property(TARGET rootcling PROPERTY ENABLE_EXPORTS 1)
109-
if(WIN32)
110-
set_target_properties(rootcling PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1)
111-
set_property(TARGET rootcling APPEND_STRING PROPERTY LINK_FLAGS " -STACK:4000000")
112-
endif()
97+
set(rootcling_exe_names rootcling genreflex rootcint)
98+
99+
foreach(exe_name IN LISTS rootcling_exe_names)
100+
ROOT_EXECUTABLE(${exe_name} src/rootcling.cxx LIBRARIES RIO Cling Core Rint)
101+
102+
# rootcling includes the ROOT complex header which would build the complex
103+
# dictionary with modules. To make sure that rootcling_stage1 builds this
104+
# dict before we use it, we add a dependency here.
105+
add_dependencies(${exe_name} complexDict)
106+
107+
target_include_directories(${exe_name} PRIVATE
108+
${CMAKE_SOURCE_DIR}/core/metacling/res
109+
${CMAKE_SOURCE_DIR}/core/dictgen/res
110+
${CMAKE_SOURCE_DIR}/io/rootpcm/res)
111+
set_property(TARGET ${exe_name} PROPERTY ENABLE_EXPORTS 1)
112+
if(WIN32)
113+
set_target_properties(${exe_name} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1)
114+
set_property(TARGET ${exe_name} APPEND_STRING PROPERTY LINK_FLAGS " -STACK:4000000")
115+
endif()
116+
endforeach()
113117

114-
ROOT_EXECUTABLE(rootls src/rootls.cxx LIBRARIES RIO Tree Core Rint ROOTNTuple)
118+
# To inherit the dependencies from rootcling
119+
add_dependencies(genreflex rootcling)
120+
add_dependencies(rootcint rootcint)
115121

116-
# Create aliases: rootcint, genreflex.
117-
if(WIN32)
118-
add_custom_command(TARGET rootcling POST_BUILD
119-
COMMAND copy /y rootcling.exe rootcint.exe
120-
COMMAND copy /y rootcling.exe genreflex.exe
121-
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
122-
else()
123-
add_custom_command(TARGET rootcling POST_BUILD
124-
COMMAND ln -f rootcling rootcint
125-
COMMAND ln -f rootcling genreflex
126-
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
127-
endif()
128-
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
129-
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/rootcint;${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/genreflex")
130122

131-
if(CMAKE_HOST_UNIX)
132-
install(CODE "execute_process(COMMAND ln -f rootcling rootcint WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})" COMPONENT applications)
133-
install(CODE "execute_process(COMMAND ln -f rootcling genreflex WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})" COMPONENT applications)
134-
else()
135-
if(MSVC)
136-
install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/rootcling.exe DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT applications)
137-
install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/rootcint.exe DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT applications)
138-
install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/genreflex.exe DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT applications)
139-
else()
140-
install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/rootcint
141-
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/genreflex
142-
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/rlibmap
143-
DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT applications)
144-
endif()
145-
endif()
123+
ROOT_EXECUTABLE(rootls src/rootls.cxx LIBRARIES RIO Tree Core Rint ROOTNTuple)

0 commit comments

Comments
 (0)