-
-
Notifications
You must be signed in to change notification settings - Fork 484
Expose version module using C++20 modules #6761
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 all commits
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 | ||||
---|---|---|---|---|---|---|
|
@@ -17,6 +17,10 @@ | |||||
|
||||||
cmake_minimum_required(VERSION 3.18 FATAL_ERROR) | ||||||
|
||||||
if(HPX_WITH_CXX_MODULES) | ||||||
cmake_minimum_required(VERSION 3.29...3.29.99 FATAL_ERROR) | ||||||
endif() | ||||||
|
||||||
# Overrides must go before the project() statement, otherwise they are ignored. | ||||||
|
||||||
# ############################################################################## | ||||||
|
@@ -312,6 +316,21 @@ if(HPX_WITH_UNITY_BUILD) | |||||
set(HPX_WITH_UNITY_BUILD_OPTION UNITY_BUILD) | ||||||
endif() | ||||||
|
||||||
# ############################################################################## | ||||||
# C++20 modules configuration | ||||||
# ############################################################################## | ||||||
hpx_option( | ||||||
HPX_WITH_CXX_MODULES BOOL "Enable C++20 modules mode (default: OFF)." OFF | ||||||
ADVANCED | ||||||
) | ||||||
if(HPX_WITH_CXX_MODULES) | ||||||
hpx_info("HPX will build and install C++20 module interface units for downstream users.") | ||||||
hpx_info("Note: HPX itself will still be built using traditional headers.") | ||||||
add_compile_definitions(HPX_HAVE_CXX_MODULES) | ||||||
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. Generally, all preprocessor macros are put into a special file (
Suggested change
|
||||||
else() | ||||||
hpx_info("HPX will be built and used with traditional headers only.") | ||||||
endif() | ||||||
kylehaokunwu marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
hpx_option( | ||||||
HPX_WITH_PRECOMPILED_HEADERS | ||||||
BOOL | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,7 +10,7 @@ include(HPX_PrintSummary) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function(add_hpx_module libname modulename) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Retrieve arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(options CUDA CONFIG_FILES NO_CONFIG_IN_GENERATED_HEADERS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(one_value_args GLOBAL_HEADER_GEN) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(one_value_args GLOBAL_HEADER_GEN GLOBAL_HEADER_MODULE_GEN) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(multi_value_args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SOURCES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
HEADERS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -154,10 +154,27 @@ function(add_hpx_module libname modulename) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(NOT ${modulename}_NO_CONFIG_IN_GENERATED_HEADERS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(module_headers "${module_headers}#endif\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
endif() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
configure_file( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"${PROJECT_SOURCE_DIR}/cmake/templates/global_module_header.hpp.in" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"${global_header}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Decide output path and template file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(DEFINED ${modulename}_GLOBAL_HEADER_MODULE_GEN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
AND ${modulename}_GLOBAL_HEADER_MODULE_GEN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(global_header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"${CMAKE_CURRENT_BINARY_DIR}/include/hpx/global_module.hpp" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(template_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"${HPX_SOURCE_DIR}/cmake/templates/global_module_header_modules.hpp.in" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(global_header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"${CMAKE_CURRENT_BINARY_DIR}/include/hpx/modules/${modulename}.hpp" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(template_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"${PROJECT_SOURCE_DIR}/cmake/templates/global_module_header.hpp.in" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
endif() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+159
to
+175
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. The name of the generated file should be the same in both cases:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
configure_file(${template_file} ${global_header} @ONLY) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
set(generated_headers ${global_header}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
endif() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,16 @@ | ||||||
// Copyright (c) 2019-@HPX_COPYRIGHT_YEAR@ STE||AR Group | ||||||
// | ||||||
// SPDX-License-Identifier: BSL-1.0 | ||||||
// Distributed under the Boost Software License, Version 1.0. | ||||||
// (See accompanying file LICENSE_1_0.txt or copy at | ||||||
// http://www.boost.org/LICENSE_1_0.txt) | ||||||
|
||||||
// Do not edit this file! It has been generated by the CMake configuration step. | ||||||
|
||||||
#pragma once | ||||||
|
||||||
#if defined(HPX_HAVE_CXX_MODULES) | ||||||
import HPX.Core; | ||||||
#else | ||||||
#include <hpx/version.hpp> | ||||||
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. For all HPX modules to be converted in the future, the generated module header should still include all necessary files as before:
Suggested change
|
||||||
#endif |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,21 @@ | ||||||||||
// Copyright (c) 2025 Haokun Wu | ||||||||||
// | ||||||||||
// SPDX-License-Identifier: BSL-1.0 | ||||||||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||||||||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||||||||||
|
||||||||||
module; | ||||||||||
kylehaokunwu marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
// Include all system headers in global module fragment to prevent ODR violations | ||||||||||
#include <algorithm> | ||||||||||
#include <cstdint> | ||||||||||
#include <sstream> | ||||||||||
#include <string> | ||||||||||
|
||||||||||
// Define module-specific macros before including config | ||||||||||
#define HPX_BUILD_MODULE | ||||||||||
#include "config/include/hpx/config.hpp" | ||||||||||
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 think this should be:
Suggested change
If you would like to minimize the #included content, this could be:
Suggested change
which contains all the |
||||||||||
|
||||||||||
export module HPX.Core; | ||||||||||
|
||||||||||
#include "version/include/hpx/version.hpp" | ||||||||||
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. Now that we're generating the module headers correctly, shouldn't we add them here (one by one as we adapt the HPX modules):
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -32,7 +32,8 @@ endif() | |||||
include(HPX_AddModule) | ||||||
add_hpx_module( | ||||||
core version | ||||||
GLOBAL_HEADER_GEN OFF | ||||||
GLOBAL_HEADER_GEN ON | ||||||
GLOBAL_HEADER_MODULE_GEN TRUE | ||||||
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. Just for consistency:
Suggested change
|
||||||
SOURCES ${version_sources} | ||||||
HEADERS ${version_headers} | ||||||
MODULE_DEPENDENCIES hpx_config hpx_config_registry hpx_format hpx_prefix | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,56 +17,56 @@ | |||||
namespace hpx { | ||||||
|
||||||
// Returns the major HPX version. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::uint8_t major_version(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::uint8_t major_version(); | ||||||
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 think this has to be in a reverse sequence, it may generate compilation errors otherwise.
Suggested change
|
||||||
|
||||||
// Returns the minor HPX version. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::uint8_t minor_version(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::uint8_t minor_version(); | ||||||
|
||||||
// Returns the sub-minor/patch-level HPX version. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::uint8_t subminor_version(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::uint8_t subminor_version(); | ||||||
|
||||||
// Returns the full HPX version. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::uint32_t full_version(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::uint32_t full_version(); | ||||||
|
||||||
// Returns the full HPX version. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::string full_version_as_string(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::string full_version_as_string(); | ||||||
|
||||||
// Returns the AGAS subsystem version. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::uint8_t agas_version(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::uint8_t agas_version(); | ||||||
|
||||||
// Returns the tag. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::string tag(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::string tag(); | ||||||
|
||||||
// Returns the HPX full build information string. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::string full_build_string(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::string full_build_string(); | ||||||
|
||||||
// Returns the HPX version string. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::string build_string(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::string build_string(); | ||||||
|
||||||
// Returns the Boost version string. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::string boost_version(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::string boost_version(); | ||||||
|
||||||
// Returns the Boost platform string. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::string boost_platform(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::string boost_platform(); | ||||||
|
||||||
// Returns the Boost compiler string. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::string boost_compiler(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::string boost_compiler(); | ||||||
|
||||||
// Returns the Boost standard library string. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::string boost_stdlib(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::string boost_stdlib(); | ||||||
|
||||||
// Returns the copyright string. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::string copyright(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::string copyright(); | ||||||
|
||||||
// Returns the full version string. | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::string complete_version(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::string complete_version(); | ||||||
|
||||||
// Returns the HPX build type ('Debug', 'Release', etc.) | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::string build_type(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::string build_type(); | ||||||
|
||||||
// Returns the HPX build date and time | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::string build_date_time(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::string build_date_time(); | ||||||
|
||||||
// Return the HPX configuration information | ||||||
[[nodiscard]] HPX_CORE_EXPORT std::string configuration_string(); | ||||||
HPX_MODULE_EXTERN_CORE [[nodiscard]] std::string configuration_string(); | ||||||
} // namespace hpx |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,8 +4,8 @@ | |||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||||||
|
||||||
#include <hpx/global_module.hpp> | ||||||
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. Let's stick with the conventions:
Suggested change
Alternatively (to avoid having to touch all files that currently Not sure if this wouldn't create a circular #include sequence, though. In this case, we need to reshuffle the content slightly:
|
||||||
#include <hpx/modules/testing.hpp> | ||||||
#include <hpx/version.hpp> | ||||||
|
||||||
#include <cstdint> | ||||||
|
||||||
|
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.
Shouldn't it work with newer versions (than 3.29) 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.
Thanks for the catch! I will switch from the fixed range to a
VERSION_GREATER_EQUAL 3.29
check. I will keep it insideif(HPX_WITH_CXX_MODULES)
so non‑module builds still work with CMake ≥ 3.18.