1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 22:37:30 +08:00

FASTBuild: use relative paths in more places when enabled

When CMAKE_FASTBUILD_USE_RELATIVE_PATHS is set -
use relative paths for Unity nodes as well as for include directories.
It makes it possible to share cache across different location of
the same repo (or potentially across different machines)
This commit is contained in:
Eduard Voronkin
2025-09-21 14:14:20 -07:00
parent 7e0d79dfa7
commit 2f51a7d83f
4 changed files with 61 additions and 35 deletions

View File

@@ -91,41 +91,6 @@ static std::map<std::string, std::string> const compilerIdToFastbuildFamily = {
static std::set<std::string> const supportedLanguages = { "C", "CXX", "CUDA",
"OBJC", "OBJCXX" };
static void ReadCompilerOptions(FastbuildCompiler& compiler, cmMakefile* mf)
{
if (compiler.CompilerFamily == "custom") {
return;
}
if (cmIsOn(mf->GetSafeDefinition(FASTBUILD_USE_LIGHTCACHE))) {
compiler.UseLightCache = true;
}
if (cmIsOn(mf->GetSafeDefinition(FASTBUILD_USE_RELATIVE_PATHS))) {
compiler.UseRelativePaths = true;
}
if (cmIsOn(mf->GetSafeDefinition(FASTBUILD_USE_DETERMINISTIC_PATHS))) {
compiler.UseDeterministicPaths = true;
}
std::string sourceMapping = mf->GetSafeDefinition(FASTBUILD_SOURCE_MAPPING);
if (!sourceMapping.empty()) {
compiler.SourceMapping = std::move(sourceMapping);
}
auto const clangRewriteIncludesDef =
mf->GetDefinition(FASTBUILD_CLANG_REWRITE_INCLUDES);
if (clangRewriteIncludesDef.IsSet() && clangRewriteIncludesDef.IsOff()) {
compiler.ClangRewriteIncludes = false;
}
if (cmIsOn(mf->GetSafeDefinition(FASTBUILD_CLANG_GCC_UPDATE_XLANG_ARG))) {
compiler.ClangGCCUpdateXLanguageArg = true;
}
if (cmIsOn(mf->GetSafeDefinition(FASTBUILD_ALLOW_RESPONSE_FILE))) {
compiler.AllowResponseFile = true;
}
if (cmIsOn(mf->GetSafeDefinition(FASTBUILD_FORCE_RESPONSE_FILE))) {
compiler.ForceResponseFile = true;
}
}
template <class T>
FastbuildAliasNode generateAlias(std::string const& name, char const* postfix,
T const& nodes)
@@ -232,6 +197,43 @@ cmGlobalFastbuildGenerator::cmGlobalFastbuildGenerator(cmake* cm)
cm->GetState()->SetIsGeneratorMultiConfig(false);
}
void cmGlobalFastbuildGenerator::ReadCompilerOptions(
FastbuildCompiler& compiler, cmMakefile* mf)
{
if (compiler.CompilerFamily == "custom") {
return;
}
if (cmIsOn(mf->GetSafeDefinition(FASTBUILD_USE_LIGHTCACHE))) {
compiler.UseLightCache = true;
}
if (cmIsOn(mf->GetSafeDefinition(FASTBUILD_USE_RELATIVE_PATHS))) {
compiler.UseRelativePaths = true;
UsingRelativePaths = true;
}
if (cmIsOn(mf->GetSafeDefinition(FASTBUILD_USE_DETERMINISTIC_PATHS))) {
compiler.UseDeterministicPaths = true;
}
std::string sourceMapping = mf->GetSafeDefinition(FASTBUILD_SOURCE_MAPPING);
if (!sourceMapping.empty()) {
compiler.SourceMapping = std::move(sourceMapping);
}
auto const clangRewriteIncludesDef =
mf->GetDefinition(FASTBUILD_CLANG_REWRITE_INCLUDES);
if (clangRewriteIncludesDef.IsSet() && clangRewriteIncludesDef.IsOff()) {
compiler.ClangRewriteIncludes = false;
}
if (cmIsOn(mf->GetSafeDefinition(FASTBUILD_CLANG_GCC_UPDATE_XLANG_ARG))) {
compiler.ClangGCCUpdateXLanguageArg = true;
}
if (cmIsOn(mf->GetSafeDefinition(FASTBUILD_ALLOW_RESPONSE_FILE))) {
compiler.AllowResponseFile = true;
}
if (cmIsOn(mf->GetSafeDefinition(FASTBUILD_FORCE_RESPONSE_FILE))) {
compiler.ForceResponseFile = true;
}
}
void cmGlobalFastbuildGenerator::ProcessEnvironment()
{
bool const CaptureSystemEnv =
@@ -1178,6 +1180,9 @@ void cmGlobalFastbuildGenerator::WriteUnity(FastbuildUnityNode const& Unity)
WriteArray("UnityInputIsolatedFiles",
Wrap(Unity.UnityInputIsolatedFiles), 2);
}
if (UsingRelativePaths) {
WriteVariable("UseRelativePaths_Experimental", "true", 2);
}
}
Indent(1);
*BuildFileStream << "}\n";

View File

@@ -347,6 +347,7 @@ class cmGlobalFastbuildGenerator : public cmGlobalCommonGenerator
public:
cmGlobalFastbuildGenerator(cmake* cm);
void ReadCompilerOptions(FastbuildCompiler& compiler, cmMakefile* mf);
void ProcessEnvironment();
static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory();
@@ -614,6 +615,7 @@ public:
// configuration (like .objs files used to create module definition from
// objects).
std::unordered_set<std::string> AllFilesToKeep;
bool UsingRelativePaths = false;
private:
std::unordered_set<std::string> AllFilesToClean;

View File

@@ -16,6 +16,7 @@
#include "cmObjectLocation.h"
#include "cmSystemTools.h"
#include "cmValue.h"
#include "cmake.h"
class cmGlobalGenerator;
@@ -96,3 +97,16 @@ void cmLocalFastbuildGenerator::AdditionalCleanFiles(std::string const& config)
}
}
}
std::string cmLocalFastbuildGenerator::ConvertToIncludeReference(
std::string const& path, cmOutputConverter::OutputFormat format)
{
std::string converted = this->ConvertToOutputForExisting(path, format);
cmGlobalFastbuildGenerator const* GG = this->GetGlobalFastbuildGenerator();
if (GG->UsingRelativePaths && cmSystemTools::FileIsFullPath(path)) {
std::string const& binDir =
GG->GetCMakeInstance()->GetHomeOutputDirectory();
return cmSystemTools::RelativePath(binDir, converted);
}
return converted;
}

View File

@@ -6,6 +6,7 @@
#include <string>
#include "cmLocalCommonGenerator.h"
#include "cmOutputConverter.h"
class cmGeneratorTarget;
class cmGlobalFastbuildGenerator;
@@ -32,4 +33,8 @@ public:
cmGlobalFastbuildGenerator* GetGlobalFastbuildGenerator();
void AdditionalCleanFiles(std::string const& config);
private:
std::string ConvertToIncludeReference(
std::string const& path, cmOutputConverter::OutputFormat format) override;
};