Skip to content

Commit ec42560

Browse files
committed
[CMake] Simplify writing of modulemap.
Instead of a two-step process that writes the dynamic contents at CMake configure time, and a build-time step that concatenates the static and dynamic part of the modulemap, CMake's configure_file() is used to directly write the full contents at configure time. As usual for configure files, the time stamp only changes when the file contents change, so spurious rebuilds of the modules are avoided.
1 parent 2d4ed63 commit ec42560

File tree

3 files changed

+6
-27
lines changed

3 files changed

+6
-27
lines changed

CMakeLists.txt

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -421,36 +421,14 @@ get_property(__allBuiltins GLOBAL PROPERTY ROOT_BUILTIN_TARGETS)
421421
add_custom_target(move_headers ALL DEPENDS ${__allHeaders} ${__allBuiltins} gitinfotxt)
422422

423423
#---CXX MODULES-----------------------------------------------------------------------------------
424-
if(MSVC)
425-
set(_os_cat "type")
426-
else()
427-
set(_os_cat "cat")
428-
endif()
429-
cmake_path(CONVERT "${CMAKE_BINARY_DIR}/include/module.modulemap.extra" TO_NATIVE_PATH_LIST _from_native)
430-
cmake_path(CONVERT "${CMAKE_BINARY_DIR}/include/ROOT.modulemap" TO_NATIVE_PATH_LIST _to_native)
431-
432-
add_custom_target(copymodulemap DEPENDS "${CMAKE_BINARY_DIR}/include/ROOT.modulemap")
433-
add_custom_command(
434-
OUTPUT "${CMAKE_BINARY_DIR}/include/ROOT.modulemap"
435-
DEPENDS cmake/unix/module.modulemap "${CMAKE_BINARY_DIR}/include/module.modulemap.extra"
436-
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/cmake/unix/module.modulemap" "${CMAKE_BINARY_DIR}/include/ROOT.modulemap"
437-
COMMAND ${_os_cat} "${_from_native}" >> "${_to_native}"
438-
)
439-
install(FILES "${CMAKE_BINARY_DIR}/include/ROOT.modulemap" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT headers)
440-
441-
add_dependencies(move_headers copymodulemap)
442-
443424
# Take all the modulemap contents we collected from the packages and append them to our modulemap.
444425
# We have to delay this because the ROOT_CXXMODULES_EXTRA_MODULEMAP_CONTENT is filled in the
445426
# add_subdirectory calls above.
446427
get_property(__modulemap_extra_content GLOBAL PROPERTY ROOT_CXXMODULES_EXTRA_MODULEMAP_CONTENT)
447-
string(REPLACE ";" "" __modulemap_extra_content "${__modulemap_extra_content}")
448-
# Write module.modulemap.extra to a temporary file first, to not touch module.modulemap.extra
449-
# if it's unchanged.
450-
file(WRITE "${CMAKE_BINARY_DIR}/include/module.modulemap.extra.tmp" "${__modulemap_extra_content}")
451-
configure_file("${CMAKE_BINARY_DIR}/include/module.modulemap.extra.tmp"
452-
"${CMAKE_BINARY_DIR}/include/module.modulemap.extra"
453-
COPYONLY)
428+
string(REPLACE ";" "" ROOT_GENERATED_MODULEMAP_CONTENT "${__modulemap_extra_content}")
429+
# Now append the generated content to the original modulemap
430+
configure_file(${CMAKE_SOURCE_DIR}/cmake/unix/module.modulemap ${CMAKE_BINARY_DIR}/include/ROOT.modulemap)
431+
install(FILES "${CMAKE_BINARY_DIR}/include/ROOT.modulemap" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT headers)
454432

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

cmake/modules/RootMacros.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ function(ROOT_GENERATE_DICTIONARY dictionary)
558558
set(cpp_module_file ${library_output_dir}/${cpp_module}.pcm)
559559
# The module depends on its modulemap file.
560560
if (cpp_module_file AND CMAKE_PROJECT_NAME STREQUAL ROOT)
561-
set (runtime_cxxmodule_dependencies copymodulemap "${CMAKE_BINARY_DIR}/include/ROOT.modulemap")
561+
set (runtime_cxxmodule_dependencies "${CMAKE_BINARY_DIR}/include/ROOT.modulemap")
562562
endif()
563563
endif(cpp_module)
564564
endif()

cmake/unix/module.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ module "Graf3D.X3DBuffer.h_C" {
7070
}
7171

7272
// From this point on the contents of this file are automatically generated.
73+
@ROOT_GENERATED_MODULEMAP_CONTENT@

0 commit comments

Comments
 (0)