Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
797854d
Re-enable external build tests with C++ modules
LSUDOKO Apr 19, 2026
cdff10b
build: fix C++ modules BMI export and re-enable external build tests
LSUDOKO Apr 25, 2026
a7c5c53
chore: resolve modify/delete conflict by removing deleted file
LSUDOKO Apr 25, 2026
af1fe47
style: apply clang-format to modified files
LSUDOKO Apr 25, 2026
6ec642a
style: apply clang-format to all library, example, and test files
LSUDOKO Apr 25, 2026
e286bfd
fix: restore extern C++ and fix POSIX header collection for modules
LSUDOKO Apr 25, 2026
45d182a
fix:disable pkg-config test for modules and cleanup header whitespace…
LSUDOKO Apr 25, 2026
a5cd735
apply CI-requested formatting for clang-format and cmake-format
LSUDOKO Apr 25, 2026
03ae3b5
trigger ci: verify all builds pass with restored extern C++ and macro…
LSUDOKO Apr 25, 2026
f879162
fix: restore standard build stability by fixing macro definitions and…
LSUDOKO Apr 25, 2026
13c5e03
fix: restore standard build stability by fixing macro definitions and…
LSUDOKO Apr 27, 2026
8b3984b
build: fix C++ modules BMI export and re-enable external build tests
LSUDOKO Apr 27, 2026
489d884
build: fix C++ modules BMI export and re-enable external build tests
LSUDOKO Apr 27, 2026
fd1e4eb
fix: correctly register pseudo-targets for build tests
LSUDOKO Apr 27, 2026
62a85b6
fix: correctly restore build tests and fix cmake formatting
LSUDOKO Apr 27, 2026
2f9325d
fix: unconditionally include POSIX headers for modules on Linux
LSUDOKO Apr 27, 2026
ccbec5a
Fix external C++ modules package consumers
LSUDOKO Apr 29, 2026
d5609b6
build: fix C++ modules BMI export and re-enable external build tests
LSUDOKO Apr 29, 2026
fb671ac
build: fix external C++ modules package tests
LSUDOKO Apr 29, 2026
3fdd927
build: fix wrapper module generation in CI
LSUDOKO Apr 30, 2026
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
57 changes: 10 additions & 47 deletions cmake/HPX_CXXModules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ endif()
# hpx_configure_module_producer(<producer> [MODULE_OUT_DIR <dir>])
#
# * Ensures a stable module output dir for producer target
# * Adds compiler flags to write module cache there (Clang/GCC)
# * Creates an interface target '<producer>_if' for consumers to link to
function(hpx_configure_module_producer producer)
if(NOT TARGET ${producer})
Expand Down Expand Up @@ -103,35 +102,6 @@ function(hpx_configure_module_producer producer)

# Make sure consumers scan for the BMI
set_target_properties(${_iface} PROPERTIES INTERFACE_CXX_SCAN_FOR_MODULES On)

if(MSVC)
# MSVC: CMake/MSVC handle IFCs automatically; create a target for
# convenience, consumers can link to this to get ordering and include info
return()
endif()

# Compiler-specific flags to instruct where to write module cache
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES
"AppleClang"
)
# Clang common flags
target_compile_options(${producer} PRIVATE "-fmodule-output=${_moddir}")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# GCC: modern flags
hpx_add_target_compile_option_if_available(
${producer} PRIVATE "-fmodule-output=${_moddir}" RESULT ok
)
if(NOT ok)
hpx_error(
"hpx_configure_module_producer: the used version of gcc does not support '-fmodule-output'"
)
endif()
else()
hpx_warn(
"hpx_configure_module_producer: unknown compiler '${CMAKE_CXX_COMPILER_ID}'; "
"exposing EXPORT_MODULE_DIR='${_moddir}' for manual handling"
)
endif()
endfunction()

# hpx_configure_module_consumer(<consumer> <producer>])
Expand All @@ -146,6 +116,16 @@ function(hpx_configure_module_consumer consumer producer)
hpx_error("hpx_configure_module_consumer: target '${producer}' not found")
endif()

# Imported module metadata is only picked up from direct link dependencies.
# Link the underlying module target directly when the producer follows the
# '<module>_if' wrapper pattern.
if(producer MATCHES "_if$")
string(REGEX REPLACE "_if$" "" _producer_target "${producer}")
if(TARGET ${_producer_target})
target_link_libraries(${consumer} PRIVATE ${_producer_target})
endif()
endif()

target_link_libraries(${consumer} PRIVATE ${producer})
get_target_property(_scan ${producer} INTERFACE_CXX_SCAN_FOR_MODULES)
if(_scan)
Expand All @@ -159,28 +139,11 @@ function(hpx_configure_module_consumer consumer producer)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID
MATCHES "AppleClang"
)
target_compile_options(
${consumer} PRIVATE "-fprebuilt-module-path=${_module_dir}"
)
get_target_property(_type ${consumer} TYPE)
if((_type STREQUAL "SHARED_LIBRARY") OR (_type STREQUAL "EXECUTABLE"))
target_link_options(${consumer} PRIVATE "-fuse-ld=lld")
target_link_options(${consumer} PRIVATE "-Wl,--error-limit=0")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
hpx_add_target_compile_option_if_available(
${consumer} PRIVATE "-fprebuilt-module-path=${_module_dir}" RESULT ok
)
if(NOT ok)
hpx_error(
"hpx_configure_module_consumer: the used version of gcc does not "
"support '-fprebuilt-module-path='"
)
endif()
else()
hpx_warn(
"hpx_configure_module_consumer: unknown compiler '${CMAKE_CXX_COMPILER_ID}'"
)
endif()
endif()
endfunction()
9 changes: 8 additions & 1 deletion cmake/HPX_CollectStdHeaders.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ set(STANDARD_LIBRARY_HEADERS
"<cwctype>"
)

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND STANDARD_LIBRARY_HEADERS "<link.h>" "<dlfcn.h>")
endif()

# Function to extract #includes from a file recursively
function(hpx_extract_includes_from_file module)

Expand Down Expand Up @@ -137,8 +141,11 @@ function(hpx_extract_includes_from_file module)
if(NOT filename MATCHES "\\.|/")
# Check if the include is a standard library header
if(${filename} IN_LIST STANDARD_LIBRARY_HEADERS)
list(APPEND found_includes ${filename})
list(APPEND found_includes "${filename}")
endif()
elseif(${filename} IN_LIST STANDARD_LIBRARY_HEADERS)
# Handle headers with extensions (like link.h) that were added to the list
list(APPEND found_includes "${filename}")
endif()
endforeach()

Expand Down
20 changes: 16 additions & 4 deletions cmake/HPX_GeneratePackage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ write_basic_package_version_file(
COMPATIBILITY AnyNewerVersion
)

# Export HPXInternalTargets in the build directory
# CXX_MODULES_DIRECTORY was added in CMake 3.28
set(_cxx_modules_directory_arg)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.28")
set(_cxx_modules_directory_arg CXX_MODULES_DIRECTORY cxx-modules)
endif()

# Export HPXInternalTargets in the build directory. Use the EXPORT signature so
# CMake also generates the per-target C++ module metadata files.
export(
TARGETS ${HPX_EXPORT_INTERNAL_TARGETS}
EXPORT HPXInternalTargets
Comment thread
hkaiser marked this conversation as resolved.
NAMESPACE HPXInternal::
FILE "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${HPX_PACKAGE_NAME}/HPXInternalTargets.cmake"
${_cxx_modules_directory_arg}
)

# Export HPXInternalTargets in the install directory
Expand All @@ -32,14 +40,17 @@ install(
NAMESPACE HPXInternal::
FILE HPXInternalTargets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${HPX_PACKAGE_NAME}
${_cxx_modules_directory_arg}
COMPONENT cmake
)

# Export HPXTargets in the build directory
# Export HPXTargets in the build directory. Use the EXPORT signature so CMake
# also generates the per-target C++ module metadata files.
export(
TARGETS ${HPX_EXPORT_TARGETS}
EXPORT HPXTargets
Comment thread
hkaiser marked this conversation as resolved.
NAMESPACE HPX::
FILE "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${HPX_PACKAGE_NAME}/HPXTargets.cmake"
${_cxx_modules_directory_arg}
)

# Add aliases with the namespace for use within HPX
Expand All @@ -57,6 +68,7 @@ install(
NAMESPACE HPX::
FILE HPXTargets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${HPX_PACKAGE_NAME}
${_cxx_modules_directory_arg}
COMPONENT cmake
)

Expand Down
4 changes: 0 additions & 4 deletions cmake/templates/hpx.ixx.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export module HPX.@cap_libname@;
// Make sure the exported symbols are name-mangled using standard C++ rules.
// This is necessary as otherwise the symbols exported from the shared libraries
// will be exported from the module using a differently encoded name.
extern "C++" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change will break linking when C++ modules are enabled. I think we discussed this before. What's you rationale of removing the extern "C++" again?

#if defined(HPX_MSVC)
// disable warning C5244: '#include <filename>' in the purview of module
// 'HPX.@cap_libname@' appears erroneous. Consider moving that directive before the
Expand All @@ -51,5 +49,3 @@ extern "C++" {
#if defined(HPX_MSVC)
#pragma warning(pop)
#endif

} // extern "C++"
17 changes: 16 additions & 1 deletion examples/gtest_emulation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ if(EXISTS "${HPX_DIR}")

if(HPX_WITH_CXX_MODULES)
set(CMAKE_CXX_SCAN_FOR_MODULES ON)

# CMake only propagates imported C++ module metadata from targets that are
# linked directly by the consumer. The exported HPXInternal module targets
# are therefore linked explicitly for the external build tests.
set(hpx_cxx_module_targets)
if(TARGET HPXInternal::hpx_core_module)
list(APPEND hpx_cxx_module_targets HPXInternal::hpx_core_module)
endif()
if(TARGET HPXInternal::hpx_full_module)
list(APPEND hpx_cxx_module_targets HPXInternal::hpx_full_module)
endif()
endif()

# Add a static library which contains a main to emulate gtest_main
Expand All @@ -27,7 +38,11 @@ if(EXISTS "${HPX_DIR}")

# Test with the main function in a separate static library
add_executable(hpx_main_ext_main hpx_main_ext_main.cpp)
target_link_libraries(hpx_main_ext_main PRIVATE hpx_helper_interface)
# Keep the helper interface for link order, but link module targets directly
# to the executable so CMake can see the imported BMI metadata.
target_link_libraries(
hpx_main_ext_main PRIVATE hpx_helper_interface ${hpx_cxx_module_targets}
)

enable_testing()
add_test(hello_world_test hpx_main_ext_main)
Expand Down
18 changes: 17 additions & 1 deletion examples/hello_world_component/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ if(EXISTS "${HPX_DIR}")

if(HPX_WITH_CXX_MODULES)
set(CMAKE_CXX_SCAN_FOR_MODULES ON)

# CMake only propagates imported C++ module metadata from targets that are
# linked directly by the consumer. The exported HPXInternal module targets
# are therefore linked explicitly for the external build tests.
set(hpx_cxx_module_targets)
if(TARGET HPXInternal::hpx_core_module)
list(APPEND hpx_cxx_module_targets HPXInternal::hpx_core_module)
endif()
if(TARGET HPXInternal::hpx_full_module)
list(APPEND hpx_cxx_module_targets HPXInternal::hpx_full_module)
endif()
endif()

add_executable(hello_world_client hello_world_client.cpp)
Expand All @@ -26,11 +37,15 @@ if(EXISTS "${HPX_DIR}")
if(HPX_WITH_DISTRIBUTED_RUNTIME)
target_link_libraries(
hello_world_component PUBLIC HPX::hpx HPX::iostreams_component
${hpx_cxx_module_targets}
)
target_link_libraries(hello_world_component PRIVATE HPX::component)
target_link_libraries(hello_world_client PRIVATE hello_world_component)
endif()
target_link_libraries(hello_world_client PRIVATE HPX::hpx HPX::wrap_main)
target_link_libraries(
hello_world_client PRIVATE HPX::hpx HPX::wrap_main
${hpx_cxx_module_targets}
)

# We still support not linking to HPX::wrap_main when
# HPX_WITH_DYNAMIC_HPX_MAIN=OFF for legacy use. This can only be done using
Expand All @@ -44,6 +59,7 @@ if(EXISTS "${HPX_DIR}")

target_link_libraries(
hello_world_client_only_hpx_init PRIVATE hello_world_component
${hpx_cxx_module_targets}
)
endif()
elseif("${SETUP_TYPE}" STREQUAL "MACROS")
Expand Down
5 changes: 3 additions & 2 deletions examples/transpose/transpose_smp_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ int hpx_main(hpx::program_options::variables_map& vm)
std::vector<hpx::shared_future<void>> transpose_futures;
transpose_futures.resize(num_blocks);

for_each(par, range, [&](std::uint64_t b) {
for (std::uint64_t b = 0; b < num_blocks; ++b)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change is unrelated. Please separate into new PR, if appropriate.

{
transpose_futures[b] =
for_each(par(task), range, [&, b](std::uint64_t phase) {
std::uint64_t const block_size = block_order * block_order;
Expand All @@ -108,7 +109,7 @@ int hpx_main(hpx::program_options::variables_map& vm)
transpose(&A[from_block][A_offset], &B[b][B_offset],
block_order, tile_size);
}).share();
});
}

hpx::wait_all(transpose_futures);

Expand Down
6 changes: 6 additions & 0 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ foreach(lib ${HPX_LIBS})
# src/CMakeLists.txt. When all of hpx_full has been modularized the target
# creation can move here as well.
if(HPX_WITH_CXX_MODULES)
if(NOT TARGET hpx_modules)
add_custom_target(hpx_modules ALL)
set_target_properties(hpx_modules PROPERTIES FOLDER "Core")
endif()

add_library(hpx_${lib}_module STATIC)
set_target_properties(
hpx_${lib}_module PROPERTIES POSITION_INDEPENDENT_CODE ON
Expand All @@ -353,6 +358,7 @@ foreach(lib ${HPX_LIBS})
PRIVATE hpx_private_flags
)
set_target_properties(hpx_${lib}_module PROPERTIES FOLDER "Core")
add_dependencies(hpx_modules hpx_${lib}_module)

add_hpx_source_group(
NAME hpx_${lib}_module
Expand Down
19 changes: 12 additions & 7 deletions tests/unit/build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ if(NOT HPX_WITH_TESTS_EXTERNAL_BUILD)
return()
endif()

# If C++ modules are enabled, exit now (we don't know yet how to setup a
# dependent HPX project to use the generated BMIs).
if(HPX_WITH_CXX_MODULES)
return()
endif()

# Try building an external cmake based project ...
function(
create_cmake_test
Expand Down Expand Up @@ -79,6 +73,14 @@ function(
VERBATIM
)
add_dependencies(${name} hpx hpx_init hpx_wrap)
if(HPX_WITH_CXX_MODULES)
if(TARGET hpx_core_module)
add_dependencies(${name} hpx_core_module)
endif()
if(TARGET hpx_full_module)
add_dependencies(${name} hpx_full_module)
endif()
endif()
Comment thread
hkaiser marked this conversation as resolved.
if(HPX_WITH_DISTRIBUTED_RUNTIME)
add_dependencies(${name} iostreams_component)
endif()
Expand Down Expand Up @@ -200,7 +202,10 @@ foreach(build_type ${build_types})
endforeach()
add_hpx_pseudo_dependencies(tests.unit.build tests.unit.build.cmake)

if(HPX_WITH_PKGCONFIG AND HPX_WITH_DISTRIBUTED_RUNTIME)
if(HPX_WITH_PKGCONFIG
AND HPX_WITH_DISTRIBUTED_RUNTIME
AND NOT HPX_WITH_CXX_MODULES
)
find_package(PkgConfig)
if(PKGCONFIG_FOUND)
create_pkgconfig_test(
Expand Down
Loading