Reduce raw string pointers usage.

* Change some functions to take `std::string` instead of
  `const char*` in the following classes: `cmMakeFile`, `cmake`,
  `cmCoreTryCompile`, `cmSystemTools`,  `cmState`, `cmLocalGenerator`
  and a few others.
* Greatly reduce using of `const char*` overloads for
  `cmSystemTools::MakeDirectory` and `cmSystemTools::RelativePath`.
* Remove many redundant `c_str()` conversions throughout the code.
This commit is contained in:
Pavel Solodovnikov
2018-01-31 18:20:02 +03:00
parent 4499cc8bb6
commit 653b894683
120 changed files with 471 additions and 507 deletions

View File

@@ -5,7 +5,6 @@
#include <map>
#include <ostream>
#include <set>
#include <string.h>
#include <utility>
#include "cmAlgorithms.h"
@@ -225,7 +224,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
}
const std::string& relative = cmSystemTools::RelativePath(
it.second[0]->GetSourceDirectory(), listFile.c_str());
it.second[0]->GetSourceDirectory(), listFile);
std::vector<std::string> splitted;
cmSystemTools::SplitPath(relative, splitted, false);
// Split filename from path
@@ -296,8 +295,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
case cmStateEnums::GLOBAL_TARGET: {
// Only add the global targets from CMAKE_BINARY_DIR,
// not from the subdirs
if (strcmp(lg->GetCurrentBinaryDirectory(),
lg->GetBinaryDirectory()) == 0) {
if (lg->GetCurrentBinaryDirectory() == lg->GetBinaryDirectory()) {
this->AppendTarget(xml, targetName, nullptr, make.c_str(), lg,
compiler.c_str(), makeArgs);
}
@@ -382,12 +380,12 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
std::string const& fullPath = s->GetFullPath();
// Check file position relative to project root dir.
const std::string& relative = cmSystemTools::RelativePath(
(*lg).GetSourceDirectory(), fullPath.c_str());
const std::string& relative =
cmSystemTools::RelativePath(lg->GetSourceDirectory(), fullPath);
// Do not add this file if it has ".." in relative path and
// if CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES variable is on.
const bool excludeExternal =
cmSystemTools::IsOn((*lg).GetMakefile()->GetSafeDefinition(
cmSystemTools::IsOn(lg->GetMakefile()->GetSafeDefinition(
"CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES"));
if (excludeExternal &&
(relative.find("..") != std::string::npos)) {
@@ -433,7 +431,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
break;
}
if (cmSystemTools::FileExists(hname.c_str())) {
if (cmSystemTools::FileExists(hname)) {
allFiles[hname].Targets = allFiles[fileName].Targets;
break;
}