cmLocalGenerator: add an override for CMakeFiles-using paths

Visual Studio doesn't use a `CMakeFiles` subdirectory for its support
directories. However, some codepaths expect to use paths which are
always under `CMakeFiles`. Add a mechanism to keep the path for such
files.
This commit is contained in:
Ben Boeckel 2025-05-23 15:22:35 +02:00
parent 35d32b8741
commit c95a8348ce
8 changed files with 31 additions and 6 deletions

View File

@ -2851,7 +2851,7 @@ std::string cmGeneratorTarget::GetPchHeader(std::string const& config,
{ "OBJCXX", ".objcxx.hxx" }
};
filename = generatorTarget->GetSupportDirectory();
filename = generatorTarget->GetCMFSupportDirectory();
if (this->GetGlobalGenerator()->IsMultiConfig()) {
filename = cmStrCat(filename, '/', config);
@ -2944,7 +2944,8 @@ std::string cmGeneratorTarget::GetPchSource(std::string const& config,
this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
}
filename = cmStrCat(generatorTarget->GetSupportDirectory(), "/cmake_pch");
filename =
cmStrCat(generatorTarget->GetCMFSupportDirectory(), "/cmake_pch");
// For GCC the source extension will be transformed into .h[xx].gch
if (!this->Makefile->IsOn("CMAKE_LINK_PCH")) {
@ -5222,6 +5223,17 @@ std::string cmGeneratorTarget::GetSupportDirectory() const
lg->GetTargetDirectory(this));
}
std::string cmGeneratorTarget::GetCMFSupportDirectory() const
{
cmLocalGenerator* lg = this->GetLocalGenerator();
if (!lg->AlwaysUsesCMFPaths()) {
return cmStrCat(lg->GetCurrentBinaryDirectory(), "/CMakeFiles/",
lg->GetTargetDirectory(this));
}
return cmStrCat(lg->GetObjectOutputRoot(), '/',
lg->GetTargetDirectory(this));
}
bool cmGeneratorTarget::IsLinkable() const
{
return (this->GetType() == cmStateEnums::STATIC_LIBRARY ||

View File

@ -935,6 +935,7 @@ public:
/** Get a build-tree directory in which to place target support files. */
std::string GetSupportDirectory() const;
std::string GetCMFSupportDirectory() const;
/** Return whether this target may be used to link another target. */
bool IsLinkable() const;

View File

@ -3636,7 +3636,7 @@ void cmGlobalGenerator::WriteSummary()
continue;
}
this->WriteSummary(tgt.get());
fout << tgt->GetSupportDirectory() << '\n';
fout << tgt->GetCMFSupportDirectory() << '\n';
}
}
}
@ -3644,7 +3644,7 @@ void cmGlobalGenerator::WriteSummary()
void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target)
{
// Place the labels file in a per-target support directory.
std::string dir = target->GetSupportDirectory();
std::string dir = target->GetCMFSupportDirectory();
std::string file = cmStrCat(dir, "/Labels.txt");
std::string json_file = cmStrCat(dir, "/Labels.json");

View File

@ -51,7 +51,7 @@ std::string cmInstallCxxModuleBmiGenerator::GetScriptLocation(
if (config.empty()) {
config_name = "noconfig";
}
return cmStrCat(this->Target->GetSupportDirectory(),
return cmStrCat(this->Target->GetCMFSupportDirectory(),
"/install-cxx-module-bmi-", config_name, ".cmake");
}

View File

@ -3323,7 +3323,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
}
std::string filename_base =
cmStrCat(target->GetSupportDirectory(), "/Unity/");
cmStrCat(target->GetCMFSupportDirectory(), "/Unity/");
cmValue batchSizeString = target->GetProperty("UNITY_BUILD_BATCH_SIZE");
size_t const unityBatchSize = batchSizeString
@ -4291,6 +4291,11 @@ std::string cmLocalGenerator::GetObjectOutputRoot() const
return cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles");
}
bool cmLocalGenerator::AlwaysUsesCMFPaths() const
{
return true;
}
std::string cmLocalGenerator::GetSourceFileLanguage(cmSourceFile const& source)
{
return source.GetLanguage();

View File

@ -439,6 +439,7 @@ public:
std::string const& GetCurrentSourceDirectory() const;
virtual std::string GetObjectOutputRoot() const;
virtual bool AlwaysUsesCMFPaths() const;
/**
* Generate a macOS application bundle Info.plist file.

View File

@ -89,6 +89,11 @@ std::string cmLocalVisualStudioGenerator::GetObjectOutputRoot() const
return this->GetCurrentBinaryDirectory();
}
bool cmLocalVisualStudioGenerator::AlwaysUsesCMFPaths() const
{
return false;
}
std::unique_ptr<cmCustomCommand>
cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmGeneratorTarget* target,
std::string const& config,

View File

@ -52,6 +52,7 @@ public:
cmGeneratorTarget const* = nullptr) override;
std::string GetObjectOutputRoot() const override;
bool AlwaysUsesCMFPaths() const override;
protected:
virtual char const* ReportErrorLabel() const;