c++modules: discover synth targets for all configs

Fixes: #26312
This commit is contained in:
Vito Gamberini
2026-07-16 12:10:02 -04:00
parent 1f3b0f6c0a
commit 82683ae8b0
8 changed files with 90 additions and 9 deletions
+2 -2
View File
@@ -193,7 +193,7 @@ cmCommonTargetGenerator::GetLinkedTargetDirectories(
auto const& synthDeps = this->GeneratorTarget->GetSyntheticDeps(config);
auto it = synthDeps.find(linkee);
if (it != synthDeps.end() && !it->second.empty()) {
return it->second.front();
return *it->second.begin();
}
// Check linked targets to find synthetic targets for transitive deps
@@ -227,7 +227,7 @@ cmCommonTargetGenerator::GetLinkedTargetDirectories(
auto itLinkeeSynth = transitiveSynthDeps.find(linkee);
if (itLinkeeSynth != transitiveSynthDeps.end() &&
!itLinkeeSynth->second.empty()) {
return itLinkeeSynth->second.front();
return *itLinkeeSynth->second.begin();
}
for (auto const& entry : transitiveSynthDeps) {
for (auto const* synth : entry.second) {
+6 -3
View File
@@ -5590,8 +5590,11 @@ cmGeneratorTarget const* cmGeneratorTarget::GetCxxSyntheticTarget(
lg->AddGeneratorTarget(std::move(gtp));
this->SynthCxxTargets[usageHash] = syntheticTarget;
if (!syntheticTarget->DiscoverSyntheticTargets(config, &bmiConsumer)) {
return nullptr;
for (auto const& innerConfig : allConfigs) {
if (!syntheticTarget->DiscoverSyntheticTargets(innerConfig,
&bmiConsumer)) {
return nullptr;
}
}
return syntheticTarget;
@@ -5629,7 +5632,7 @@ bool cmGeneratorTarget::DiscoverSyntheticTargets(
return false;
}
if (dep->IsSynthetic()) {
SyntheticDeps[gt].push_back(dep);
SyntheticDeps[gt].insert(dep);
}
}
+2 -2
View File
@@ -1155,7 +1155,7 @@ public:
std::string const& config, cmGeneratorTarget const* bmiConsumer = nullptr);
using SyntheticDepsMap =
std::map<cmGeneratorTarget const*, std::vector<cmGeneratorTarget const*>>;
std::map<cmGeneratorTarget const*, std::set<cmGeneratorTarget const*>>;
SyntheticDepsMap const& GetSyntheticDeps(std::string const& config) const;
class CustomTransitiveProperty : public TransitiveProperty
@@ -1613,7 +1613,7 @@ public:
private:
struct InfoByConfig
{
std::map<cmGeneratorTarget const*, std::vector<cmGeneratorTarget const*>>
std::map<cmGeneratorTarget const*, std::set<cmGeneratorTarget const*>>
SyntheticDeps;
std::map<cmSourceFile const*, ClassifiedFlags> SourceFlags;
};
@@ -219,11 +219,15 @@ if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
run_cxx_module_test(scan_props)
run_cxx_module_test(target-objects)
# mixed-bmi-compatibility requires a generator that implements per-importer
# BMI generation
# Requires a generator that implements per-importer BMI generation
if ("cxx_std_23" IN_LIST CMAKE_CXX_COMPILE_FEATURES AND
RunCMake_GENERATOR MATCHES "Ninja")
run_cxx_module_test(mixed-bmi-compatibility)
if (RunCMake_GENERATOR_IS_MULTI_CONFIG AND
"collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND
"bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION)
run_cxx_module_test(multi-config-synth)
endif()
endif()
if ("cxx_std_23" IN_LIST CMAKE_CXX_COMPILE_FEATURES AND
@@ -0,0 +1,54 @@
cmake_minimum_required(VERSION 3.24...3.28)
project(cxx_modules_multi_config_synth CXX)
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
add_library(importable)
target_sources(importable
PUBLIC FILE_SET CXX_MODULES FILES importable.cxx)
target_compile_features(importable PUBLIC cxx_std_20)
export(TARGETS importable
NAMESPACE CXXModules::
FILE "${CMAKE_CURRENT_BINARY_DIR}/importable-targets.cmake"
CXX_MODULES_DIRECTORY "importable-cxx-modules"
)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/importable-config.cmake"
"include(\"\${CMAKE_CURRENT_LIST_DIR}/importable-targets.cmake\")\n"
)
set(generator
-G "${CMAKE_GENERATOR}")
if (CMAKE_GENERATOR_TOOLSET)
list(APPEND generator -T "${CMAKE_GENERATOR_TOOLSET}")
endif ()
if (CMAKE_GENERATOR_PLATFORM)
list(APPEND generator -A "${CMAKE_GENERATOR_PLATFORM}")
endif ()
add_test(NAME multi_config_synth_consumer
COMMAND
"${CMAKE_COMMAND}"
"-DCMAKE_PREFIX_PATH=${CMAKE_CURRENT_BINARY_DIR}"
${generator}
-S "${CMAKE_CURRENT_SOURCE_DIR}/consumer"
-B "${CMAKE_CURRENT_BINARY_DIR}/consumer"
)
add_test(NAME multi_config_synth_build_debug
COMMAND
"${CMAKE_COMMAND}" --build "${CMAKE_CURRENT_BINARY_DIR}/consumer" --config Debug
)
add_test(NAME multi_config_synth_build_release
COMMAND
"${CMAKE_COMMAND}" --build "${CMAKE_CURRENT_BINARY_DIR}/consumer" --config Release
)
set_tests_properties(
multi_config_synth_build_debug
multi_config_synth_build_release
PROPERTIES DEPENDS multi_config_synth_consumer)
add_test(NAME multi_config_synth_run
COMMAND "${CMAKE_CTEST_COMMAND}" -C Debug --test-dir "${CMAKE_CURRENT_BINARY_DIR}/consumer"
)
set_tests_properties(multi_config_synth_run
PROPERTIES DEPENDS multi_config_synth_build_debug)
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.24...3.28)
project(cxx_modules_multi_config_consumer CXX)
find_package(importable REQUIRED)
add_executable(consumer main.cxx)
target_link_libraries(consumer PRIVATE CXXModules::importable)
target_compile_features(consumer PRIVATE cxx_std_20)
add_test(NAME consumer COMMAND consumer)
@@ -0,0 +1,5 @@
import importable;
int main()
{
return from_import();
}
@@ -0,0 +1,5 @@
export module importable;
export int from_import()
{
return 0;
}