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

Enable C++ Modules #385

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
1ccfdaf
Replaced genreflex with rootcling
imorlxs Jul 11, 2024
2e4dcd7
Added solution from FairROOT/#385
imorlxs Jul 17, 2024
0c3e4c9
Get rid of genreflex instances
imorlxs Jul 24, 2024
aacbf40
Remove -cxxmodule flag
imorlxs Jul 24, 2024
9a7680a
Remove LAUNCHER invocation
imorlxs Jul 27, 2024
e79411f
Add -f flag to overwrite files
imorlxs Jul 27, 2024
083b433
Removed double minus to keep the code clean
imorlxs Jul 27, 2024
8139c5b
Fix whitespace changes
imorlxs Aug 5, 2024
21ad68d
Remove --select from bdm-code-generation
imorlxs Aug 5, 2024
68f110d
Remove trim whitespaces
imorlxs Aug 7, 2024
7bed670
Changed rootcling calls to be the same
imorlxs Aug 7, 2024
59a6ce7
Add RootMacros.cmake
imorlxs Aug 14, 2024
6a09c01
Add support for REFLEX argument.
imorlxs Aug 14, 2024
e7f40b3
Change .cxx entension to .cc
imorlxs Aug 14, 2024
23ace61
Include RootMacros to the CMake Project
imorlxs Aug 14, 2024
6f401fe
Add ROOT_GENERATE_DICTIONARY invocation
imorlxs Aug 14, 2024
c9db0b9
Fix rootcling executable invocation
imorlxs Aug 14, 2024
77cd6dc
Add launcher to rootcling invocation
imorlxs Aug 14, 2024
e684441
Add --noIncludePaths and --inlineInputHeader args
imorlxs Aug 14, 2024
6d1c574
Merge branch 'master' into cppmodules
imorlxs Aug 14, 2024
3791701
Include RootMacros.cmake in CMakeLists
imorlxs Aug 14, 2024
6a2743a
Testing with a different include path
imorlxs Aug 14, 2024
55e2592
Fix RootMacros include path
imorlxs Aug 14, 2024
5de61fe
Change full path to relative path on ROOT_GENERATE_DICTIONARY
imorlxs Aug 19, 2024
73b7df5
Add deleted code
imorlxs Aug 23, 2024
1b0dee0
Changed path of module.modulemap
imorlxs Aug 27, 2024
e5fc01a
Add runtime_cxxmodules option
imorlxs Aug 27, 2024
f896784
Remove _dict suffix
imorlxs Aug 27, 2024
56a3a8e
Fix self-contained headers problem
imorlxs Aug 30, 2024
8b35112
It compiles!
imorlxs Sep 2, 2024
3f71ebf
Add modulemapfile option
imorlxs Sep 4, 2024
f6d897c
Now it compiles!
imorlxs Sep 16, 2024
a399cb5
Fix submission
imorlxs Sep 16, 2024
43f415d
Modify modulemap path
imorlxs Sep 17, 2024
189438d
Added modulemap env variable
imorlxs Sep 17, 2024
540bab0
Add -modulemapfile flag
imorlxs Sep 17, 2024
51f8c0b
First copy the files in the include dir
imorlxs Sep 17, 2024
5e6acc3
Changed some variables
imorlxs Sep 28, 2024
e36e3f7
Fix deprecated Cmake call `FetchContent_Populate` (#387)
imorlxs Aug 26, 2024
e67be81
Add ROOT supporting new Xcode 16.0 on macOS 15.0 and 14.7.
FonsRademakers Sep 18, 2024
8954286
Update sha256 for ROOT for i386 for Xcode 16.0 on macOS 14.7 and 15.0.
FonsRademakers Sep 18, 2024
ba20129
Change bits/stdint-uintn.h for stdint.h to add macOS support
imorlxs Oct 8, 2024
e093b4c
Changed bits/std_function.hto functional
imorlxs Oct 8, 2024
68332b8
Fix missing behavior header
imorlxs Oct 16, 2024
2c4114c
Added the -cxxmodules flag to bdm-dictionary. With C++ Modules, we do…
imorlxs Dec 11, 2024
ac5524d
Add missing endif()
imorlxs Dec 11, 2024
7a2d6b3
Format code and fix wrong variable name
imorlxs Dec 11, 2024
1f79202
Add BDM_CXXMODULES variable to track if BDM was built with cxxmodules
imorlxs Dec 11, 2024
301b75f
Merge main into this branch
imorlxs Dec 11, 2024
8c84c55
Fix wrong variable name
imorlxs Dec 11, 2024
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ root = true
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
trim_trailing_whitespace = false
indent_style = space
indent_size = 2

Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ option(website "Enable website generation (make website<-live>)." OFF)
option(valgrind "Enable valgrind tests and make build compatible with valgrind tool." ON)
option(rpath "Link libraries with built-in RPATH (run-time search path)." OFF)
option(real_t "Define data type for real numbers. Currently supported: float, double" double)
option(runtime_cxxmodules "Enable C++ Modules support." ON)

if(APPLE)
# ParaView on Apple devices
Expand Down Expand Up @@ -504,6 +505,7 @@ file(COPY ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/launcher.sh
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

# -------------------- includes -----------------------------------------------
include(RootMacros)
include(BioDynaMo)
include(ExternalProject)
include(Documentation)
Expand Down
31 changes: 25 additions & 6 deletions cmake/BioDynaMo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,33 @@ function(build_shared_library TARGET)
# We always need dictionaries for the plugins (plugin manager requires class
# information)
if(dict OR DEFINED ARG_PLUGIN)
# generate dictionary using genreflex
# generate dictionary using rootcling reflex
set(DICT_FILE "${CMAKE_CURRENT_BINARY_DIR}/lib${TARGET}_dict")
set(BDM_DICT_FILE "${CMAKE_CURRENT_BINARY_DIR}/lib${TARGET}_bdm_dict.cc")
set(ROOT_HEADERS)
string(REPLACE "${CMAKE_SOURCE_DIR}/src/" "" ROOT_HEADERS_TEMP "${ARG_HEADERS}")
string(REPLACE "${CMAKE_SOURCE_DIR}/test/" "" ROOT_HEADERS "${ROOT_HEADERS_TEMP}")


if (runtime_cxxmodules)
set(MODULEMAP "--moduleMapFile=${CMAKE_BINARY_DIR}/include/module.modulemap")
else()
set(NO_MODULE "NO_CXXMODULE")
endif()

if (NOT ${TARGET} STREQUAL "biodynamo")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if can be removed as is not longer necessary

#set(DEPENDENCY_OPTION "-m ${CMAKE_CURRENT_BINARY_DIR}/lib/biodynamo.pcm")
#set(NO_MODULE "NO_CXXMODULE")
#set(MODULEMAP)
endif()

# Since the location of the CMake files differ in the build and installation
# directory, we check if BDM_CMAKE_DIR is already set (in build directory
# case). Otherwise, set it to the installation directory
if(NOT DEFINED BDM_CMAKE_DIR)
set(BDM_CMAKE_DIR $ENV{BDMSYS}/share/cmake)
endif()
REFLEX_GENERATE_DICTIONARY(${DICT_FILE} ${ARG_HEADERS} SELECTION ${BDM_CMAKE_DIR}/${ARG_SELECTION})
ROOT_GENERATE_DICTIONARY(${DICT_FILE} ${ROOT_HEADERS} MODULE ${TARGET} LINKDEF ${BDM_CMAKE_DIR}/${ARG_SELECTION} REFLEX ${NO_MODULE} OPTIONS ${DEPENDENCY_OPTION} -I src --inlineInputHeader --noIncludePaths ${MODULEMAP})
if (BDM_OUT_OF_SOURCE)
set(BDM_DICT_BIN_PATH "$ENV{BDMSYS}/bin")
else()
Expand All @@ -130,8 +146,11 @@ function(build_shared_library TARGET)
else()
set(BDM_OUT_OF_SRC_ARG --bdm-source ${CMAKE_SOURCE_DIR})
endif()
if (BDM_CXXMODULES)
set(BDM_CXX_MODULES_ARG "--cxxmodules")
endif()
add_custom_command(OUTPUT "${BDM_DICT_FILE}"
COMMAND ${Python_EXECUTABLE} ${BDM_DICT_BIN_PATH}/bdm-dictionary ${BDM_OUT_OF_SRC_ARG} --output ${BDM_DICT_FILE} --include-dirs ${INCLUDE_DIRS} --headers ${ARG_HEADERS}
COMMAND ${Python_EXECUTABLE} ${BDM_DICT_BIN_PATH}/bdm-dictionary ${BDM_OUT_OF_SRC_ARG} ${BDM_CXX_MODULES_ARG} --output ${BDM_DICT_FILE} --include-dirs ${INCLUDE_DIRS} --headers ${ARG_HEADERS}
DEPENDS ${ARG_HEADERS} ${BDM_DICT_BIN_PATH}/bdm-dictionary)
# generate shared library
add_library(${TARGET} SHARED ${ARG_SOURCES} ${DICT_FILE}.cc ${BDM_DICT_FILE})
Expand All @@ -140,9 +159,9 @@ function(build_shared_library TARGET)
endif()
target_link_libraries(${TARGET} ${ARG_LIBRARIES})
if (DEFINED CMAKE_INSTALL_LIBDIR)
add_custom_command(TARGET ${TARGET}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${DICT_FILE}_rdict.pcm ${CMAKE_INSTALL_LIBDIR})
# add_custom_command(TARGET ${TARGET}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this code is not longer necessary, as ROOT_GENERATE_DICTIONARY already generates the .pcm in CMAKE_INSTALL_LIBDIR

# POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy ${DICT_FILE}_rdict.pcm ${CMAKE_INSTALL_LIBDIR})
endif()
else()
add_library(${TARGET} SHARED ${ARG_SOURCES})
Expand Down
98 changes: 0 additions & 98 deletions cmake/FindROOT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,108 +97,10 @@ mark_as_advanced(ROOT_CONFIG_EXECUTABLE)
include(CMakeParseArguments)
find_program(ROOTCLING_EXECUTABLE rootcling
HINTS "$ENV{ROOTSYS}/bin" "$ENV{BDM_ROOT_DIR}/bin" "${CMAKE_THIRD_PARTY_DIR}/root/bin")
find_program(GENREFLEX_EXECUTABLE genreflex
HINTS "$ENV{ROOTSYS}/bin" "$ENV{BDM_ROOT_DIR}/bin" "${CMAKE_THIRD_PARTY_DIR}/root/bin")
#find_package(GCCXML)

# We use the launcher script to emulate a `source thisbdm.sh` call
if(NOT BDM_OUT_OF_SOURCE)
set(LAUNCHER ${CMAKE_BINARY_DIR}/launcher.sh)
endif()

#----------------------------------------------------------------------------
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is now in RootMacros.cmake, imported from the root source code.

# function ROOT_GENERATE_DICTIONARY( dictionary
# header1 header2 ...
# LINKDEF linkdef1 ...
# OPTIONS opt1...)
function(ROOT_GENERATE_DICTIONARY dictionary)
CMAKE_PARSE_ARGUMENTS(ARG "" "" "LINKDEF;OPTIONS" "" ${ARGN})
#---Get the list of include directories------------------
get_directory_property(incdirs INCLUDE_DIRECTORIES)
set(includedirs)
foreach( d ${incdirs})
set(includedirs ${includedirs} -I${d})
endforeach()
#---Get the list of header files-------------------------
set(headerfiles)
foreach(fp ${ARG_UNPARSED_ARGUMENTS})
if(${fp} MATCHES "[*?]") # Is this header a globbing expression?
file(GLOB files ${fp})
foreach(f ${files})
if(NOT f MATCHES LinkDef) # skip LinkDefs from globbing result
set(headerfiles ${headerfiles} ${f})
endif()
endforeach()
else()
find_file(headerFile ${fp} HINTS ${incdirs})
set(headerfiles ${headerfiles} ${headerFile})
unset(headerFile CACHE)
endif()
endforeach()
#---Get LinkDef.h file------------------------------------
set(linkdefs)
foreach( f ${ARG_LINKDEF})
find_file(linkFile ${f} HINTS ${incdirs})
set(linkdefs ${linkdefs} ${linkFile})
unset(linkFile CACHE)
endforeach()
#---call rootcling------------------------------------------
add_custom_command(OUTPUT ${dictionary}.cxx
OUTPUT ${dictionary}_rdict.pcm
COMMAND ${LAUNCHER} ${ROOTCLING_EXECUTABLE} -f ${dictionary}.cxx
${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs}
DEPENDS ${headerfiles} ${linkdefs} VERBATIM)
endfunction()

#----------------------------------------------------------------------------
# function REFLEX_GENERATE_DICTIONARY(dictionary
# header1 header2 ...
# SELECTION selectionfile ...
# OPTIONS opt1...)
function(REFLEX_GENERATE_DICTIONARY dictionary)
CMAKE_PARSE_ARGUMENTS(ARG "" "" "SELECTION;OPTIONS" "" ${ARGN})
#---Get the list of header files-------------------------
set(headerfiles)
foreach(fp ${ARG_UNPARSED_ARGUMENTS})
file(GLOB files ${fp})
if(files)
foreach(f ${files})
set(headerfiles ${headerfiles} ${f})
endforeach()
else()
set(headerfiles ${headerfiles} ${fp})
endif()
endforeach()
#---Get Selection file------------------------------------
if(IS_ABSOLUTE ${ARG_SELECTION})
set(selectionfile ${ARG_SELECTION})
else()
set(selectionfile ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_SELECTION})
endif()
#---Get the list of include directories------------------
get_directory_property(incdirs INCLUDE_DIRECTORIES)
set(includedirs)
foreach( d ${incdirs})
set(includedirs ${includedirs} -I${d})
endforeach()
#---Get preprocessor definitions--------------------------
get_directory_property(defs COMPILE_DEFINITIONS)
foreach( d ${defs})
set(definitions ${definitions} -D${d})
endforeach()
#---Nanes and others---------------------------------------
set(gensrcdict ${dictionary}.cc)
if(MSVC)
set(gccxmlopts "--gccxmlopt=\"--gccxml-compiler cl\"")
else()
#set(gccxmlopts "--gccxmlopt=\'--gccxml-cxxflags -m64 \'")
set(gccxmlopts)
endif()
#set(rootmapname ${dictionary}Dict.rootmap)
#set(rootmapopts --rootmap=${rootmapname} --rootmap-lib=${libprefix}${dictionary}Dict)
#---Actual command----------------------------------------
add_custom_command(OUTPUT ${gensrcdict} ${rootmapname} ${dictionary}_rdict.pcm
COMMAND ${LAUNCHER} ${GENREFLEX_EXECUTABLE} ${headerfiles} -o ${gensrcdict} ${rootmapopts} --select=${selectionfile} --noIncludePaths
${ARG_OPTIONS} ${includedirs} ${definitions}
DEPENDS ${headerfiles} ${selectionfile})
endfunction()
Loading
Loading