1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-19 02:17:27 +08:00

cmComputeLinkInformation: modernize memory management

This commit is contained in:
Marc Chevrier
2020-01-26 14:01:45 +01:00
parent 55ea8f6b1b
commit b50b2755da
2 changed files with 15 additions and 15 deletions

View File

@@ -8,6 +8,8 @@
#include <sstream> #include <sstream>
#include <utility> #include <utility>
#include <cm/memory>
#include "cmAlgorithms.h" #include "cmAlgorithms.h"
#include "cmComputeLinkDepends.h" #include "cmComputeLinkDepends.h"
#include "cmGeneratorTarget.h" #include "cmGeneratorTarget.h"
@@ -256,11 +258,10 @@ cmComputeLinkInformation::cmComputeLinkInformation(
"FIND_LIBRARY_USE_OPENBSD_VERSIONING"); "FIND_LIBRARY_USE_OPENBSD_VERSIONING");
// Allocate internals. // Allocate internals.
this->OrderLinkerSearchPath = new cmOrderDirectories( this->OrderLinkerSearchPath = cm::make_unique<cmOrderDirectories>(
this->GlobalGenerator, target, "linker search path"); this->GlobalGenerator, target, "linker search path");
this->OrderRuntimeSearchPath = new cmOrderDirectories( this->OrderRuntimeSearchPath = cm::make_unique<cmOrderDirectories>(
this->GlobalGenerator, target, "runtime search path"); this->GlobalGenerator, target, "runtime search path");
this->OrderDependentRPath = nullptr;
// Get the language used for linking this target. // Get the language used for linking this target.
this->LinkLanguage = this->Target->GetLinkerLanguage(config); this->LinkLanguage = this->Target->GetLinkerLanguage(config);
@@ -358,7 +359,7 @@ cmComputeLinkInformation::cmComputeLinkInformation(
this->SharedDependencyMode = SharedDepModeLibDir; this->SharedDependencyMode = SharedDepModeLibDir;
} else if (!this->RPathLinkFlag.empty()) { } else if (!this->RPathLinkFlag.empty()) {
this->SharedDependencyMode = SharedDepModeDir; this->SharedDependencyMode = SharedDepModeDir;
this->OrderDependentRPath = new cmOrderDirectories( this->OrderDependentRPath = cm::make_unique<cmOrderDirectories>(
this->GlobalGenerator, target, "dependent library path"); this->GlobalGenerator, target, "dependent library path");
} }
@@ -400,12 +401,7 @@ cmComputeLinkInformation::cmComputeLinkInformation(
"CMAKE_POLICY_WARNING_CMP0060"); "CMAKE_POLICY_WARNING_CMP0060");
} }
cmComputeLinkInformation::~cmComputeLinkInformation() cmComputeLinkInformation::~cmComputeLinkInformation() = default;
{
delete this->OrderLinkerSearchPath;
delete this->OrderRuntimeSearchPath;
delete this->OrderDependentRPath;
}
void cmComputeLinkInformation::AppendValues( void cmComputeLinkInformation::AppendValues(
std::string& result, std::vector<BT<std::string>>& values) std::string& result, std::vector<BT<std::string>>& values)
@@ -747,10 +743,10 @@ void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
if (this->SharedDependencyMode == SharedDepModeLibDir && if (this->SharedDependencyMode == SharedDepModeLibDir &&
!this->LinkWithRuntimePath /* AddLibraryRuntimeInfo adds it */) { !this->LinkWithRuntimePath /* AddLibraryRuntimeInfo adds it */) {
// Add the item to the linker search path. // Add the item to the linker search path.
order = this->OrderLinkerSearchPath; order = this->OrderLinkerSearchPath.get();
} else if (this->SharedDependencyMode == SharedDepModeDir) { } else if (this->SharedDependencyMode == SharedDepModeDir) {
// Add the item to the separate dependent library search path. // Add the item to the separate dependent library search path.
order = this->OrderDependentRPath; order = this->OrderDependentRPath.get();
} }
if (order) { if (order) {
if (tgt) { if (tgt) {

View File

@@ -6,6 +6,7 @@
#include "cmConfigure.h" // IWYU pragma: keep #include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd> #include <iosfwd>
#include <memory>
#include <set> #include <set>
#include <string> #include <string>
#include <utility> #include <utility>
@@ -29,6 +30,9 @@ class cmComputeLinkInformation
public: public:
cmComputeLinkInformation(cmGeneratorTarget const* target, cmComputeLinkInformation(cmGeneratorTarget const* target,
const std::string& config); const std::string& config);
cmComputeLinkInformation(const cmComputeLinkInformation&) = delete;
cmComputeLinkInformation& operator=(const cmComputeLinkInformation&) =
delete;
~cmComputeLinkInformation(); ~cmComputeLinkInformation();
bool Compute(); bool Compute();
@@ -164,7 +168,7 @@ private:
cmsys::RegularExpression SplitFramework; cmsys::RegularExpression SplitFramework;
// Linker search path computation. // Linker search path computation.
cmOrderDirectories* OrderLinkerSearchPath; std::unique_ptr<cmOrderDirectories> OrderLinkerSearchPath;
bool FinishLinkerSearchDirectories(); bool FinishLinkerSearchDirectories();
void PrintLinkPolicyDiagnosis(std::ostream&); void PrintLinkPolicyDiagnosis(std::ostream&);
@@ -184,9 +188,9 @@ private:
std::vector<std::string> OldUserFlagItems; std::vector<std::string> OldUserFlagItems;
std::set<std::string> CMP0060WarnItems; std::set<std::string> CMP0060WarnItems;
// Dependent library path computation. // Dependent library path computation.
cmOrderDirectories* OrderDependentRPath; std::unique_ptr<cmOrderDirectories> OrderDependentRPath;
// Runtime path computation. // Runtime path computation.
cmOrderDirectories* OrderRuntimeSearchPath; std::unique_ptr<cmOrderDirectories> OrderRuntimeSearchPath;
bool OldLinkDirMode; bool OldLinkDirMode;
bool OpenBSD; bool OpenBSD;