cmIncludeDirectoryCommand: Port away from cmCommand
This commit is contained in:
parent
fdc3ba4583
commit
d038beec21
@ -231,8 +231,7 @@ void GetProjectCommands(cmState* state)
|
||||
cmGetSourceFilePropertyCommand);
|
||||
state->AddBuiltinCommand("get_target_property", cmGetTargetPropertyCommand);
|
||||
state->AddBuiltinCommand("get_test_property", cmGetTestPropertyCommand);
|
||||
state->AddBuiltinCommand("include_directories",
|
||||
cm::make_unique<cmIncludeDirectoryCommand>());
|
||||
state->AddBuiltinCommand("include_directories", cmIncludeDirectoryCommand);
|
||||
state->AddBuiltinCommand("include_regular_expression",
|
||||
cmIncludeRegularExpressionCommand);
|
||||
state->AddBuiltinCommand("install", cm::make_unique<cmInstallCommand>());
|
||||
|
@ -7,24 +7,28 @@
|
||||
#include <utility>
|
||||
|
||||
#include "cmAlgorithms.h"
|
||||
#include "cmExecutionStatus.h"
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
static void GetIncludes(cmMakefile& mf, const std::string& arg,
|
||||
std::vector<std::string>& incs);
|
||||
static void NormalizeInclude(cmMakefile& mf, std::string& inc);
|
||||
|
||||
// cmIncludeDirectoryCommand
|
||||
bool cmIncludeDirectoryCommand::InitialPass(
|
||||
std::vector<std::string> const& args, cmExecutionStatus&)
|
||||
bool cmIncludeDirectoryCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
{
|
||||
if (args.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
cmMakefile& mf = status.GetMakefile();
|
||||
|
||||
auto i = args.begin();
|
||||
|
||||
bool before = this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_BEFORE");
|
||||
bool before = mf.IsOn("CMAKE_INCLUDE_DIRECTORIES_BEFORE");
|
||||
bool system = false;
|
||||
|
||||
if ((*i) == "BEFORE") {
|
||||
@ -45,13 +49,13 @@ bool cmIncludeDirectoryCommand::InitialPass(
|
||||
continue;
|
||||
}
|
||||
if (i->empty()) {
|
||||
this->SetError("given empty-string as include directory.");
|
||||
status.SetError("given empty-string as include directory.");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string> includes;
|
||||
|
||||
this->GetIncludes(*i, includes);
|
||||
GetIncludes(mf, *i, includes);
|
||||
|
||||
if (before) {
|
||||
cmAppend(beforeIncludes, includes);
|
||||
@ -64,9 +68,9 @@ bool cmIncludeDirectoryCommand::InitialPass(
|
||||
}
|
||||
std::reverse(beforeIncludes.begin(), beforeIncludes.end());
|
||||
|
||||
this->Makefile->AddIncludeDirectories(afterIncludes);
|
||||
this->Makefile->AddIncludeDirectories(beforeIncludes, before);
|
||||
this->Makefile->AddSystemIncludeDirectories(systemIncludes);
|
||||
mf.AddIncludeDirectories(afterIncludes);
|
||||
mf.AddIncludeDirectories(beforeIncludes, before);
|
||||
mf.AddSystemIncludeDirectories(systemIncludes);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -83,8 +87,8 @@ bool cmIncludeDirectoryCommand::InitialPass(
|
||||
// output from a program and passing it into a command the cleanup doesn't
|
||||
// always happen
|
||||
//
|
||||
void cmIncludeDirectoryCommand::GetIncludes(const std::string& arg,
|
||||
std::vector<std::string>& incs)
|
||||
static void GetIncludes(cmMakefile& mf, const std::string& arg,
|
||||
std::vector<std::string>& incs)
|
||||
{
|
||||
// break apart any line feed arguments
|
||||
std::string::size_type pos = 0;
|
||||
@ -92,7 +96,7 @@ void cmIncludeDirectoryCommand::GetIncludes(const std::string& arg,
|
||||
while ((pos = arg.find('\n', lastPos)) != std::string::npos) {
|
||||
if (pos) {
|
||||
std::string inc = arg.substr(lastPos, pos);
|
||||
this->NormalizeInclude(inc);
|
||||
NormalizeInclude(mf, inc);
|
||||
if (!inc.empty()) {
|
||||
incs.push_back(std::move(inc));
|
||||
}
|
||||
@ -100,13 +104,13 @@ void cmIncludeDirectoryCommand::GetIncludes(const std::string& arg,
|
||||
lastPos = pos + 1;
|
||||
}
|
||||
std::string inc = arg.substr(lastPos);
|
||||
this->NormalizeInclude(inc);
|
||||
NormalizeInclude(mf, inc);
|
||||
if (!inc.empty()) {
|
||||
incs.push_back(std::move(inc));
|
||||
}
|
||||
}
|
||||
|
||||
void cmIncludeDirectoryCommand::NormalizeInclude(std::string& inc)
|
||||
static void NormalizeInclude(cmMakefile& mf, std::string& inc)
|
||||
{
|
||||
std::string::size_type b = inc.find_first_not_of(" \r");
|
||||
std::string::size_type e = inc.find_last_not_of(" \r");
|
||||
@ -119,13 +123,9 @@ void cmIncludeDirectoryCommand::NormalizeInclude(std::string& inc)
|
||||
|
||||
if (!cmIsOff(inc)) {
|
||||
cmSystemTools::ConvertToUnixSlashes(inc);
|
||||
|
||||
if (!cmSystemTools::FileIsFullPath(inc)) {
|
||||
if (!cmGeneratorExpression::StartsWithGeneratorExpression(inc)) {
|
||||
std::string tmp =
|
||||
cmStrCat(this->Makefile->GetCurrentSourceDirectory(), '/', inc);
|
||||
inc = tmp;
|
||||
}
|
||||
if (!cmSystemTools::FileIsFullPath(inc) &&
|
||||
!cmGeneratorExpression::StartsWithGeneratorExpression(inc)) {
|
||||
inc = cmStrCat(mf.GetCurrentSourceDirectory(), '/', inc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,40 +8,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/memory>
|
||||
|
||||
#include "cmCommand.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
|
||||
/** \class cmIncludeDirectoryCommand
|
||||
* \brief Add include directories to the build.
|
||||
*
|
||||
* cmIncludeDirectoryCommand is used to specify directory locations
|
||||
* to search for included files.
|
||||
*/
|
||||
class cmIncludeDirectoryCommand : public cmCommand
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This is a virtual constructor for the command.
|
||||
*/
|
||||
std::unique_ptr<cmCommand> Clone() override
|
||||
{
|
||||
return cm::make_unique<cmIncludeDirectoryCommand>();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the command is first encountered in
|
||||
* the CMakeLists.txt file.
|
||||
*/
|
||||
bool InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status) override;
|
||||
|
||||
protected:
|
||||
// used internally
|
||||
void GetIncludes(const std::string& arg, std::vector<std::string>& incs);
|
||||
void NormalizeInclude(std::string& inc);
|
||||
};
|
||||
bool cmIncludeDirectoryCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user