1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmTargetIncludeDirectoriesCommand.h"
7 #include "cmGeneratorExpression.h"
8 #include "cmListFileCache.h"
9 #include "cmMakefile.h"
10 #include "cmMessageType.h"
11 #include "cmStringAlgorithms.h"
12 #include "cmSystemTools.h"
14 #include "cmTargetPropCommandBase.h"
18 class TargetIncludeDirectoriesImpl : public cmTargetPropCommandBase
21 using cmTargetPropCommandBase::cmTargetPropCommandBase;
24 void HandleMissingTarget(const std::string& name) override
26 this->Makefile->IssueMessage(
27 MessageType::FATAL_ERROR,
28 cmStrCat("Cannot specify include directories for target \"", name,
29 "\" which is not built by this project."));
32 bool HandleDirectContent(cmTarget* tgt,
33 const std::vector<std::string>& content,
34 bool prepend, bool system) override;
36 void HandleInterfaceContent(cmTarget* tgt,
37 const std::vector<std::string>& content,
38 bool prepend, bool system) override;
40 std::string Join(const std::vector<std::string>& content) override;
43 std::string TargetIncludeDirectoriesImpl::Join(
44 const std::vector<std::string>& content)
48 std::string prefix = this->Makefile->GetCurrentSourceDirectory() + "/";
49 for (std::string const& it : content) {
50 if (cmSystemTools::FileIsFullPath(it) ||
51 cmGeneratorExpression::Find(it) == 0) {
52 dirs += cmStrCat(sep, it);
54 dirs += cmStrCat(sep, prefix, it);
61 bool TargetIncludeDirectoriesImpl::HandleDirectContent(
62 cmTarget* tgt, const std::vector<std::string>& content, bool prepend,
65 cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
66 tgt->InsertInclude(BT<std::string>(this->Join(content), lfbt), prepend);
68 std::string prefix = this->Makefile->GetCurrentSourceDirectory() + "/";
69 std::set<std::string> sdirs;
70 for (std::string const& it : content) {
71 if (cmSystemTools::FileIsFullPath(it) ||
72 cmGeneratorExpression::Find(it) == 0) {
75 sdirs.insert(prefix + it);
78 tgt->AddSystemIncludeDirectories(sdirs);
80 return true; // Successfully handled.
83 void TargetIncludeDirectoriesImpl::HandleInterfaceContent(
84 cmTarget* tgt, const std::vector<std::string>& content, bool prepend,
87 this->cmTargetPropCommandBase::HandleInterfaceContent(tgt, content, prepend,
90 std::string joined = this->Join(content);
91 tgt->AppendProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", joined,
92 this->Makefile->GetBacktrace());
98 bool cmTargetIncludeDirectoriesCommand(std::vector<std::string> const& args,
99 cmExecutionStatus& status)
101 return TargetIncludeDirectoriesImpl(status).HandleArguments(
102 args, "INCLUDE_DIRECTORIES",
103 static_cast<TargetIncludeDirectoriesImpl::ArgumentFlags>(
104 TargetIncludeDirectoriesImpl::PROCESS_BEFORE |
105 TargetIncludeDirectoriesImpl::PROCESS_AFTER |
106 TargetIncludeDirectoriesImpl::PROCESS_SYSTEM));