mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-31 02:39:48 -06:00
VS: Fix C++ modules in source files with the same name
When multiple source files in a single target have the same name, we
already set `ObjectFileName` explicitly to avoid a `.obj` collision. For
C++ module sources, set `Module{Output,Dependencies}File` to avoid
`.ifc` and `.module.json` collisions.
Fixes: #25038
This commit is contained in:
@@ -2778,6 +2778,8 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
|
||||
}
|
||||
}
|
||||
|
||||
bool isCppModule = false;
|
||||
|
||||
for (std::string const& config : this->Configurations) {
|
||||
this->GeneratorTarget->NeedCxxModuleSupport(lang, config);
|
||||
|
||||
@@ -2801,6 +2803,7 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
|
||||
if (fs && fs->GetType() == "CXX_MODULES"_s) {
|
||||
if (lang == "CXX"_s) {
|
||||
if (fs->GetType() == "CXX_MODULES"_s) {
|
||||
isCppModule = true;
|
||||
if (shouldScanForModules &&
|
||||
this->GlobalGenerator->IsScanDependenciesSupported()) {
|
||||
// ScanSourceforModuleDependencies uses 'cl /scanDependencies' and
|
||||
@@ -2959,6 +2962,14 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
|
||||
oh.OutputPreprocessorDefinitions(lang);
|
||||
}
|
||||
}
|
||||
|
||||
if (isCppModule && !objectName.empty()) {
|
||||
std::string baseName = cmStrCat("$(IntDir)/", objectName);
|
||||
cmStripSuffixIfExists(baseName, ".obj");
|
||||
e2.Element("ModuleOutputFile", cmStrCat(baseName, ".ifc"));
|
||||
e2.Element("ModuleDependenciesFile", cmStrCat(baseName, ".module.json"));
|
||||
}
|
||||
|
||||
if (this->IsXamlSource(source->GetFullPath())) {
|
||||
const std::string& fileName = source->GetFullPath();
|
||||
e2.Element("DependentUpon",
|
||||
|
||||
@@ -148,6 +148,7 @@ if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
||||
set(RunCMake_CXXModules_NO_TEST 1)
|
||||
run_cxx_module_test(circular)
|
||||
unset(RunCMake_CXXModules_NO_TEST)
|
||||
run_cxx_module_test(same-src-name)
|
||||
run_cxx_module_test(scan_properties)
|
||||
endif ()
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
CMake Warning \(dev\) at CMakeLists.txt:7 \(target_sources\):
|
||||
CMake's C\+\+ module support is experimental. It is meant only for
|
||||
experimentation and feedback to CMake developers.
|
||||
This warning is for project developers. Use -Wno-dev to suppress it.
|
||||
@@ -0,0 +1,20 @@
|
||||
cmake_minimum_required(VERSION 3.27)
|
||||
project(cxx_modules_same_src_name CXX)
|
||||
|
||||
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
|
||||
|
||||
add_executable(same_src_name)
|
||||
target_sources(same_src_name
|
||||
PRIVATE
|
||||
main.cxx
|
||||
PRIVATE
|
||||
FILE_SET CXX_MODULES
|
||||
BASE_DIRS
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
FILES
|
||||
a/same.cxx
|
||||
b/same.cxx
|
||||
)
|
||||
target_compile_features(same_src_name PUBLIC cxx_std_20)
|
||||
|
||||
add_test(NAME same_src_name COMMAND same_src_name)
|
||||
@@ -0,0 +1,5 @@
|
||||
export module a.same;
|
||||
export int a_same()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export module b.same;
|
||||
export int b_same()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import a.same;
|
||||
import b.same;
|
||||
|
||||
int main()
|
||||
{
|
||||
return a_same() + b_same();
|
||||
}
|
||||
Reference in New Issue
Block a user