Merge topic 'duplicate-source-behavior' into release-3.31
3e15419bd4
target_sources: Restore toleration of duplicate CXX_MODULES sources5cfb8ae790
Tests/CXXModules: add a test with duplicate sources Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !10155
This commit is contained in:
commit
92b260387d
@ -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 ",
|
||||
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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.
|
@ -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)
|
@ -0,0 +1,8 @@
|
||||
module;
|
||||
|
||||
export module duplicate;
|
||||
|
||||
export int from_import()
|
||||
{
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
import duplicate;
|
||||
|
||||
int main()
|
||||
{
|
||||
return from_import();
|
||||
}
|
Loading…
Reference in New Issue
Block a user