From d038beec21fde74977e6ce6604f7fc913066dad6 Mon Sep 17 00:00:00 2001 From: Regina Pfeifer Date: Wed, 18 Sep 2019 17:31:38 +0200 Subject: cmIncludeDirectoryCommand: Port away from cmCommand --- Source/cmCommands.cxx | 3 +-- Source/cmIncludeDirectoryCommand.cxx | 44 ++++++++++++++++++------------------ Source/cmIncludeDirectoryCommand.h | 35 ++-------------------------- 3 files changed, 25 insertions(+), 57 deletions(-) diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index f569c2b..a8a77c2 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -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()); + state->AddBuiltinCommand("include_directories", cmIncludeDirectoryCommand); state->AddBuiltinCommand("include_regular_expression", cmIncludeRegularExpressionCommand); state->AddBuiltinCommand("install", cm::make_unique()); diff --git a/Source/cmIncludeDirectoryCommand.cxx b/Source/cmIncludeDirectoryCommand.cxx index a4d0a0d..170aea1 100644 --- a/Source/cmIncludeDirectoryCommand.cxx +++ b/Source/cmIncludeDirectoryCommand.cxx @@ -7,24 +7,28 @@ #include #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& incs); +static void NormalizeInclude(cmMakefile& mf, std::string& inc); -// cmIncludeDirectoryCommand -bool cmIncludeDirectoryCommand::InitialPass( - std::vector const& args, cmExecutionStatus&) +bool cmIncludeDirectoryCommand(std::vector 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 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& incs) +static void GetIncludes(cmMakefile& mf, const std::string& arg, + std::vector& 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); } } } diff --git a/Source/cmIncludeDirectoryCommand.h b/Source/cmIncludeDirectoryCommand.h index bcaae9d..66caff7 100644 --- a/Source/cmIncludeDirectoryCommand.h +++ b/Source/cmIncludeDirectoryCommand.h @@ -8,40 +8,9 @@ #include #include -#include - -#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 Clone() override - { - return cm::make_unique(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector const& args, - cmExecutionStatus& status) override; - -protected: - // used internally - void GetIncludes(const std::string& arg, std::vector& incs); - void NormalizeInclude(std::string& inc); -}; +bool cmIncludeDirectoryCommand(std::vector const& args, + cmExecutionStatus& status); #endif -- cgit v0.12