mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-04 21:00:17 -06:00
cmObjectLocation: add a class to track object locations
With the feature to use a shorter path for the build tree, the install tree may still want to use a longer path.
This commit is contained in:
@@ -401,6 +401,8 @@ add_library(
|
||||
cmMSVC60LinkLineComputer.h
|
||||
cmOSXBundleGenerator.cxx
|
||||
cmOSXBundleGenerator.h
|
||||
cmObjectLocation.cxx
|
||||
cmObjectLocation.h
|
||||
cmOutputConverter.cxx
|
||||
cmOutputConverter.h
|
||||
cmNewLineStyle.h
|
||||
|
||||
47
Source/cmObjectLocation.cxx
Normal file
47
Source/cmObjectLocation.cxx
Normal file
@@ -0,0 +1,47 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file LICENSE.rst or https://cmake.org/licensing for details. */
|
||||
|
||||
#include "cmObjectLocation.h"
|
||||
|
||||
void cmObjectLocation::Update(std::string path)
|
||||
{
|
||||
this->Path = std::move(path);
|
||||
}
|
||||
|
||||
std::string const& cmObjectLocation::GetPath() const
|
||||
{
|
||||
return this->Path;
|
||||
}
|
||||
|
||||
cm::string_view cmObjectLocation::GetDirectory() const
|
||||
{
|
||||
auto const pos = this->Path.rfind('/');
|
||||
if (pos == std::string::npos) {
|
||||
return {};
|
||||
}
|
||||
return cm::string_view(this->Path.c_str(), pos);
|
||||
}
|
||||
|
||||
cm::string_view cmObjectLocation::GetName() const
|
||||
{
|
||||
auto const pos = this->Path.rfind('/');
|
||||
if (pos == std::string::npos) {
|
||||
return this->Path;
|
||||
}
|
||||
auto const nameStart = pos + 1;
|
||||
return cm::string_view(this->Path.c_str() + nameStart,
|
||||
this->Path.size() - nameStart);
|
||||
}
|
||||
|
||||
cmObjectLocation const& cmObjectLocations::GetLocation(UseShortPath use) const
|
||||
{
|
||||
if (use == UseShortPath::Yes && this->ShortLoc) {
|
||||
return *this->ShortLoc;
|
||||
}
|
||||
return this->LongLoc;
|
||||
}
|
||||
|
||||
std::string const& cmObjectLocations::GetPath(UseShortPath use) const
|
||||
{
|
||||
return this->GetLocation(use).GetPath();
|
||||
}
|
||||
50
Source/cmObjectLocation.h
Normal file
50
Source/cmObjectLocation.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file LICENSE.rst or https://cmake.org/licensing for details. */
|
||||
#pragma once
|
||||
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <cm/optional>
|
||||
#include <cm/string_view>
|
||||
|
||||
struct cmObjectLocation
|
||||
{
|
||||
public:
|
||||
cmObjectLocation() = default;
|
||||
cmObjectLocation(std::string path)
|
||||
: Path(std::move(path))
|
||||
{
|
||||
}
|
||||
|
||||
void Update(std::string path);
|
||||
|
||||
// Get the path to the object under the common directory for the target's
|
||||
// objects.
|
||||
std::string const& GetPath() const;
|
||||
// Get the directory of the object file under the common directory.
|
||||
cm::string_view GetDirectory() const;
|
||||
// Get the name of the object file.
|
||||
cm::string_view GetName() const;
|
||||
|
||||
private:
|
||||
std::string Path;
|
||||
};
|
||||
|
||||
struct cmObjectLocations
|
||||
{
|
||||
cmObjectLocations() = default;
|
||||
|
||||
cm::optional<cmObjectLocation> ShortLoc;
|
||||
cmObjectLocation LongLoc;
|
||||
|
||||
enum class UseShortPath
|
||||
{
|
||||
Yes,
|
||||
No,
|
||||
};
|
||||
cmObjectLocation const& GetLocation(UseShortPath use) const;
|
||||
std::string const& GetPath(UseShortPath use) const;
|
||||
};
|
||||
Reference in New Issue
Block a user