From cd179e75606c6dc821b10574927e449b397b931c Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 11 Dec 2024 12:10:48 -0500 Subject: Tests/RunCMake/CXXModules: Rename FileSetModules cases to be more specific They all add `CXX_MODULES` to `STATIC` libraries. --- Tests/RunCMake/CXXModules/FileSetModulesInterface-result.txt | 1 - Tests/RunCMake/CXXModules/FileSetModulesInterface-stderr.txt | 5 ----- Tests/RunCMake/CXXModules/FileSetModulesInterface.cmake | 8 -------- .../CXXModules/FileSetModulesInterfaceOnStatic-result.txt | 1 + .../CXXModules/FileSetModulesInterfaceOnStatic-stderr.txt | 5 +++++ .../RunCMake/CXXModules/FileSetModulesInterfaceOnStatic.cmake | 8 ++++++++ Tests/RunCMake/CXXModules/FileSetModulesPrivate.cmake | 11 ----------- Tests/RunCMake/CXXModules/FileSetModulesPrivateOnStatic.cmake | 11 +++++++++++ Tests/RunCMake/CXXModules/FileSetModulesPublic.cmake | 11 ----------- Tests/RunCMake/CXXModules/FileSetModulesPublicOnStatic.cmake | 11 +++++++++++ Tests/RunCMake/CXXModules/RunCMakeTest.cmake | 7 ++++++- 11 files changed, 42 insertions(+), 37 deletions(-) delete mode 100644 Tests/RunCMake/CXXModules/FileSetModulesInterface-result.txt delete mode 100644 Tests/RunCMake/CXXModules/FileSetModulesInterface-stderr.txt delete mode 100644 Tests/RunCMake/CXXModules/FileSetModulesInterface.cmake create mode 100644 Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic-result.txt create mode 100644 Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic-stderr.txt create mode 100644 Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic.cmake delete mode 100644 Tests/RunCMake/CXXModules/FileSetModulesPrivate.cmake create mode 100644 Tests/RunCMake/CXXModules/FileSetModulesPrivateOnStatic.cmake delete mode 100644 Tests/RunCMake/CXXModules/FileSetModulesPublic.cmake create mode 100644 Tests/RunCMake/CXXModules/FileSetModulesPublicOnStatic.cmake diff --git a/Tests/RunCMake/CXXModules/FileSetModulesInterface-result.txt b/Tests/RunCMake/CXXModules/FileSetModulesInterface-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/CXXModules/FileSetModulesInterface-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/CXXModules/FileSetModulesInterface-stderr.txt b/Tests/RunCMake/CXXModules/FileSetModulesInterface-stderr.txt deleted file mode 100644 index 7269c65..0000000 --- a/Tests/RunCMake/CXXModules/FileSetModulesInterface-stderr.txt +++ /dev/null @@ -1,5 +0,0 @@ -CMake Error at FileSetModulesInterface.cmake:[0-9]+ \(target_sources\): - target_sources File set TYPE "CXX_MODULES" may not have "INTERFACE" - visibility -Call Stack \(most recent call first\): - CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/CXXModules/FileSetModulesInterface.cmake b/Tests/RunCMake/CXXModules/FileSetModulesInterface.cmake deleted file mode 100644 index 24cec3e..0000000 --- a/Tests/RunCMake/CXXModules/FileSetModulesInterface.cmake +++ /dev/null @@ -1,8 +0,0 @@ -add_library(module) -target_sources(module - INTERFACE - FILE_SET fs TYPE CXX_MODULES FILES - sources/module.cxx) -target_compile_features(module - PRIVATE - cxx_std_20) diff --git a/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic-result.txt b/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic-stderr.txt b/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic-stderr.txt new file mode 100644 index 0000000..7d099de --- /dev/null +++ b/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic-stderr.txt @@ -0,0 +1,5 @@ +CMake Error at FileSetModulesInterfaceOnStatic.cmake:[0-9]+ \(target_sources\): + target_sources File set TYPE "CXX_MODULES" may not have "INTERFACE" + visibility +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic.cmake b/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic.cmake new file mode 100644 index 0000000..24cec3e --- /dev/null +++ b/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic.cmake @@ -0,0 +1,8 @@ +add_library(module) +target_sources(module + INTERFACE + FILE_SET fs TYPE CXX_MODULES FILES + sources/module.cxx) +target_compile_features(module + PRIVATE + cxx_std_20) diff --git a/Tests/RunCMake/CXXModules/FileSetModulesPrivate.cmake b/Tests/RunCMake/CXXModules/FileSetModulesPrivate.cmake deleted file mode 100644 index 83bbd4d..0000000 --- a/Tests/RunCMake/CXXModules/FileSetModulesPrivate.cmake +++ /dev/null @@ -1,11 +0,0 @@ -enable_language(CXX) -set(CMAKE_CXX_SCANDEP_SOURCE "") - -add_library(module) -target_sources(module - PRIVATE - FILE_SET fs TYPE CXX_MODULES FILES - sources/module.cxx) -target_compile_features(module - PRIVATE - cxx_std_20) diff --git a/Tests/RunCMake/CXXModules/FileSetModulesPrivateOnStatic.cmake b/Tests/RunCMake/CXXModules/FileSetModulesPrivateOnStatic.cmake new file mode 100644 index 0000000..83bbd4d --- /dev/null +++ b/Tests/RunCMake/CXXModules/FileSetModulesPrivateOnStatic.cmake @@ -0,0 +1,11 @@ +enable_language(CXX) +set(CMAKE_CXX_SCANDEP_SOURCE "") + +add_library(module) +target_sources(module + PRIVATE + FILE_SET fs TYPE CXX_MODULES FILES + sources/module.cxx) +target_compile_features(module + PRIVATE + cxx_std_20) diff --git a/Tests/RunCMake/CXXModules/FileSetModulesPublic.cmake b/Tests/RunCMake/CXXModules/FileSetModulesPublic.cmake deleted file mode 100644 index 52ba35f..0000000 --- a/Tests/RunCMake/CXXModules/FileSetModulesPublic.cmake +++ /dev/null @@ -1,11 +0,0 @@ -enable_language(CXX) -set(CMAKE_CXX_SCANDEP_SOURCE "") - -add_library(module) -target_sources(module - PUBLIC - FILE_SET fs TYPE CXX_MODULES FILES - sources/module.cxx) -target_compile_features(module - PRIVATE - cxx_std_20) diff --git a/Tests/RunCMake/CXXModules/FileSetModulesPublicOnStatic.cmake b/Tests/RunCMake/CXXModules/FileSetModulesPublicOnStatic.cmake new file mode 100644 index 0000000..52ba35f --- /dev/null +++ b/Tests/RunCMake/CXXModules/FileSetModulesPublicOnStatic.cmake @@ -0,0 +1,11 @@ +enable_language(CXX) +set(CMAKE_CXX_SCANDEP_SOURCE "") + +add_library(module) +target_sources(module + PUBLIC + FILE_SET fs TYPE CXX_MODULES FILES + sources/module.cxx) +target_compile_features(module + PRIVATE + cxx_std_20) diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index 8b7bc86..0413793 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -71,9 +71,14 @@ set(scopes Interface Private Public) +set(target_types + Static + ) foreach (fileset_type IN LISTS fileset_types) foreach (scope IN LISTS scopes) - run_cmake("FileSet${fileset_type}${scope}") + foreach (target_type IN LISTS target_types) + run_cmake("FileSet${fileset_type}${scope}On${target_type}") + endforeach () endforeach () run_cmake("FileSet${fileset_type}InterfaceImported") -- cgit v0.12 From 854eba0c53505190adb8fdd32cbdaed318d8dfda Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 11 Dec 2024 11:53:26 -0500 Subject: target_sources: Improve error message for CXX_MODULES on INTERFACE libraries We support non-compiled `SOURCES` on `INTERFACE` libraries, and also support `CXX_MODULES` on *imported* `INTERFACE` libraries (via synthetic targets that compile module interface units). However, we do not support `CXX_MODULES` on non-imported `INTERFACE` libraries because there is no place to hold module interface unit's object files for their module initializers. Previously this was not explicitly rejected, and so was diagnosed only by "CMake Internal Error" messages due to assumption violations in the implementation. Fixes: #26524 Co-authored-by: Ben Boeckel --- Source/cmTargetSourcesCommand.cxx | 12 ++++++++++++ .../CXXModules/FileSetModulesInterfaceOnInterface-result.txt | 1 + .../CXXModules/FileSetModulesInterfaceOnInterface-stderr.txt | 5 +++++ .../CXXModules/FileSetModulesInterfaceOnInterface.cmake | 8 ++++++++ .../CXXModules/FileSetModulesPrivateOnInterface-result.txt | 1 + .../CXXModules/FileSetModulesPrivateOnInterface-stderr.txt | 5 +++++ .../CXXModules/FileSetModulesPrivateOnInterface.cmake | 11 +++++++++++ .../CXXModules/FileSetModulesPublicOnInterface-result.txt | 1 + .../CXXModules/FileSetModulesPublicOnInterface-stderr.txt | 5 +++++ .../CXXModules/FileSetModulesPublicOnInterface.cmake | 11 +++++++++++ Tests/RunCMake/CXXModules/RunCMakeTest.cmake | 1 + 11 files changed, 61 insertions(+) create mode 100644 Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnInterface-result.txt create mode 100644 Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnInterface-stderr.txt create mode 100644 Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnInterface.cmake create mode 100644 Tests/RunCMake/CXXModules/FileSetModulesPrivateOnInterface-result.txt create mode 100644 Tests/RunCMake/CXXModules/FileSetModulesPrivateOnInterface-stderr.txt create mode 100644 Tests/RunCMake/CXXModules/FileSetModulesPrivateOnInterface.cmake create mode 100644 Tests/RunCMake/CXXModules/FileSetModulesPublicOnInterface-result.txt create mode 100644 Tests/RunCMake/CXXModules/FileSetModulesPublicOnInterface-stderr.txt create mode 100644 Tests/RunCMake/CXXModules/FileSetModulesPublicOnInterface.cmake diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx index babbaa5..cdb9836 100644 --- a/Source/cmTargetSourcesCommand.cxx +++ b/Source/cmTargetSourcesCommand.cxx @@ -265,6 +265,18 @@ bool TargetSourcesImpl::HandleOneFileSet( return false; } + if (cmFileSetVisibilityIsForSelf(visibility) && + this->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY && + !this->Target->IsImported()) { + if (type == "CXX_MODULES"_s) { + this->SetError(R"(File set TYPE "CXX_MODULES" may not have "PUBLIC" )" + R"(or "PRIVATE" visibility on INTERFACE libraries.)"); + return false; + } + } + + // FIXME(https://wg21.link/P3470): This condition can go + // away when interface-only module units are a thing. if (cmFileSetVisibilityIsForInterface(visibility) && !cmFileSetVisibilityIsForSelf(visibility) && !this->Target->IsImported()) { diff --git a/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnInterface-result.txt b/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnInterface-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnInterface-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnInterface-stderr.txt b/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnInterface-stderr.txt new file mode 100644 index 0000000..d14a221 --- /dev/null +++ b/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnInterface-stderr.txt @@ -0,0 +1,5 @@ +CMake Error at FileSetModulesInterfaceOnInterface.cmake:[0-9]+ \(target_sources\): + target_sources File set TYPE "CXX_MODULES" may not have "INTERFACE" + visibility +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnInterface.cmake b/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnInterface.cmake new file mode 100644 index 0000000..c2c4d63 --- /dev/null +++ b/Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnInterface.cmake @@ -0,0 +1,8 @@ +add_library(module INTERFACE) +target_sources(module + INTERFACE + FILE_SET fs TYPE CXX_MODULES FILES + sources/module.cxx) +target_compile_features(module + INTERFACE + cxx_std_20) diff --git a/Tests/RunCMake/CXXModules/FileSetModulesPrivateOnInterface-result.txt b/Tests/RunCMake/CXXModules/FileSetModulesPrivateOnInterface-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CXXModules/FileSetModulesPrivateOnInterface-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CXXModules/FileSetModulesPrivateOnInterface-stderr.txt b/Tests/RunCMake/CXXModules/FileSetModulesPrivateOnInterface-stderr.txt new file mode 100644 index 0000000..f949df9 --- /dev/null +++ b/Tests/RunCMake/CXXModules/FileSetModulesPrivateOnInterface-stderr.txt @@ -0,0 +1,5 @@ +^CMake Error at FileSetModulesPrivateOnInterface\.cmake:[0-9]+ \(target_sources\): + target_sources File set TYPE "CXX_MODULES" may not have "PUBLIC" or + "PRIVATE" visibility on INTERFACE libraries\. +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/CXXModules/FileSetModulesPrivateOnInterface.cmake b/Tests/RunCMake/CXXModules/FileSetModulesPrivateOnInterface.cmake new file mode 100644 index 0000000..9ee4024 --- /dev/null +++ b/Tests/RunCMake/CXXModules/FileSetModulesPrivateOnInterface.cmake @@ -0,0 +1,11 @@ +enable_language(CXX) +set(CMAKE_CXX_SCANDEP_SOURCE "") + +add_library(module INTERFACE) +target_sources(module + PRIVATE + FILE_SET fs TYPE CXX_MODULES FILES + sources/module.cxx) +target_compile_features(module + INTERFACE + cxx_std_20) diff --git a/Tests/RunCMake/CXXModules/FileSetModulesPublicOnInterface-result.txt b/Tests/RunCMake/CXXModules/FileSetModulesPublicOnInterface-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CXXModules/FileSetModulesPublicOnInterface-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CXXModules/FileSetModulesPublicOnInterface-stderr.txt b/Tests/RunCMake/CXXModules/FileSetModulesPublicOnInterface-stderr.txt new file mode 100644 index 0000000..7d732eb --- /dev/null +++ b/Tests/RunCMake/CXXModules/FileSetModulesPublicOnInterface-stderr.txt @@ -0,0 +1,5 @@ +^CMake Error at FileSetModulesPublicOnInterface\.cmake:[0-9]+ \(target_sources\): + target_sources File set TYPE "CXX_MODULES" may not have "PUBLIC" or + "PRIVATE" visibility on INTERFACE libraries\. +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/CXXModules/FileSetModulesPublicOnInterface.cmake b/Tests/RunCMake/CXXModules/FileSetModulesPublicOnInterface.cmake new file mode 100644 index 0000000..0bc4123 --- /dev/null +++ b/Tests/RunCMake/CXXModules/FileSetModulesPublicOnInterface.cmake @@ -0,0 +1,11 @@ +enable_language(CXX) +set(CMAKE_CXX_SCANDEP_SOURCE "") + +add_library(module INTERFACE) +target_sources(module + PUBLIC + FILE_SET fs TYPE CXX_MODULES FILES + sources/module.cxx) +target_compile_features(module + INTERFACE + cxx_std_20) diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index 0413793..8780ff2 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -72,6 +72,7 @@ set(scopes Private Public) set(target_types + Interface Static ) foreach (fileset_type IN LISTS fileset_types) -- cgit v0.12