resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmTargetCompileOptionsCommand.cxx
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 "cmTargetCompileOptionsCommand.h"
4
5 #include "cmListFileCache.h"
6 #include "cmMakefile.h"
7 #include "cmMessageType.h"
8 #include "cmPolicies.h"
9 #include "cmStringAlgorithms.h"
10 #include "cmTarget.h"
11 #include "cmTargetPropCommandBase.h"
12
13 namespace {
14
15 class TargetCompileOptionsImpl : public cmTargetPropCommandBase
16 {
17 public:
18   using cmTargetPropCommandBase::cmTargetPropCommandBase;
19
20 private:
21   void HandleMissingTarget(const std::string& name) override
22   {
23     this->Makefile->IssueMessage(
24       MessageType::FATAL_ERROR,
25       cmStrCat("Cannot specify compile options for target \"", name,
26                "\" which is not built by this project."));
27   }
28
29   bool HandleDirectContent(cmTarget* tgt,
30                            const std::vector<std::string>& content,
31                            bool prepend, bool /*system*/) override
32   {
33     cmPolicies::PolicyStatus policyStatus =
34       this->Makefile->GetPolicyStatus(cmPolicies::CMP0101);
35     if (policyStatus == cmPolicies::OLD || policyStatus == cmPolicies::WARN) {
36       prepend = false;
37     }
38
39     cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
40     tgt->InsertCompileOption(BT<std::string>(this->Join(content), lfbt),
41                              prepend);
42     return true; // Successfully handled.
43   }
44
45   std::string Join(const std::vector<std::string>& content) override
46   {
47     return cmJoin(content, ";");
48   }
49 };
50
51 } // namespace
52
53 bool cmTargetCompileOptionsCommand(std::vector<std::string> const& args,
54                                    cmExecutionStatus& status)
55 {
56   return TargetCompileOptionsImpl(status).HandleArguments(
57     args, "COMPILE_OPTIONS", TargetCompileOptionsImpl::PROCESS_BEFORE);
58 }