-
Notifications
You must be signed in to change notification settings - Fork 64
[WIP] Support installation of C++20 modules (with non-ROOT functionality) #907
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
base: master
Are you sure you want to change the base?
Changes from 21 commits
1782778
eeeca16
9219cdd
8aec23b
528d5c4
a9141d4
59a0e30
e5cf1a9
2aab78a
e69da7c
c5ab024
5a049b7
dd06c41
60f19ea
6a68383
3d37bb6
8db7160
88c80f1
fcbc75c
14e46d3
5dc9a50
048ec04
621116a
61d424f
d5d9138
739b12e
2e991ad
6c6dafb
dfde5d6
0fac8aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,6 +135,12 @@ function(PODIO_GENERATE_DATAMODEL datamodel YAML_FILE RETURN_HEADERS RETURN_SOUR | |
| set(VERSION_ARG "--datamodel-version=${ARG_VERSION}") | ||
| endif() | ||
|
|
||
| # Check if C++20 modules should be generated | ||
| set(MODULES_ARG "") | ||
| if(PODIO_ENABLE_CXX_MODULES) | ||
| set(MODULES_ARG "--enable-modules") | ||
| endif() | ||
|
Comment on lines
+138
to
+142
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering whether this should be an explicit argument to the datamodel generation. For my understanding: This requires
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now the data model module definition (from The only thing from podio that is re-exported is: export namespace podio {
using podio::CollectionBase;
using podio::ICollectionProvider;
using podio::SchemaEvolution;
using podio::SchemaVersionT;
}That is significantly less than what's in As long as we don't re-export a different entity under the same name this is fine. They are ultimately just |
||
|
|
||
| # Make sure that we re run the generation process every time either the | ||
| # templates or the yaml file changes. | ||
| include(${podio_PYTHON_DIR}/templates/CMakeLists.txt) | ||
|
|
@@ -155,7 +161,7 @@ function(PODIO_GENERATE_DATAMODEL datamodel YAML_FILE RETURN_HEADERS RETURN_SOUR | |
| message(STATUS "Creating '${datamodel}' datamodel") | ||
| # we need to bootstrap the data model, so this has to be executed in the cmake run | ||
| execute_process( | ||
| COMMAND ${Python_EXECUTABLE} ${podio_PYTHON_DIR}/podio_class_generator.py ${CLANG_FORMAT_ARG} ${SCHEMA_EVOLUTION_ARG} ${UPSTREAM_EDM_ARG} ${YAML_FILE} ${ARG_OUTPUT_FOLDER} ${datamodel} ${ARG_IO_BACKEND_HANDLERS} ${LANGUAGE_ARG} ${VERSION_ARG} ${OLD_DESCRIPTION_ARG} | ||
| COMMAND ${Python_EXECUTABLE} ${podio_PYTHON_DIR}/podio_class_generator.py ${CLANG_FORMAT_ARG} ${SCHEMA_EVOLUTION_ARG} ${UPSTREAM_EDM_ARG} ${YAML_FILE} ${ARG_OUTPUT_FOLDER} ${datamodel} ${ARG_IO_BACKEND_HANDLERS} ${LANGUAGE_ARG} ${VERSION_ARG} ${MODULES_ARG} ${OLD_DESCRIPTION_ARG} | ||
| WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
| RESULT_VARIABLE podio_generate_command_retval | ||
| ) | ||
|
|
@@ -210,6 +216,21 @@ function(PODIO_ADD_DATAMODEL_CORE_LIB lib_name HEADERS SOURCES) | |
| CXX_CLANG_TIDY "" # Do not run clang-tidy on generated sources | ||
| # TODO: Update generation to generate compliant code already | ||
| ) | ||
|
|
||
| # Add C++20 module interface if it was generated | ||
| if(PODIO_ENABLE_CXX_MODULES) | ||
| # Check if module files were generated | ||
| include(${ARG_OUTPUT_FOLDER}/podio_generated_files.cmake) | ||
| if(DEFINED module_files AND module_files) | ||
| message(STATUS "Adding C++20 module interface to ${lib_name}") | ||
| target_sources(${lib_name} | ||
| PUBLIC | ||
| FILE_SET CXX_MODULES | ||
| BASE_DIRS ${ARG_OUTPUT_FOLDER} | ||
| FILES ${module_files} | ||
| ) | ||
| endif() | ||
| endif() | ||
| endfunction() | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| #--------------------------------------------------------------------------------------------------- | ||
| # CMake support for C++20 modules in podio | ||
| # | ||
| # This file provides macros and options for generating and using C++20 module interfaces | ||
| # for podio-generated datamodels. | ||
| #--------------------------------------------------------------------------------------------------- | ||
|
|
||
| # Option to enable C++20 module generation | ||
| option(PODIO_ENABLE_CXX_MODULES "Generate C++20 module interface files (.ixx) for datamodels" OFF) | ||
|
|
||
| # Check if modules are actually supported | ||
| if(PODIO_ENABLE_CXX_MODULES) | ||
| # Check CMake version | ||
| if(CMAKE_VERSION VERSION_LESS 3.29) | ||
| message(WARNING "C++20 modules require CMake 3.29 or later (found ${CMAKE_VERSION}). Disabling module support.") | ||
| set(PODIO_ENABLE_CXX_MODULES OFF CACHE BOOL "C++20 modules disabled due to CMake version" FORCE) | ||
| endif() | ||
|
|
||
| # Check generator | ||
| if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") | ||
| message(WARNING "C++20 modules are not supported with the Unix Makefiles generator. Please use Ninja. Disabling module support.") | ||
| set(PODIO_ENABLE_CXX_MODULES OFF CACHE BOOL "C++20 modules disabled due to generator" FORCE) | ||
| endif() | ||
|
|
||
| # Check compiler support | ||
| if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
| if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14.0) | ||
| message(WARNING "C++20 modules require GCC 14 or later (found ${CMAKE_CXX_COMPILER_VERSION}). Disabling module support.") | ||
| set(PODIO_ENABLE_CXX_MODULES OFF CACHE BOOL "C++20 modules disabled due to compiler version" FORCE) | ||
| endif() | ||
| elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
| if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0) | ||
| message(WARNING "C++20 modules require Clang 18 or later (found ${CMAKE_CXX_COMPILER_VERSION}). Disabling module support.") | ||
| set(PODIO_ENABLE_CXX_MODULES OFF CACHE BOOL "C++20 modules disabled due to compiler version" FORCE) | ||
| endif() | ||
| else() | ||
| message(WARNING "C++20 modules have only been tested with GCC 14+ and Clang 18+. Found ${CMAKE_CXX_COMPILER_ID}. Proceed at your own risk.") | ||
| endif() | ||
| endif() | ||
|
|
||
| if(PODIO_ENABLE_CXX_MODULES) | ||
| message(STATUS "C++20 module support is ENABLED for podio datamodels") | ||
| message(STATUS " - CMake version: ${CMAKE_VERSION}") | ||
| message(STATUS " - Generator: ${CMAKE_GENERATOR}") | ||
| message(STATUS " - Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}") | ||
| else() | ||
| message(STATUS "C++20 module support is DISABLED for podio datamodels") | ||
| endif() | ||
|
|
||
| #--------------------------------------------------------------------------------------------------- | ||
| # PODIO_ADD_MODULE_INTERFACE( target module_name module_file ) | ||
| # | ||
| # Add a C++20 module interface to a target | ||
| # | ||
| # Arguments: | ||
| # target - The target to which the module should be added | ||
| # module_name - The name of the module (e.g., "podio.core") | ||
| # module_file - The .ixx file implementing the module interface | ||
| #--------------------------------------------------------------------------------------------------- | ||
| function(PODIO_ADD_MODULE_INTERFACE target module_name module_file) | ||
| if(NOT PODIO_ENABLE_CXX_MODULES) | ||
| return() | ||
| endif() | ||
|
|
||
| message(STATUS "Adding C++20 module '${module_name}' to target '${target}'") | ||
|
|
||
| # Add the module file to the target as a CXX_MODULES file set | ||
| # Use PUBLIC so the module gets installed and can be used by downstream projects | ||
| target_sources(${target} | ||
| PUBLIC | ||
| FILE_SET CXX_MODULES | ||
| BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} | ||
| FILES ${module_file} | ||
| ) | ||
| endfunction() | ||
|
|
||
| #--------------------------------------------------------------------------------------------------- | ||
| # PODIO_GENERATE_MODULE_INTERFACE( datamodel OUTPUT_FILE ) | ||
| # | ||
| # Generate a C++20 module interface for a podio datamodel | ||
| # This is currently a placeholder - actual generation will be added later | ||
| # | ||
| # Arguments: | ||
| # datamodel - Name of the datamodel (e.g., "TestDataModel") | ||
| # OUTPUT_FILE - Variable name to store the generated .ixx file path | ||
| #--------------------------------------------------------------------------------------------------- | ||
| function(PODIO_GENERATE_MODULE_INTERFACE datamodel OUTPUT_FILE) | ||
| if(NOT PODIO_ENABLE_CXX_MODULES) | ||
| set(${OUTPUT_FILE} "" PARENT_SCOPE) | ||
| return() | ||
| endif() | ||
|
|
||
| # For now, just set the expected output location | ||
| # Actual generation will be implemented in the template | ||
| set(module_file "${CMAKE_CURRENT_BINARY_DIR}/${datamodel}_module.ixx") | ||
| set(${OUTPUT_FILE} ${module_file} PARENT_SCOPE) | ||
|
|
||
| message(STATUS "Will generate module interface: ${module_file}") | ||
| endfunction() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we don't have a build already with a recent enough clang that we could simply test drive as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think clang itself is recent enough (19 should work) but I think lcg has clang setup with the GCC libstdc++ instead of clang's libc++. That makes it harder. But I haven't really tried much to make it work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, let's see if @andresailer has a special LCG stack that would make this easy.