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