-
-
Notifications
You must be signed in to change notification settings - Fork 542
Fix C++ modules BMI installation and re-enable external build tests #7206
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,14 +4,13 @@ | |||||
| # 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_AddCompileFlag) | ||||||
| include(HPX_Message) | ||||||
|
|
||||||
| macro(hpx_check_cxx_modules_support) | ||||||
| if(HPX_WITH_CXX_MODULES) | ||||||
| if(NOT (CMAKE_VERSION VERSION_GREATER_EQUAL "3.29")) | ||||||
| if(NOT (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28")) | ||||||
| hpx_fatal( | ||||||
| "Please use a version of CMake newer than V3.28 in order to enable C++ module support for HPX" | ||||||
| "Please use a version of CMake 3.28 or newer in order to enable C++ module support for HPX" | ||||||
| ) | ||||||
| endif() | ||||||
|
|
||||||
|
|
@@ -65,79 +64,39 @@ if(NOT HPX_WITH_CXX_MODULES) | |||||
| return() | ||||||
| endif() | ||||||
|
|
||||||
| # hpx_configure_module_producer(<producer> [MODULE_OUT_DIR <dir>]) | ||||||
| # hpx_configure_module_producer(<producer>) | ||||||
| # | ||||||
| # * 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 | ||||||
| # * Creates an interface target '<producer>_if' for consumers to link to. | ||||||
| # * Sets INTERFACE_CXX_SCAN_FOR_MODULES ON so that CMake's native module | ||||||
| # dependency tracking propagates to all consumers. | ||||||
| # | ||||||
| # CMake 3.28+ with FILE_SET CXX_MODULES handles BMI generation and | ||||||
| # -fmodule-output/-fprebuilt-module-path flags automatically. No manual compiler | ||||||
| # flags are needed here. | ||||||
| function(hpx_configure_module_producer producer) | ||||||
| if(NOT TARGET ${producer}) | ||||||
| hpx_error("hpx_configure_module_producer: target '${producer}' not found") | ||||||
| endif() | ||||||
|
|
||||||
| # parse optional args | ||||||
| set(options) | ||||||
| set(one_value_args MODULE_OUT_DIR) | ||||||
| set(multi_value_args) | ||||||
| cmake_parse_arguments( | ||||||
| _args "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN} | ||||||
| ) | ||||||
|
|
||||||
| if(_args_MODULE_OUT_DIR) | ||||||
| set(_moddir "${_args_MODULE_OUT_DIR}") | ||||||
| else() | ||||||
| set(_moddir "$<TARGET_FILE_DIR:${producer}>") | ||||||
| endif() | ||||||
|
|
||||||
| set(_iface "${producer}_if") | ||||||
| if(NOT TARGET ${_iface}) | ||||||
| add_library(${_iface} INTERFACE) | ||||||
| target_link_libraries(${_iface} INTERFACE ${producer}) | ||||||
| endif() | ||||||
|
|
||||||
| # Set a property so consumers can query the BMI directory via | ||||||
| # get_target_property. | ||||||
| set_target_properties( | ||||||
| ${_iface} PROPERTIES INTERFACE_EXPORT_MODULE_DIR "${_moddir}" | ||||||
| ) | ||||||
|
|
||||||
| # 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() | ||||||
| # Propagate scanning requirement to consumers via the interface target. CMake | ||||||
| # uses this to enable its native module dependency scanning for any target | ||||||
| # that links to this interface. | ||||||
| set_target_properties(${_iface} PROPERTIES INTERFACE_CXX_SCAN_FOR_MODULES ON) | ||||||
|
arpittkhandelwal marked this conversation as resolved.
|
||||||
| endfunction() | ||||||
|
|
||||||
| # hpx_configure_module_consumer(<consumer> <producer>]) | ||||||
| # hpx_configure_module_consumer(<consumer> <producer>) | ||||||
| # | ||||||
| # * Links the consumer to the producer interface target. | ||||||
| # * Enables CMake's native module scanning on the consumer. | ||||||
| # | ||||||
| # * propagates module-related properties from producer interface target | ||||||
| # * sets necessary consumer compiler flags for clang and gcc | ||||||
| # CMake 3.29+ automatically resolves the BMI location from the FILE_SET | ||||||
|
Contributor
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. Shouldn't this be:
Suggested change
|
||||||
| # CXX_MODULES declared on the producer. No -fprebuilt-module-path needed. | ||||||
| function(hpx_configure_module_consumer consumer producer) | ||||||
| if(NOT TARGET ${consumer}) | ||||||
| hpx_error("hpx_configure_module_consumer: target '${consumer}' not found") | ||||||
|
|
@@ -146,41 +105,20 @@ 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) | ||||||
| set_target_properties(${consumer} PROPERTIES CXX_SCAN_FOR_MODULES ${_scan}) | ||||||
| endif() | ||||||
|
|
||||||
| get_target_property(_module_dir ${producer} INTERFACE_EXPORT_MODULE_DIR) | ||||||
| if(_module_dir) | ||||||
| if(MSVC) | ||||||
| return() | ||||||
| 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() | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ function(hpx_setup_target target) | |
| HPX_PREFIX | ||
| HEADER_ROOT | ||
| SCAN_FOR_MODULES | ||
| CXX_STANDARD | ||
|
Contributor
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. You may want to add this new argument option to |
||
| ) | ||
| set(multi_value_args DEPENDENCIES COMPONENT_DEPENDENCIES COMPILE_FLAGS | ||
| LINK_FLAGS INSTALL_FLAGS INSTALL_PDB | ||
|
|
@@ -87,6 +88,13 @@ function(hpx_setup_target target) | |
| hpx_debug("setup_target.${target}" "LINK_FLAGS: ${target_LINK_FLAGS}") | ||
| endif() | ||
|
|
||
| if(target_CXX_STANDARD) | ||
| set_target_properties( | ||
| ${target} PROPERTIES CXX_STANDARD ${target_CXX_STANDARD} | ||
| ) | ||
| hpx_debug("setup_target.${target}" "CXX_STANDARD: ${target_CXX_STANDARD}") | ||
| endif() | ||
|
|
||
| if(target_NAME) | ||
| set(name "${target_NAME}") | ||
| else() | ||
|
|
@@ -232,9 +240,21 @@ function(hpx_setup_target target) | |
| if(HPX_WITH_CXX_MODULES AND target_SCAN_FOR_MODULES) | ||
| hpx_debug("setup_target.${target} SCAN_FOR_MODULES: ON") | ||
|
|
||
| hpx_configure_module_consumer(${target} hpx_core_module_if) | ||
| if(TARGET hpx_core_module_if) | ||
| hpx_configure_module_consumer(${target} hpx_core_module_if) | ||
|
arpittkhandelwal marked this conversation as resolved.
|
||
| elseif(TARGET HPXInternal::hpx_core_module_if) | ||
| hpx_configure_module_consumer(${target} HPXInternal::hpx_core_module_if) | ||
| else() | ||
| hpx_error( | ||
| "setup_target.${target}: C++ modules scanning is enabled, but neither " | ||
| "hpx_core_module_if nor HPXInternal::hpx_core_module_if exists" | ||
| ) | ||
| endif() | ||
|
|
||
| if(TARGET hpx_full_module_if) | ||
| hpx_configure_module_consumer(${target} hpx_full_module_if) | ||
| elseif(TARGET HPXInternal::hpx_full_module_if) | ||
| hpx_configure_module_consumer(${target} HPXInternal::hpx_full_module_if) | ||
|
arpittkhandelwal marked this conversation as resolved.
arpittkhandelwal marked this conversation as resolved.
|
||
| endif() | ||
| else() | ||
| hpx_debug("setup_target.${target} SCAN_FOR_MODULES: OFF") | ||
|
|
@@ -247,8 +267,8 @@ function(hpx_setup_target target) | |
|
|
||
| # If modules are enabled, Clang emits DWARF v5, which requires using lld | ||
| # instead of ld. | ||
| if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES | ||
| "AppleClang" | ||
| if((NOT MSVC) AND (CMAKE_CXX_COMPILER_ID MATCHES "Clang" | ||
| OR CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") | ||
| ) | ||
|
arpittkhandelwal marked this conversation as resolved.
|
||
| get_target_property(_type ${target} TYPE) | ||
| if((_type STREQUAL "SHARED_LIBRARY") OR (_type STREQUAL "EXECUTABLE")) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.