Skip to content

Commit

Permalink
ROOT.modulemap changed from single file to a distributed file set
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavlo Svirin committed Aug 13, 2024
1 parent 9669d42 commit 68bf200
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -458,32 +458,53 @@ if(MSVC)
else()
set(_os_cat "cat")
endif()

file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/include/module.modulemap.extra" _from_native)
file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/include/module.modulemap.split.extra" _from_native_split)

# we use this modulemap for compilation because modules can not be located in case
# of a distributed file. Should be fixed in the future.
file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/include/ROOT.modulemap" _to_native)
# this modulemap is installed together with its partial components
file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/include/ROOT.modulemap.split" _to_native_split)

make_directory("${CMAKE_BINARY_DIR}/include/ROOT.modulemap.d")

add_custom_target(copymodulemap DEPENDS "${CMAKE_BINARY_DIR}/include/ROOT.modulemap")
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/include/ROOT.modulemap"
DEPENDS build/unix/module.modulemap "${CMAKE_BINARY_DIR}/include/module.modulemap.extra"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/build/unix/module.modulemap" "${CMAKE_BINARY_DIR}/include/ROOT.modulemap"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/build/unix/module.modulemap" "${CMAKE_BINARY_DIR}/include/ROOT.modulemap.split"
COMMAND ${_os_cat} "${_from_native}" >> "${_to_native}"
COMMAND ${_os_cat} "${_from_native_split}" >> "${_to_native_split}"
)
install(FILES "${CMAKE_BINARY_DIR}/include/ROOT.modulemap" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT headers)
install(DIRECTORY "${CMAKE_BINARY_DIR}/include/ROOT.modulemap.d" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES "${CMAKE_BINARY_DIR}/include/ROOT.modulemap.split" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} RENAME "ROOT.modulemap")

add_dependencies(move_headers copymodulemap)

# Take all the modulemap contents we collected from the packages and append them to our modulemap.
# We have to delay this because the ROOT_CXXMODULES_EXTRA_MODULEMAP_CONTENT is filled in the
# add_subdirectory calls above.
get_property(__modulemap_extra_content GLOBAL PROPERTY ROOT_CXXMODULES_EXTRA_MODULEMAP_CONTENT)
get_property(__modulemap_split_extra_content GLOBAL PROPERTY ROOT_CXXMODULES_EXTRA_SPLIT_MODULEMAP_CONTENT)
string(REPLACE ";" "" __modulemap_extra_content "${__modulemap_extra_content}")
string(REPLACE ";" "" __modulemap_split_extra_content "${__modulemap_split_extra_content}")

# Write module.modulemap.extra to a temporary file first, to not touch module.modulemap.extra
# if it's unchanged.
file(WRITE "${CMAKE_BINARY_DIR}/include/module.modulemap.extra.tmp" "${__modulemap_extra_content}")
file(WRITE "${CMAKE_BINARY_DIR}/include/module.modulemap.split.extra.tmp" "${__modulemap_split_extra_content}")

configure_file("${CMAKE_BINARY_DIR}/include/module.modulemap.extra.tmp"
"${CMAKE_BINARY_DIR}/include/module.modulemap.extra"
COPYONLY)

configure_file("${CMAKE_BINARY_DIR}/include/module.modulemap.split.extra.tmp"
"${CMAKE_BINARY_DIR}/include/module.modulemap.split.extra"
COPYONLY)

# From now on we handled all exposed module and want to make all new modulemaps private to ROOT.
set(ROOT_CXXMODULES_WRITE_TO_CURRENT_DIR ON)

Expand Down
7 changes: 6 additions & 1 deletion cmake/modules/RootMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,12 @@ function (ROOT_CXXMODULES_APPEND_TO_MODULEMAP library library_headers)
endif()

else()
set_property(GLOBAL APPEND PROPERTY ROOT_CXXMODULES_EXTRA_MODULEMAP_CONTENT ${modulemap_entry})
#set_property(GLOBAL APPEND PROPERTY ROOT_CXXMODULES_EXTRA_MODULEMAP_CONTENT ${modulemap_entry})
set_property(GLOBAL APPEND PROPERTY ROOT_CXXMODULES_EXTRA_SPLIT_MODULEMAP_CONTENT "extern module ${library} \"ROOT.modulemap.d/${library}.modulemap\"\n")
set_property(GLOBAL APPEND PROPERTY ROOT_CXXMODULES_EXTRA_MODULEMAP_CONTENT "extern module ${library} \"${library}.modulemap\"\n")

file(WRITE "${CMAKE_BINARY_DIR}/include/ROOT.modulemap.d/${library}.modulemap" "${modulemap_entry}")
file(WRITE "${CMAKE_BINARY_DIR}/include/${library}.modulemap" "${modulemap_entry}")
endif()
endfunction()

Expand Down

0 comments on commit 68bf200

Please sign in to comment.