cmake/Source/cmTargetIncludeDirectoriesCommand.cxx

98 lines
2.8 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2013-03-16 19:13:01 +02:00
#include "cmTargetIncludeDirectoriesCommand.h"
2017-04-14 19:02:05 +02:00
#include <set>
#include <sstream>
2014-08-03 19:52:23 +02:00
#include "cmGeneratorExpression.h"
2017-04-14 19:02:05 +02:00
#include "cmListFileCache.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmake.h"
class cmExecutionStatus;
2014-08-03 19:52:23 +02:00
2016-07-09 11:21:54 +02:00
bool cmTargetIncludeDirectoriesCommand::InitialPass(
std::vector<std::string> const& args, cmExecutionStatus&)
2013-03-16 19:13:01 +02:00
{
2013-11-03 12:27:13 +02:00
return this->HandleArguments(args, "INCLUDE_DIRECTORIES",
ArgumentFlags(PROCESS_BEFORE | PROCESS_SYSTEM));
2013-03-16 19:13:01 +02:00
}
2016-07-09 11:21:54 +02:00
void cmTargetIncludeDirectoriesCommand::HandleImportedTarget(
const std::string& tgt)
2013-03-16 19:13:01 +02:00
{
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2016-07-09 11:21:54 +02:00
e << "Cannot specify include directories for imported target \"" << tgt
<< "\".";
2013-03-16 19:13:01 +02:00
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
}
2016-07-09 11:21:54 +02:00
void cmTargetIncludeDirectoriesCommand::HandleMissingTarget(
const std::string& name)
2013-03-16 19:13:01 +02:00
{
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2016-07-09 11:21:54 +02:00
e << "Cannot specify include directories for target \"" << name
<< "\" "
2013-03-16 19:13:01 +02:00
"which is not built by this project.";
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
}
2016-07-09 11:21:54 +02:00
std::string cmTargetIncludeDirectoriesCommand::Join(
const std::vector<std::string>& content)
2013-03-16 19:13:01 +02:00
{
std::string dirs;
std::string sep;
2015-08-17 11:37:30 +02:00
std::string prefix =
2016-07-09 11:21:54 +02:00
this->Makefile->GetCurrentSourceDirectory() + std::string("/");
2018-01-26 17:06:56 +01:00
for (std::string const& it : content) {
if (cmSystemTools::FileIsFullPath(it.c_str()) ||
cmGeneratorExpression::Find(it) == 0) {
dirs += sep + it;
2016-07-09 11:21:54 +02:00
} else {
2018-01-26 17:06:56 +01:00
dirs += sep + prefix + it;
2013-03-16 19:13:01 +02:00
}
2016-07-09 11:21:54 +02:00
sep = ";";
}
2013-03-16 19:13:01 +02:00
return dirs;
}
2016-07-09 11:21:54 +02:00
bool cmTargetIncludeDirectoriesCommand::HandleDirectContent(
cmTarget* tgt, const std::vector<std::string>& content, bool prepend,
bool system)
2013-03-16 19:13:01 +02:00
{
2015-04-27 22:25:09 +02:00
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
2015-11-17 17:22:37 +01:00
tgt->InsertInclude(this->Join(content), lfbt, prepend);
2016-07-09 11:21:54 +02:00
if (system) {
2015-11-17 17:22:37 +01:00
std::string prefix =
this->Makefile->GetCurrentSourceDirectory() + std::string("/");
std::set<std::string> sdirs;
2018-01-26 17:06:56 +01:00
for (std::string const& it : content) {
if (cmSystemTools::FileIsFullPath(it.c_str()) ||
cmGeneratorExpression::Find(it) == 0) {
sdirs.insert(it);
2016-07-09 11:21:54 +02:00
} else {
2018-01-26 17:06:56 +01:00
sdirs.insert(prefix + it);
2015-11-17 17:22:37 +01:00
}
2013-11-03 12:27:13 +02:00
}
2016-07-09 11:21:54 +02:00
tgt->AddSystemIncludeDirectories(sdirs);
}
2015-04-27 22:25:09 +02:00
return true;
2013-11-03 12:27:13 +02:00
}
2016-07-09 11:21:54 +02:00
void cmTargetIncludeDirectoriesCommand::HandleInterfaceContent(
cmTarget* tgt, const std::vector<std::string>& content, bool prepend,
bool system)
2013-11-03 12:27:13 +02:00
{
2016-07-09 11:21:54 +02:00
cmTargetPropCommandBase::HandleInterfaceContent(tgt, content, prepend,
system);
2013-11-03 12:27:13 +02:00
2016-07-09 11:21:54 +02:00
if (system) {
2015-11-17 17:22:37 +01:00
std::string joined = this->Join(content);
2013-11-03 12:27:13 +02:00
tgt->AppendProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES",
joined.c_str());
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
}