Merge topic 'mk-directory'

c8fd23ec6f cmMakefile: return directories as const std::string&

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2311
This commit is contained in:
Brad King 2018-08-28 17:42:36 +00:00 committed by Kitware Robot
commit 6f7c96fb17
21 changed files with 65 additions and 67 deletions

View File

@ -320,7 +320,7 @@ bool cmAddCustomCommandCommand::InitialPass(
// Convert working directory to a full path.
if (!working.empty()) {
const char* build_dir = this->Makefile->GetCurrentBinaryDirectory();
const std::string& build_dir = this->Makefile->GetCurrentBinaryDirectory();
working = cmSystemTools::CollapseFullPath(working, build_dir);
}

View File

@ -183,7 +183,7 @@ bool cmAddCustomTargetCommand::InitialPass(
// Convert working directory to a full path.
if (!working_directory.empty()) {
const char* build_dir = this->Makefile->GetCurrentBinaryDirectory();
const std::string& build_dir = this->Makefile->GetCurrentBinaryDirectory();
working_directory =
cmSystemTools::CollapseFullPath(working_directory, build_dir);
}

View File

@ -80,17 +80,17 @@ bool cmAddSubDirectoryCommand::InitialPass(
// Remove the CurrentDirectory from the srcPath and replace it
// with the CurrentOutputDirectory.
const char* src = this->Makefile->GetCurrentSourceDirectory();
const char* bin = this->Makefile->GetCurrentBinaryDirectory();
size_t srcLen = strlen(src);
size_t binLen = strlen(bin);
const std::string& src = this->Makefile->GetCurrentSourceDirectory();
const std::string& bin = this->Makefile->GetCurrentBinaryDirectory();
size_t srcLen = src.length();
size_t binLen = bin.length();
if (srcLen > 0 && src[srcLen - 1] == '/') {
--srcLen;
}
if (binLen > 0 && bin[binLen - 1] == '/') {
--binLen;
}
binPath = std::string(bin, binLen) + srcPath.substr(srcLen);
binPath = bin.substr(0, binLen) + srcPath.substr(srcLen);
} else {
// Use the binary directory specified.
// Interpret a relative path with respect to the current binary directory.

View File

@ -118,22 +118,22 @@ const char* CCONV cmGetHomeOutputDirectory(void* arg)
const char* CCONV cmGetStartDirectory(void* arg)
{
cmMakefile* mf = static_cast<cmMakefile*>(arg);
return mf->GetCurrentSourceDirectory();
return mf->GetCurrentSourceDirectory().c_str();
}
const char* CCONV cmGetStartOutputDirectory(void* arg)
{
cmMakefile* mf = static_cast<cmMakefile*>(arg);
return mf->GetCurrentBinaryDirectory();
return mf->GetCurrentBinaryDirectory().c_str();
}
const char* CCONV cmGetCurrentDirectory(void* arg)
{
cmMakefile* mf = static_cast<cmMakefile*>(arg);
return mf->GetCurrentSourceDirectory();
return mf->GetCurrentSourceDirectory().c_str();
}
const char* CCONV cmGetCurrentOutputDirectory(void* arg)
{
cmMakefile* mf = static_cast<cmMakefile*>(arg);
return mf->GetCurrentBinaryDirectory();
return mf->GetCurrentBinaryDirectory().c_str();
}
const char* CCONV cmGetDefinition(void* arg, const char* def)
{

View File

@ -254,12 +254,12 @@ bool cmExportCommand::HandlePackage(std::vector<std::string> const& args)
// We store the current build directory in the registry as a value
// named by a hash of its own content. This is deterministic and is
// unique with high probability.
const char* outDir = this->Makefile->GetCurrentBinaryDirectory();
const std::string& outDir = this->Makefile->GetCurrentBinaryDirectory();
std::string hash = cmSystemTools::ComputeStringMD5(outDir);
#if defined(_WIN32) && !defined(__CYGWIN__)
this->StorePackageRegistryWin(package, outDir, hash.c_str());
this->StorePackageRegistryWin(package, outDir.c_str(), hash.c_str());
#else
this->StorePackageRegistryDir(package, outDir, hash.c_str());
this->StorePackageRegistryDir(package, outDir.c_str(), hash.c_str());
#endif
return true;

View File

@ -3463,7 +3463,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args)
}
if (!cmsys::SystemTools::FileIsFullPath(path)) {
path = this->Makefile->GetCurrentSourceDirectory() + ("/" + path);
path = this->Makefile->GetCurrentSourceDirectory() + "/" + path;
}
// Unify path (remove '//', '/../', ...)

View File

@ -64,8 +64,8 @@ bool cmTarget::StrictTargetComparison::operator()(cmTarget const* t1,
{
int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
if (nameResult == 0) {
return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory(),
t2->GetMakefile()->GetCurrentBinaryDirectory()) < 0;
return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory().c_str(),
t2->GetMakefile()->GetCurrentBinaryDirectory().c_str()) < 0;
}
return nameResult < 0;
}

View File

@ -73,7 +73,7 @@ void cmInstallDirectoryGenerator::GenerateScriptForConfig(
cmMakefile const& mf = *this->LocalGenerator->GetMakefile();
for (std::string& d : dirs) {
if (!cmSystemTools::FileIsFullPath(d)) {
d = std::string(mf.GetCurrentSourceDirectory()) + "/" + d;
d = mf.GetCurrentSourceDirectory() + "/" + d;
}
}

View File

@ -1635,14 +1635,14 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath,
}
}
const char* cmMakefile::GetCurrentSourceDirectory() const
const std::string& cmMakefile::GetCurrentSourceDirectory() const
{
return this->StateSnapshot.GetDirectory().GetCurrentSource().c_str();
return this->StateSnapshot.GetDirectory().GetCurrentSource();
}
const char* cmMakefile::GetCurrentBinaryDirectory() const
const std::string& cmMakefile::GetCurrentBinaryDirectory() const
{
return this->StateSnapshot.GetDirectory().GetCurrentBinary().c_str();
return this->StateSnapshot.GetDirectory().GetCurrentBinary();
}
std::vector<cmTarget*> cmMakefile::GetImportedTargets() const

View File

@ -327,8 +327,8 @@ public:
*/
void SetArgcArgv(const std::vector<std::string>& args);
const char* GetCurrentSourceDirectory() const;
const char* GetCurrentBinaryDirectory() const;
std::string const& GetCurrentSourceDirectory() const;
std::string const& GetCurrentBinaryDirectory() const;
//@}

View File

@ -35,19 +35,19 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
srcdir += "_SOURCE_DIR";
this->Makefile->AddCacheDefinition(
bindir, this->Makefile->GetCurrentBinaryDirectory(),
bindir, this->Makefile->GetCurrentBinaryDirectory().c_str(),
"Value Computed by CMake", cmStateEnums::STATIC);
this->Makefile->AddCacheDefinition(
srcdir, this->Makefile->GetCurrentSourceDirectory(),
srcdir, this->Makefile->GetCurrentSourceDirectory().c_str(),
"Value Computed by CMake", cmStateEnums::STATIC);
bindir = "PROJECT_BINARY_DIR";
srcdir = "PROJECT_SOURCE_DIR";
this->Makefile->AddDefinition(bindir,
this->Makefile->GetCurrentBinaryDirectory());
this->Makefile->AddDefinition(srcdir,
this->Makefile->GetCurrentSourceDirectory());
this->Makefile->AddDefinition(
bindir, this->Makefile->GetCurrentBinaryDirectory().c_str());
this->Makefile->AddDefinition(
srcdir, this->Makefile->GetCurrentSourceDirectory().c_str());
this->Makefile->AddDefinition("PROJECT_NAME", projectName.c_str());

View File

@ -231,7 +231,7 @@ bool cmQtAutoGenInitializer::InitCustomTargets()
{
// Collapsed current binary directory
std::string const cbd = cmSystemTools::CollapseFullPath(
"", makefile->GetCurrentBinaryDirectory());
std::string(), makefile->GetCurrentBinaryDirectory());
// Info directory
this->Dir.Info = cbd;
@ -452,7 +452,7 @@ bool cmQtAutoGenInitializer::InitUic()
this->Target->GetSafeProperty("AUTOUIC_SEARCH_PATHS");
if (!usp.empty()) {
cmSystemTools::ExpandListArgument(usp, this->Uic.SearchPaths);
std::string const srcDir = makefile->GetCurrentSourceDirectory();
std::string const& srcDir = makefile->GetCurrentSourceDirectory();
for (std::string& path : this->Uic.SearchPaths) {
path = cmSystemTools::CollapseFullPath(path, srcDir);
}

View File

@ -69,7 +69,8 @@ void cmSearchPath::AddUserPath(const std::string& path)
// Process them all from the current directory
for (std::string const& p : outPaths) {
this->AddPathInternal(p, this->FC->Makefile->GetCurrentSourceDirectory());
this->AddPathInternal(
p, this->FC->Makefile->GetCurrentSourceDirectory().c_str());
}
}
@ -83,8 +84,8 @@ void cmSearchPath::AddCMakePath(const std::string& variable)
cmSystemTools::ExpandListArgument(value, expanded);
for (std::string const& p : expanded) {
this->AddPathInternal(p,
this->FC->Makefile->GetCurrentSourceDirectory());
this->AddPathInternal(
p, this->FC->Makefile->GetCurrentSourceDirectory().c_str());
}
}
}
@ -107,8 +108,8 @@ void cmSearchPath::AddCMakePrefixPath(const std::string& variable)
std::vector<std::string> expanded;
cmSystemTools::ExpandListArgument(value, expanded);
this->AddPrefixPaths(expanded,
this->FC->Makefile->GetCurrentSourceDirectory());
this->AddPrefixPaths(
expanded, this->FC->Makefile->GetCurrentSourceDirectory().c_str());
}
}

View File

@ -769,7 +769,7 @@ static Json::Value DumpSourceFilesList(
groupFileList.push_back(file->GetFullPath());
}
const std::string baseDir = target->Makefile->GetCurrentSourceDirectory();
const std::string& baseDir = target->Makefile->GetCurrentSourceDirectory();
Json::Value result = Json::arrayValue;
for (auto const& it : fileGroups) {
Json::Value group = DumpSourceFileGroup(it.first, it.second, baseDir);

View File

@ -132,8 +132,8 @@ bool cmSourceFile::FindFullPath(std::string* error)
cmMakefile const* mf = this->Location.GetMakefile();
const char* tryDirs[3] = { nullptr, nullptr, nullptr };
if (this->Location.DirectoryIsAmbiguous()) {
tryDirs[0] = mf->GetCurrentSourceDirectory();
tryDirs[1] = mf->GetCurrentBinaryDirectory();
tryDirs[0] = mf->GetCurrentSourceDirectory().c_str();
tryDirs[1] = mf->GetCurrentBinaryDirectory().c_str();
} else {
tryDirs[0] = "";
}

View File

@ -205,18 +205,18 @@ bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc)
}
} else if (this->AmbiguousDirectory) {
// Compare possible directory combinations.
std::string const& srcDir = cmSystemTools::CollapseFullPath(
std::string const srcDir = cmSystemTools::CollapseFullPath(
this->Directory, this->Makefile->GetCurrentSourceDirectory());
std::string const& binDir = cmSystemTools::CollapseFullPath(
std::string const binDir = cmSystemTools::CollapseFullPath(
this->Directory, this->Makefile->GetCurrentBinaryDirectory());
if (srcDir != loc.Directory && binDir != loc.Directory) {
return false;
}
} else if (loc.AmbiguousDirectory) {
// Compare possible directory combinations.
std::string const& srcDir = cmSystemTools::CollapseFullPath(
std::string const srcDir = cmSystemTools::CollapseFullPath(
loc.Directory, loc.Makefile->GetCurrentSourceDirectory());
std::string const& binDir = cmSystemTools::CollapseFullPath(
std::string const binDir = cmSystemTools::CollapseFullPath(
loc.Directory, loc.Makefile->GetCurrentBinaryDirectory());
if (srcDir != this->Directory && binDir != this->Directory) {
return false;

View File

@ -30,18 +30,17 @@ bool cmSubdirCommand::InitialPass(std::vector<std::string> const& args,
// if they specified a relative path then compute the full
std::string srcPath =
std::string(this->Makefile->GetCurrentSourceDirectory()) + "/" + i;
this->Makefile->GetCurrentSourceDirectory() + "/" + i;
if (cmSystemTools::FileIsDirectory(srcPath)) {
std::string binPath =
std::string(this->Makefile->GetCurrentBinaryDirectory()) + "/" + i;
this->Makefile->GetCurrentBinaryDirectory() + "/" + i;
this->Makefile->AddSubDirectory(srcPath, binPath, excludeFromAll, false);
}
// otherwise it is a full path
else if (cmSystemTools::FileIsDirectory(i)) {
// we must compute the binPath from the srcPath, we just take the last
// element from the source path and use that
std::string binPath =
std::string(this->Makefile->GetCurrentBinaryDirectory()) + "/" +
std::string binPath = this->Makefile->GetCurrentBinaryDirectory() + "/" +
cmSystemTools::GetFilenameName(i);
this->Makefile->AddSubDirectory(i, binPath, excludeFromAll, false);
} else {

View File

@ -1127,10 +1127,11 @@ void cmTarget::AppendBuildInterfaceIncludes()
this->BuildInterfaceIncludesAppended = true;
if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE")) {
const char* binDir = this->Makefile->GetCurrentBinaryDirectory();
const char* srcDir = this->Makefile->GetCurrentSourceDirectory();
const std::string dirs = std::string(binDir ? binDir : "") +
std::string(binDir ? ";" : "") + std::string(srcDir ? srcDir : "");
std::string dirs = this->Makefile->GetCurrentBinaryDirectory();
if (!dirs.empty()) {
dirs += ';';
}
dirs += this->Makefile->GetCurrentSourceDirectory();
if (!dirs.empty()) {
this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
("$<BUILD_INTERFACE:" + dirs + ">").c_str());

View File

@ -35,8 +35,7 @@ std::string cmTargetIncludeDirectoriesCommand::Join(
{
std::string dirs;
std::string sep;
std::string prefix =
this->Makefile->GetCurrentSourceDirectory() + std::string("/");
std::string prefix = this->Makefile->GetCurrentSourceDirectory() + "/";
for (std::string const& it : content) {
if (cmSystemTools::FileIsFullPath(it) ||
cmGeneratorExpression::Find(it) == 0) {
@ -56,8 +55,7 @@ bool cmTargetIncludeDirectoriesCommand::HandleDirectContent(
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
tgt->InsertInclude(this->Join(content), lfbt, prepend);
if (system) {
std::string prefix =
this->Makefile->GetCurrentSourceDirectory() + std::string("/");
std::string prefix = this->Makefile->GetCurrentSourceDirectory() + "/";
std::set<std::string> sdirs;
for (std::string const& it : content) {
if (cmSystemTools::FileIsFullPath(it) ||

View File

@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmTargetSourcesCommand.h"
#include <cstring>
#include <sstream>
#include "cmAlgorithms.h"
@ -71,8 +70,8 @@ std::vector<std::string> cmTargetSourcesCommand::ConvertToAbsoluteContent(
if (cmSystemTools::FileIsFullPath(src) ||
cmGeneratorExpression::Find(src) == 0 ||
(!isInterfaceContent &&
strcmp(this->Makefile->GetCurrentSourceDirectory(),
tgt->GetMakefile()->GetCurrentSourceDirectory()) == 0)) {
(this->Makefile->GetCurrentSourceDirectory() ==
tgt->GetMakefile()->GetCurrentSourceDirectory()))) {
absoluteSrc = src;
} else {
changedPath = true;

View File

@ -252,9 +252,8 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator(
this->DefaultArtifactDir =
this->LocalGenerator->GetCurrentBinaryDirectory() + std::string("/") +
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
this->InSourceBuild =
(strcmp(this->Makefile->GetCurrentSourceDirectory(),
this->Makefile->GetCurrentBinaryDirectory()) == 0);
this->InSourceBuild = (this->Makefile->GetCurrentSourceDirectory() ==
this->Makefile->GetCurrentBinaryDirectory());
}
cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
@ -722,8 +721,7 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences(Elem& e0)
if (!name.empty()) {
std::string path = i.second.GetValue();
if (!cmsys::SystemTools::FileIsFullPath(path)) {
path = std::string(this->Makefile->GetCurrentSourceDirectory()) +
"/" + path;
path = this->Makefile->GetCurrentSourceDirectory() + "/" + path;
}
ConvertToWindowsSlash(path);
this->DotNetHintReferences[""].push_back(
@ -929,8 +927,10 @@ void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup(Elem& e0)
e2.SetHasElements();
if (this->ProjectType == csproj && !this->InSourceBuild) {
// add <Link> tag to written XAML source if necessary
const std::string srcDir = this->Makefile->GetCurrentSourceDirectory();
const std::string binDir = this->Makefile->GetCurrentBinaryDirectory();
const std::string& srcDir =
this->Makefile->GetCurrentSourceDirectory();
const std::string& binDir =
this->Makefile->GetCurrentBinaryDirectory();
std::string link;
if (obj.find(srcDir) == 0) {
link = obj.substr(srcDir.length() + 1);
@ -4581,7 +4581,7 @@ void cmVisualStudio10TargetGenerator::GetCSharpSourceLink(
std::string const& binaryDir = LocalGenerator->GetCurrentBinaryDirectory();
if (!cmSystemTools::IsSubDirectory(sourceFilePath, binaryDir)) {
const std::string stripFromPath =
const std::string& stripFromPath =
this->Makefile->GetCurrentSourceDirectory();
if (sourceFilePath.find(stripFromPath) == 0) {
if (const char* l = sf->GetProperty("VS_CSHARP_Link")) {