mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 13:51:33 -06:00
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 <ben.boeckel@kitware.com>
This commit is contained in:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user