/src/CMake/Source/cmTargetIncludeDirectoriesCommand.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmTargetIncludeDirectoriesCommand.h" |
4 | | |
5 | | #include <set> |
6 | | #include <utility> |
7 | | |
8 | | #include <cm/optional> |
9 | | |
10 | | #include "cmGeneratorExpression.h" |
11 | | #include "cmListFileCache.h" |
12 | | #include "cmMakefile.h" |
13 | | #include "cmMessageType.h" |
14 | | #include "cmStringAlgorithms.h" |
15 | | #include "cmSystemTools.h" |
16 | | #include "cmTarget.h" |
17 | | #include "cmTargetPropCommandBase.h" |
18 | | |
19 | | namespace { |
20 | | |
21 | | class TargetIncludeDirectoriesImpl : public cmTargetPropCommandBase |
22 | | { |
23 | | public: |
24 | | using cmTargetPropCommandBase::cmTargetPropCommandBase; |
25 | | |
26 | | private: |
27 | | void HandleMissingTarget(std::string const& name) override |
28 | 0 | { |
29 | 0 | this->Makefile->IssueMessage( |
30 | 0 | MessageType::FATAL_ERROR, |
31 | 0 | cmStrCat("Cannot specify include directories for target \"", name, |
32 | 0 | "\" which is not built by this project.")); |
33 | 0 | } |
34 | | |
35 | | bool HandleDirectContent(cmTarget* tgt, |
36 | | std::vector<std::string> const& content, |
37 | | bool prepend, bool system) override; |
38 | | |
39 | | void HandleInterfaceContent(cmTarget* tgt, |
40 | | std::vector<std::string> const& content, |
41 | | bool prepend, bool system) override; |
42 | | |
43 | | std::string Join(std::vector<std::string> const& content) override; |
44 | | }; |
45 | | |
46 | | std::string TargetIncludeDirectoriesImpl::Join( |
47 | | std::vector<std::string> const& content) |
48 | 5.92k | { |
49 | 5.92k | std::string dirs; |
50 | 5.92k | std::string sep; |
51 | 5.92k | std::string prefix = this->Makefile->GetCurrentSourceDirectory() + "/"; |
52 | 11.8k | for (std::string const& it : content) { |
53 | 11.8k | if (cmSystemTools::FileIsFullPath(it) || |
54 | 11.8k | cmGeneratorExpression::Find(it) == 0) { |
55 | 11.8k | dirs = cmStrCat(std::move(dirs), sep, it); |
56 | 11.8k | } else { |
57 | 0 | dirs = cmStrCat(std::move(dirs), sep, prefix, it); |
58 | 0 | } |
59 | 11.8k | sep = ";"; |
60 | 11.8k | } |
61 | 5.92k | return dirs; |
62 | 5.92k | } |
63 | | |
64 | | bool TargetIncludeDirectoriesImpl::HandleDirectContent( |
65 | | cmTarget* tgt, std::vector<std::string> const& content, bool prepend, |
66 | | bool system) |
67 | 0 | { |
68 | 0 | cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); |
69 | 0 | tgt->InsertInclude(BT<std::string>(this->Join(content), lfbt), prepend); |
70 | 0 | if (system) { |
71 | 0 | std::string prefix = this->Makefile->GetCurrentSourceDirectory() + "/"; |
72 | 0 | std::set<std::string> sdirs; |
73 | 0 | for (std::string const& it : content) { |
74 | 0 | if (cmSystemTools::FileIsFullPath(it) || |
75 | 0 | cmGeneratorExpression::Find(it) == 0) { |
76 | 0 | sdirs.insert(it); |
77 | 0 | } else { |
78 | 0 | sdirs.insert(prefix + it); |
79 | 0 | } |
80 | 0 | } |
81 | 0 | tgt->AddSystemIncludeDirectories(sdirs); |
82 | 0 | } |
83 | 0 | return true; // Successfully handled. |
84 | 0 | } |
85 | | |
86 | | void TargetIncludeDirectoriesImpl::HandleInterfaceContent( |
87 | | cmTarget* tgt, std::vector<std::string> const& content, bool prepend, |
88 | | bool system) |
89 | 5.92k | { |
90 | 5.92k | this->cmTargetPropCommandBase::HandleInterfaceContent(tgt, content, prepend, |
91 | 5.92k | system); |
92 | 5.92k | if (system) { |
93 | 0 | std::string joined = this->Join(content); |
94 | 0 | tgt->AppendProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", joined, |
95 | 0 | this->Makefile->GetBacktrace()); |
96 | 0 | } |
97 | 5.92k | } |
98 | | |
99 | | } // namespace |
100 | | |
101 | | bool cmTargetIncludeDirectoriesCommand(std::vector<std::string> const& args, |
102 | | cmExecutionStatus& status) |
103 | 5.92k | { |
104 | 5.92k | return TargetIncludeDirectoriesImpl(status).HandleArguments( |
105 | 5.92k | args, "INCLUDE_DIRECTORIES", |
106 | 5.92k | TargetIncludeDirectoriesImpl::PROCESS_BEFORE | |
107 | 5.92k | TargetIncludeDirectoriesImpl::PROCESS_AFTER | |
108 | 5.92k | TargetIncludeDirectoriesImpl::PROCESS_SYSTEM); |
109 | 5.92k | } |