cmake/Source/cmTargetIncludeDirectoriesCommand.cxx

99 lines
3.2 KiB
C++
Raw Normal View History

2013-03-16 19:13:01 +02:00
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2013 Stephen Kelly <steveire@gmail.com>
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "cmTargetIncludeDirectoriesCommand.h"
2014-08-03 19:52:23 +02:00
#include "cmGeneratorExpression.h"
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("/");
for (std::vector<std::string>::const_iterator it = content.begin();
it != content.end(); ++it) {
if (cmSystemTools::FileIsFullPath(it->c_str()) ||
cmGeneratorExpression::Find(*it) == 0) {
2013-03-16 19:13:01 +02:00
dirs += sep + *it;
2016-07-09 11:21:54 +02:00
} else {
2013-03-16 19:13:01 +02:00
dirs += sep + prefix + *it;
}
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;
for (std::vector<std::string>::const_iterator it = content.begin();
2016-07-09 11:21:54 +02:00
it != content.end(); ++it) {
if (cmSystemTools::FileIsFullPath(it->c_str()) ||
cmGeneratorExpression::Find(*it) == 0) {
2015-11-17 17:22:37 +01:00
sdirs.insert(*it);
2016-07-09 11:21:54 +02:00
} else {
2015-11-17 17:22:37 +01:00
sdirs.insert(prefix + *it);
}
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
}