Skip to content

Commit c27ae7d

Browse files
Fix C++ module installation for downstream BMI discovery
1 parent ac34da2 commit c27ae7d

4 files changed

Lines changed: 7 additions & 88 deletions

File tree

.cmake-format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@
586586
'INCLUDE_DIRS': '+',
587587
'FOUND_HEADERS': 1},
588588
'pargs': { 'flags': [], 'nargs': '1+'}},
589-
'hpx_configure_module_producer': { 'kwargs': { 'MODULE_OUT_DIR': 1},
589+
'hpx_configure_module_producer': { 'kwargs': {},
590590
'pargs': { 'flags': [], 'nargs': '1+'}}
591591
}
592592

cmake/HPX_CXXModules.cmake

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -65,73 +65,23 @@ 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
83+
# Make sure consumers scan for modules through CMake's native module handling
10584
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()
112-
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()
13585
endfunction()
13686

13787
# hpx_configure_module_consumer(<consumer> <producer>])
@@ -150,37 +100,15 @@ function(hpx_configure_module_consumer consumer producer)
150100
get_target_property(_scan ${producer} INTERFACE_CXX_SCAN_FOR_MODULES)
151101
if(_scan)
152102
set_target_properties(${consumer} PROPERTIES CXX_SCAN_FOR_MODULES ${_scan})
153-
endif()
154103

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"
104+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID
105+
MATCHES "AppleClang"
161106
)
162-
target_compile_options(
163-
${consumer} PRIVATE "-fprebuilt-module-path=${_module_dir}"
164-
)
165107
get_target_property(_type ${consumer} TYPE)
166108
if((_type STREQUAL "SHARED_LIBRARY") OR (_type STREQUAL "EXECUTABLE"))
167109
target_link_options(${consumer} PRIVATE "-fuse-ld=lld")
168110
target_link_options(${consumer} PRIVATE "-Wl,--error-limit=0")
169111
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-
)
184112
endif()
185113
endif()
186114
endfunction()

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
347-
MODULE_OUT_DIR ${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: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ if(NOT HPX_WITH_TESTS_EXTERNAL_BUILD)
1010
return()
1111
endif()
1212

13-
# If C++ modules are enabled, exit now (we don't know yet how to setup a
14-
# dependent HPX project to use the generated BMIs).
15-
if(HPX_WITH_CXX_MODULES)
16-
return()
17-
endif()
18-
1913
# Try building an external cmake based project ...
2014
function(
2115
create_cmake_test

0 commit comments

Comments
 (0)