/src/CMake/Source/cmTargetCompileDefinitionsCommand.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 "cmTargetCompileDefinitionsCommand.h" |
4 | | |
5 | | #include <cm/optional> |
6 | | |
7 | | #include "cmListFileCache.h" |
8 | | #include "cmMakefile.h" |
9 | | #include "cmMessageType.h" |
10 | | #include "cmStringAlgorithms.h" |
11 | | #include "cmTarget.h" |
12 | | #include "cmTargetPropCommandBase.h" |
13 | | |
14 | | namespace { |
15 | | |
16 | | class TargetCompileDefinitionsImpl : public cmTargetPropCommandBase |
17 | | { |
18 | | public: |
19 | | using cmTargetPropCommandBase::cmTargetPropCommandBase; |
20 | | |
21 | | private: |
22 | | void HandleMissingTarget(std::string const& name) override |
23 | 0 | { |
24 | 0 | this->Makefile->IssueMessage( |
25 | 0 | MessageType::FATAL_ERROR, |
26 | 0 | cmStrCat("Cannot specify compile definitions for target \"", name, |
27 | 0 | "\" which is not built by this project.")); |
28 | 0 | } |
29 | | |
30 | | bool HandleDirectContent(cmTarget* tgt, |
31 | | std::vector<std::string> const& content, |
32 | | bool /*prepend*/, bool /*system*/) override |
33 | 0 | { |
34 | 0 | tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content), |
35 | 0 | this->Makefile->GetBacktrace()); |
36 | 0 | return true; // Successfully handled. |
37 | 0 | } |
38 | | |
39 | | std::string Join(std::vector<std::string> const& content) override |
40 | 0 | { |
41 | 0 | std::string defs; |
42 | 0 | std::string sep; |
43 | 0 | for (std::string const& it : content) { |
44 | 0 | if (cmHasLiteralPrefix(it, "-D")) { |
45 | 0 | defs += sep + it.substr(2); |
46 | 0 | } else { |
47 | 0 | defs += sep + it; |
48 | 0 | } |
49 | 0 | sep = ";"; |
50 | 0 | } |
51 | 0 | return defs; |
52 | 0 | } |
53 | | }; |
54 | | |
55 | | } // namespace |
56 | | |
57 | | bool cmTargetCompileDefinitionsCommand(std::vector<std::string> const& args, |
58 | | cmExecutionStatus& status) |
59 | 0 | { |
60 | 0 | return TargetCompileDefinitionsImpl(status).HandleArguments( |
61 | 0 | args, "COMPILE_DEFINITIONS"); |
62 | 0 | } |