/src/CMake/Source/cmTargetCompileOptionsCommand.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 "cmTargetCompileOptionsCommand.h" |
4 | | |
5 | | #include "cmList.h" |
6 | | #include "cmListFileCache.h" |
7 | | #include "cmMakefile.h" |
8 | | #include "cmMessageType.h" |
9 | | #include "cmPolicies.h" |
10 | | #include "cmStringAlgorithms.h" |
11 | | #include "cmTarget.h" |
12 | | #include "cmTargetPropCommandBase.h" |
13 | | |
14 | | namespace { |
15 | | |
16 | | class TargetCompileOptionsImpl : 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 options 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 | cmPolicies::PolicyStatus policyStatus = |
35 | 0 | this->Makefile->GetPolicyStatus(cmPolicies::CMP0101); |
36 | 0 | if (policyStatus == cmPolicies::OLD || policyStatus == cmPolicies::WARN) { |
37 | 0 | prepend = false; |
38 | 0 | } |
39 | |
|
40 | 0 | cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); |
41 | 0 | tgt->InsertCompileOption(BT<std::string>(this->Join(content), lfbt), |
42 | 0 | prepend); |
43 | 0 | return true; // Successfully handled. |
44 | 0 | } |
45 | | |
46 | | std::string Join(std::vector<std::string> const& content) override |
47 | 0 | { |
48 | 0 | return cmList::to_string(content); |
49 | 0 | } |
50 | | }; |
51 | | |
52 | | } // namespace |
53 | | |
54 | | bool cmTargetCompileOptionsCommand(std::vector<std::string> const& args, |
55 | | cmExecutionStatus& status) |
56 | 0 | { |
57 | 0 | return TargetCompileOptionsImpl(status).HandleArguments( |
58 | 0 | args, "COMPILE_OPTIONS", TargetCompileOptionsImpl::PROCESS_BEFORE); |
59 | 0 | } |