Browse Source

Merge topic 'iface-public-modules' into release-3.31

854eba0c53 target_sources: Improve error message for CXX_MODULES on INTERFACE libraries
cd179e7560 Tests/RunCMake/CXXModules: Rename FileSetModules cases to be more specific

Acked-by: Kitware Robot <[email protected]>
Tested-by: buildbot <[email protected]>
Merge-request: !10090
Brad King 1 year ago
parent
commit
2670dd4ed1

+ 12 - 0
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()) {

+ 0 - 0
Tests/RunCMake/CXXModules/FileSetModulesInterface-result.txt → Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnInterface-result.txt


+ 5 - 0
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\)

+ 8 - 0
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)

+ 1 - 0
Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic-result.txt

@@ -0,0 +1 @@
+1

+ 1 - 1
Tests/RunCMake/CXXModules/FileSetModulesInterface-stderr.txt → Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at FileSetModulesInterface.cmake:[0-9]+ \(target_sources\):
+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\):

+ 0 - 0
Tests/RunCMake/CXXModules/FileSetModulesInterface.cmake → Tests/RunCMake/CXXModules/FileSetModulesInterfaceOnStatic.cmake


+ 1 - 0
Tests/RunCMake/CXXModules/FileSetModulesPrivateOnInterface-result.txt

@@ -0,0 +1 @@
+1

+ 5 - 0
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\)$

+ 11 - 0
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)

+ 0 - 0
Tests/RunCMake/CXXModules/FileSetModulesPrivate.cmake → Tests/RunCMake/CXXModules/FileSetModulesPrivateOnStatic.cmake


+ 1 - 0
Tests/RunCMake/CXXModules/FileSetModulesPublicOnInterface-result.txt

@@ -0,0 +1 @@
+1

+ 5 - 0
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\)$

+ 11 - 0
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)

+ 0 - 0
Tests/RunCMake/CXXModules/FileSetModulesPublic.cmake → Tests/RunCMake/CXXModules/FileSetModulesPublicOnStatic.cmake


+ 7 - 1
Tests/RunCMake/CXXModules/RunCMakeTest.cmake

@@ -71,9 +71,15 @@ set(scopes
   Interface
   Private
   Public)
+set(target_types
+  Interface
+  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")