Skip to content

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,22 @@ if(HPX_WITH_UNITY_BUILD)
set(HPX_WITH_UNITY_BUILD_OPTION UNITY_BUILD)
endif()

# ##############################################################################
# C++20 modules configuration
# ##############################################################################
hpx_option(
HPX_USE_MODULES BOOL "Enable C++20 modules mode (default: OFF)." OFF
ADVANCED
)
if(HPX_USE_MODULES)
hpx_info("Building HPX with C++20 modules")
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
add_compile_definitions(HPX_USE_MODULES)
else()
hpx_info("Building HPX with traditional headers")
endif()


hpx_option(
HPX_WITH_PRECOMPILED_HEADERS
BOOL
Expand Down
34 changes: 27 additions & 7 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,35 @@ foreach(lib ${HPX_LIBS})
add_library(hpx_${lib} ${hpx_library_link_mode} src/empty.cpp)
target_compile_definitions(hpx_${lib} PRIVATE HPX_${uppercase_lib}_EXPORTS)

if(HPX_USE_MODULES)
target_sources(hpx_${lib}
PUBLIC
FILE_SET hpx_${lib}_public_sources TYPE CXX_MODULES FILES
${CMAKE_CURRENT_SOURCE_DIR}/core/hpx_core.ixx
)
endif()

set_target_properties(hpx_${lib} PROPERTIES FOLDER "Core")

install(
TARGETS hpx_${lib}
EXPORT HPXInternalTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime
)
if(lib STREQUAL "core" AND HPX_USE_MODULES)
install(
TARGETS hpx_${lib}
EXPORT HPXInternalTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime
FILE_SET hpx_core_public_sources DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
else()
install(
TARGETS hpx_${lib}
EXPORT HPXInternalTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime
)
endif()


# install PDB if needed
if(MSVC AND NOT HPX_WITH_STATIC_LINKING)
Expand Down
12 changes: 12 additions & 0 deletions libs/core/config/include/hpx/config/export_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@
# define HPX_CORE_EXPORT HPX_SYMBOL_IMPORT
#endif

///////////////////////////////////////////////////////////////////////////////
// C++20 module export definitions
#if defined(HPX_BUILD_MODULE)
#undef HPX_CORE_EXPORT
# define HPX_CORE_EXPORT /* empty */
# define HPX_EXPORT_TEMPLATE export
# define HPX_EXPORT_NON_TEMPLATE extern "C++" export
#else
# define HPX_EXPORT_TEMPLATE /* empty */
# define HPX_EXPORT_NON_TEMPLATE /* empty */
#endif

///////////////////////////////////////////////////////////////////////////////
#if defined(HPX_EXPORTS) || defined(HPX_FULL_EXPORTS)
# define HPX_EXPORT HPX_SYMBOL_EXPORT
Expand Down
17 changes: 17 additions & 0 deletions libs/core/hpx_core.ixx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module;

// Include all system headers in global module fragment to prevent ODR violations
#include <algorithm>
#include <cstdint>
#include <sstream>
#include <string>
#include <boost/config.hpp>
#include <boost/version.hpp>

// Define module-specific macros before including config
#define HPX_BUILD_MODULE
#include "config/include/hpx/config.hpp"
Copy link
Member

@hkaiser hkaiser Aug 9, 2025

Choose a reason for hiding this comment

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

I think this should be:

Suggested change
#include "config/include/hpx/config.hpp"
#include <hpx/config.hpp>

If you would like to minimize the #included content, this could be:

Suggested change
#include "config/include/hpx/config.hpp"
#include <hpx/config/defines.hpp>

which contains all the HPX_HAVE_XXX macro definitions.


export module HPX.Core;

#include "version/include/hpx/version.hpp"
36 changes: 18 additions & 18 deletions libs/core/version/include/hpx/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,56 @@
namespace hpx {

// Returns the major HPX version.
[[nodiscard]] HPX_CORE_EXPORT std::uint8_t major_version();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::uint8_t major_version();

// Returns the minor HPX version.
[[nodiscard]] HPX_CORE_EXPORT std::uint8_t minor_version();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::uint8_t minor_version();

// Returns the sub-minor/patch-level HPX version.
[[nodiscard]] HPX_CORE_EXPORT std::uint8_t subminor_version();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::uint8_t subminor_version();

// Returns the full HPX version.
[[nodiscard]] HPX_CORE_EXPORT std::uint32_t full_version();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::uint32_t full_version();

// Returns the full HPX version.
[[nodiscard]] HPX_CORE_EXPORT std::string full_version_as_string();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::string full_version_as_string();

// Returns the AGAS subsystem version.
[[nodiscard]] HPX_CORE_EXPORT std::uint8_t agas_version();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::uint8_t agas_version();

// Returns the tag.
[[nodiscard]] HPX_CORE_EXPORT std::string tag();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::string tag();

// Returns the HPX full build information string.
[[nodiscard]] HPX_CORE_EXPORT std::string full_build_string();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::string full_build_string();

// Returns the HPX version string.
[[nodiscard]] HPX_CORE_EXPORT std::string build_string();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::string build_string();

// Returns the Boost version string.
[[nodiscard]] HPX_CORE_EXPORT std::string boost_version();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::string boost_version();

// Returns the Boost platform string.
[[nodiscard]] HPX_CORE_EXPORT std::string boost_platform();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::string boost_platform();

// Returns the Boost compiler string.
[[nodiscard]] HPX_CORE_EXPORT std::string boost_compiler();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::string boost_compiler();

// Returns the Boost standard library string.
[[nodiscard]] HPX_CORE_EXPORT std::string boost_stdlib();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::string boost_stdlib();

// Returns the copyright string.
[[nodiscard]] HPX_CORE_EXPORT std::string copyright();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::string copyright();

// Returns the full version string.
[[nodiscard]] HPX_CORE_EXPORT std::string complete_version();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::string complete_version();

// Returns the HPX build type ('Debug', 'Release', etc.)
[[nodiscard]] HPX_CORE_EXPORT std::string build_type();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::string build_type();

// Returns the HPX build date and time
[[nodiscard]] HPX_CORE_EXPORT std::string build_date_time();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::string build_date_time();

// Return the HPX configuration information
[[nodiscard]] HPX_CORE_EXPORT std::string configuration_string();
HPX_EXPORT_NON_TEMPLATE [[nodiscard]] HPX_CORE_EXPORT std::string configuration_string();
} // namespace hpx