Skip to content

Commit

Permalink
Merge topic 'duplicate-source-behavior' into release-3.31
Browse files Browse the repository at this point in the history
3e15419 target_sources: Restore toleration of duplicate CXX_MODULES sources
5cfb8ae Tests/CXXModules: add a test with duplicate sources

Acked-by: Kitware Robot <[email protected]>
Tested-by: buildbot <[email protected]>
Merge-request: !10155
  • Loading branch information
bradking authored and kwrobot committed Jan 10, 2025
2 parents 3df8890 + 3e15419 commit 92b2603
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Source/cmDyndepCollation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,23 @@ TdiSourceInfo CollationInformationSources(cmGeneratorTarget const* gt,
}
}

// Detect duplicate sources.
std::set<std::string> visited_sources;

for (auto const& files_per_dir : files_per_dirs) {
for (auto const& file : files_per_dir.second) {
auto const full_file = cmSystemTools::CollapseFullPath(file);
auto lookup = sf_map.find(full_file);
if (lookup == sf_map.end()) {
if (visited_sources.count(full_file)) {
// Duplicate source; raise an author warning.
gt->Makefile->IssueMessage(
MessageType::AUTHOR_WARNING,
cmStrCat(
"Target \"", tgt->GetName(), "\" has source file\n ", file,
"\nin a \"FILE_SET TYPE CXX_MODULES\" multiple times."));
continue;
}
gt->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("Target \"", tgt->GetName(), "\" has source file\n ",
Expand All @@ -140,6 +152,7 @@ TdiSourceInfo CollationInformationSources(cmGeneratorTarget const* gt,
"scheduled for compilation."));
continue;
}
visited_sources.insert(full_file);

auto const* sf = lookup->second.first;
CompileType const ct = lookup->second.second;
Expand Down
1 change: 1 addition & 0 deletions Tests/RunCMake/CXXModules/RunCMakeTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ endif ()

# Tests which require collation work.
if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION)
run_cxx_module_test(duplicate-sources)
run_cxx_module_test(public-req-private)
set(RunCMake_CXXModules_NO_TEST 1)
run_cxx_module_test(req-private-other-target)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CMake Warning \(dev\) in CMakeLists.txt:
Target "duplicate_sources" has source file

[^
]*/Tests/RunCMake/CXXModules/examples/duplicate-sources/duplicate.cxx

in a "FILE_SET TYPE CXX_MODULES" multiple times.
This warning is for project developers. Use -Wno-dev to suppress it.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.31)
project(cxx_modules_duplicate_sources CXX)

include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")

add_executable(duplicate_sources)
target_sources(duplicate_sources
PRIVATE
main.cxx
PRIVATE
FILE_SET CXX_MODULES
BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
duplicate.cxx
duplicate.cxx)
target_compile_features(duplicate_sources PRIVATE cxx_std_20)

add_test(NAME duplicate_sources COMMAND duplicate_sources)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module;

export module duplicate;

export int from_import()
{
return 0;
}
6 changes: 6 additions & 0 deletions Tests/RunCMake/CXXModules/examples/duplicate-sources/main.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import duplicate;

int main()
{
return from_import();
}

0 comments on commit 92b2603

Please sign in to comment.