Skip to content

Commit 5d13ec5

Browse files
Address reviewer feedback: Refine module dependencies and fix circularity
1 parent c69705b commit 5d13ec5

4 files changed

Lines changed: 16 additions & 111 deletions

File tree

cmake/HPX_CXXModules.cmake

Lines changed: 9 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -65,73 +65,27 @@ if(NOT HPX_WITH_CXX_MODULES)
6565
return()
6666
endif()
6767

68-
# hpx_configure_module_producer(<producer> [MODULE_OUT_DIR <dir>])
68+
# hpx_configure_module_producer(<producer>)
6969
#
70-
# * Ensures a stable module output dir for producer target
71-
# * Adds compiler flags to write module cache there (Clang/GCC)
7270
# * Creates an interface target '<producer>_if' for consumers to link to
71+
# * Marks the interface target for CMake's native module scanning
7372
function(hpx_configure_module_producer producer)
7473
if(NOT TARGET ${producer})
7574
hpx_error("hpx_configure_module_producer: target '${producer}' not found")
7675
endif()
7776

78-
# parse optional args
79-
set(options)
80-
set(one_value_args MODULE_OUT_DIR)
81-
set(multi_value_args)
82-
cmake_parse_arguments(
83-
_args "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}
84-
)
85-
86-
if(_args_MODULE_OUT_DIR)
87-
set(_moddir "${_args_MODULE_OUT_DIR}")
88-
else()
89-
set(_moddir "$<TARGET_FILE_DIR:${producer}>")
90-
endif()
91-
9277
set(_iface "${producer}_if")
9378
if(NOT TARGET ${_iface})
9479
add_library(${_iface} INTERFACE)
9580
target_link_libraries(${_iface} INTERFACE ${producer})
9681
endif()
9782

98-
# Set a property so consumers can query the BMI directory via
99-
# get_target_property.
100-
set_target_properties(
101-
${_iface} PROPERTIES INTERFACE_EXPORT_MODULE_DIR "${_moddir}"
102-
)
103-
104-
# Make sure consumers scan for the BMI
105-
set_target_properties(${_iface} PROPERTIES INTERFACE_CXX_SCAN_FOR_MODULES On)
106-
107-
if(MSVC)
108-
# MSVC: CMake/MSVC handle IFCs automatically; create a target for
109-
# convenience, consumers can link to this to get ordering and include info
110-
return()
111-
endif()
83+
# Make sure consumers scan for modules through CMake's native module handling
84+
set_target_properties(${_iface} PROPERTIES INTERFACE_CXX_SCAN_FOR_MODULES ON)
11285

113-
# Compiler-specific flags to instruct where to write module cache
114-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES
115-
"AppleClang"
116-
)
117-
# Clang common flags
118-
target_compile_options(${producer} PRIVATE "-fmodule-output=${_moddir}")
119-
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
120-
# GCC: modern flags
121-
hpx_add_target_compile_option_if_available(
122-
${producer} PRIVATE "-fmodule-output=${_moddir}" RESULT ok
123-
)
124-
if(NOT ok)
125-
hpx_error(
126-
"hpx_configure_module_producer: the used version of gcc does not support '-fmodule-output'"
127-
)
128-
endif()
129-
else()
130-
hpx_warn(
131-
"hpx_configure_module_producer: unknown compiler '${CMAKE_CXX_COMPILER_ID}'; "
132-
"exposing EXPORT_MODULE_DIR='${_moddir}' for manual handling"
133-
)
134-
endif()
86+
# Define HPX_COMPILE_BMI to ensure that internal headers use #include instead
87+
# of import during the generation of the BMI.
88+
target_compile_definitions(${producer} PRIVATE HPX_COMPILE_BMI)
13589
endfunction()
13690

13791
# hpx_configure_module_consumer(<consumer> <producer>])
@@ -150,37 +104,15 @@ function(hpx_configure_module_consumer consumer producer)
150104
get_target_property(_scan ${producer} INTERFACE_CXX_SCAN_FOR_MODULES)
151105
if(_scan)
152106
set_target_properties(${consumer} PROPERTIES CXX_SCAN_FOR_MODULES ${_scan})
153-
endif()
154107

155-
get_target_property(_module_dir ${producer} INTERFACE_EXPORT_MODULE_DIR)
156-
if(_module_dir)
157-
if(MSVC)
158-
return()
159-
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID
160-
MATCHES "AppleClang"
108+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES
109+
"AppleClang"
161110
)
162-
target_compile_options(
163-
${consumer} PRIVATE "-fprebuilt-module-path=${_module_dir}"
164-
)
165111
get_target_property(_type ${consumer} TYPE)
166112
if((_type STREQUAL "SHARED_LIBRARY") OR (_type STREQUAL "EXECUTABLE"))
167113
target_link_options(${consumer} PRIVATE "-fuse-ld=lld")
168114
target_link_options(${consumer} PRIVATE "-Wl,--error-limit=0")
169115
endif()
170-
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
171-
hpx_add_target_compile_option_if_available(
172-
${consumer} PRIVATE "-fprebuilt-module-path=${_module_dir}" RESULT ok
173-
)
174-
if(NOT ok)
175-
hpx_error(
176-
"hpx_configure_module_consumer: the used version of gcc does not "
177-
"support '-fprebuilt-module-path='"
178-
)
179-
endif()
180-
else()
181-
hpx_warn(
182-
"hpx_configure_module_consumer: unknown compiler '${CMAKE_CXX_COMPILER_ID}'"
183-
)
184116
endif()
185117
endif()
186118
endfunction()

examples/hello_world_component/CMakeLists.txt

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,6 @@ if(EXISTS "${HPX_DIR}")
3131
target_link_libraries(hello_world_client PRIVATE hello_world_component)
3232
endif()
3333
target_link_libraries(hello_world_client PRIVATE HPX::hpx HPX::wrap_main)
34-
if(HPX_WITH_CXX_MODULES)
35-
if(TARGET hpx_core_module_if)
36-
if(TARGET hello_world_component)
37-
target_link_libraries(
38-
hello_world_component PRIVATE hpx_core_module_if
39-
)
40-
endif()
41-
target_link_libraries(hello_world_client PRIVATE hpx_core_module_if)
42-
elseif(TARGET HPXInternal::hpx_core_module_if)
43-
if(TARGET hello_world_component)
44-
target_link_libraries(
45-
hello_world_component PRIVATE HPXInternal::hpx_core_module_if
46-
)
47-
endif()
48-
target_link_libraries(
49-
hello_world_client PRIVATE HPXInternal::hpx_core_module_if
50-
)
51-
endif()
52-
endif()
5334

5435
# We still support not linking to HPX::wrap_main when
5536
# HPX_WITH_DYNAMIC_HPX_MAIN=OFF for legacy use. This can only be done using
@@ -72,15 +53,17 @@ if(EXISTS "${HPX_DIR}")
7253
COMPONENT_DEPENDENCIES iostreams
7354
DEPENDENCIES HPX::wrap_main
7455
TYPE COMPONENT
75-
SCAN_FOR_MODULES ON
56+
SCAN_FOR_MODULES ${HPX_WITH_CXX_MODULES}
7657
)
7758
hpx_setup_target(
7859
hello_world_client
7960
DEPENDENCIES hello_world_component
80-
SCAN_FOR_MODULES ON
61+
SCAN_FOR_MODULES ${HPX_WITH_CXX_MODULES}
8162
)
8263
else()
83-
hpx_setup_target(hello_world_client SCAN_FOR_MODULES ON)
64+
hpx_setup_target(
65+
hello_world_client SCAN_FOR_MODULES ${HPX_WITH_CXX_MODULES}
66+
)
8467
endif()
8568
else()
8669
message(FATAL_ERROR "Unknown SETUP_TYPE=\"${SETUP_TYPE}\"")

libs/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,7 @@ foreach(lib ${HPX_LIBS})
342342
set_target_properties(
343343
hpx_${lib}_module PROPERTIES POSITION_INDEPENDENT_CODE ON
344344
)
345-
hpx_configure_module_producer(
346-
hpx_${lib}_module MODULE_OUT_DIR
347-
${CMAKE_INSTALL_LIBDIR}/cmake/${HPX_PACKAGE_NAME}/${lib}
348-
)
345+
hpx_configure_module_producer(hpx_${lib}_module)
349346

350347
target_link_libraries(
351348
hpx_${lib}_module

tests/unit/build/CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,7 @@ function(
7373
VERBATIM
7474
)
7575
add_dependencies(${name} hpx hpx_init hpx_wrap)
76-
if(HPX_WITH_CXX_MODULES)
77-
if(TARGET hpx_core_module)
78-
add_dependencies(${name} hpx_core_module)
79-
endif()
80-
if(TARGET hpx_full_module)
81-
add_dependencies(${name} hpx_full_module)
82-
endif()
83-
endif()
76+
8477
if(HPX_WITH_DISTRIBUTED_RUNTIME)
8578
add_dependencies(${name} iostreams_component)
8679
endif()

0 commit comments

Comments
 (0)