Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some ideas on add_root_dictionary #1

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 31 additions & 19 deletions cmake/AddRootDictionary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,25 @@ include_guard()
# Note also that the generated dictionary is added to PRIVATE SOURCES list of
# the target.
#
function(add_root_dictionary)
function(add_root_dictionary target)
cmake_parse_arguments(PARSE_ARGV
1
A
""
"LINKDEF;BASENAME"
"LINKDEF"
"HEADERS")
if(A_UNPARSED_ARGUMENTS)
message(
FATAL_ERROR "Unexpected unparsed arguments: ${A_UNPARSED_ARGUMENTS}")
endif()

if(${ARGC} LESS 4)
message(
FATAL_ERROR "Wrong number of arguments. All arguments are required.")
endif()

set(target ${ARGV0})
set(required_args "LINKDEF;HEADERS")
foreach(required_arg IN LISTS required_args)
if(NOT A_${required_arg})
message(
FATAL_ERROR "Missing required argument: ${required_arg}")
endif()
endforeach()

# check all given filepaths are relative ones
foreach(h ${A_HEADERS} ${A_LINKDEF})
Expand All @@ -79,8 +80,22 @@ function(add_root_dictionary)
endif()
endforeach()

set(dictionaryFile ${CMAKE_CURRENT_BINARY_DIR}/G__${A_BASENAME}Dict.cxx)
set(pcmFile G__${A_BASENAME}Dict_rdict.pcm)
# Generate the pcm and rootmap files alongside the library
get_property(lib_output_dir TARGET ${target} PROPERTY LIBRARY_OUTPUT_DIRECTORY)
if(NOT lib_output_dir)
set(lib_output_dir ${CMAKE_CURRENT_BINARY_DIR})
endif()

# Define the names of generated files
get_property(basename TARGET ${target} PROPERTY OUTPUT_NAME)
if(NOT basename)
set(basename ${target})
endif()
set(dictionary G__${basename})
set(dictionaryFile ${CMAKE_CURRENT_BINARY_DIR}/${dictionary}.cxx)
set(pcmTarget lib${basename})
set(pcmFile ${lib_output_dir}/${pcmTarget}_rdict.pcm)
set(rootmapFile ${lib_output_dir}/lib${basename}.rootmap)

# get the list of compile_definitions and split it into -Dxxx pieces but only
# if non empty
Expand All @@ -97,30 +112,27 @@ function(add_root_dictionary)
set(LD_LIBRARY_PATH "${LD_LIBRARY_PATH}:$ENV{GCC_TOOLCHAIN_ROOT}/lib64")
endif()

if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()

# add a custom command to generate the dictionary using rootcling
# cmake-format: off
add_custom_command(
OUTPUT ${dictionaryFile}
OUTPUT ${dictionaryFile} ${pcmFile} ${rootmapFile}
VERBATIM
COMMAND
${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${LD_LIBRARY_PATH} ${ROOT_rootcling_CMD}
-f
${dictionaryFile}
-inlineInputHeader
-rmf ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${A_BASENAME}.rootmap
-rmf ${rootmapFile}
-rml $<TARGET_FILE:${target}>
-s ${pcmTarget}
$<GENEX_EVAL:-I$<JOIN:$<TARGET_PROPERTY:${target},INCLUDE_DIRECTORIES>,\;-I>>
# the generator expression above gets the list of all include
# directories that might be required using the transitive dependencies
# of the target ${target} and prepend each item of that list with -I
"${defs}"
${incdirs} ${headers}
COMMAND
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${pcmFile} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${pcmFile}
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${pcmTarget}_rdict.pcm ${pcmFile}
COMMAND_EXPAND_LISTS
DEPENDS ${headers})
# cmake-format: on
Expand Down Expand Up @@ -150,8 +162,8 @@ function(add_root_dictionary)

# will install the rootmap and pcm files alongside the target's lib
get_filename_component(dict ${dictionaryFile} NAME_WE)
install(FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${A_BASENAME}.rootmap
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${dict}_rdict.pcm
install(FILES ${rootmapFile}
${pcmFile}
DESTINATION ${CMAKE_INSTALL_LIBDIR})

endfunction()