Imported Upstream version 2.8.11.2
[platform/upstream/cmake.git] / Source / cmTargetCompileDefinitionsCommand.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2013 Stephen Kelly <steveire@gmail.com>
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmTargetCompileDefinitionsCommand.h"
13
14 bool cmTargetCompileDefinitionsCommand
15 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
16 {
17   return this->HandleArguments(args, "COMPILE_DEFINITIONS");
18 }
19
20 void cmTargetCompileDefinitionsCommand
21 ::HandleImportedTarget(const std::string &tgt)
22 {
23   cmOStringStream e;
24   e << "Cannot specify compile definitions for imported target \""
25     << tgt << "\".";
26   this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
27 }
28
29 void cmTargetCompileDefinitionsCommand
30 ::HandleMissingTarget(const std::string &name)
31 {
32   cmOStringStream e;
33   e << "Cannot specify compile definitions for target \"" << name << "\" "
34        "which is not built by this project.";
35   this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
36 }
37
38 //----------------------------------------------------------------------------
39 std::string cmTargetCompileDefinitionsCommand
40 ::Join(const std::vector<std::string> &content)
41 {
42   std::string defs;
43   std::string sep;
44   for(std::vector<std::string>::const_iterator it = content.begin();
45     it != content.end(); ++it)
46     {
47     if (strncmp(it->c_str(), "-D", 2) == 0)
48       {
49       defs += sep + it->substr(2);
50       }
51     else
52       {
53       defs += sep + *it;
54       }
55     sep = ";";
56     }
57   return defs;
58 }
59
60 //----------------------------------------------------------------------------
61 void cmTargetCompileDefinitionsCommand
62 ::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
63                                    bool)
64 {
65   tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
66 }