Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmAddExecutableCommand.cxx
blobc382da23d64e213aaa56de464a58854e8aa193dd
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmAddExecutableCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008/01/28 13:38:35 $
7 Version: $Revision: 1.33 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmAddExecutableCommand.h"
19 // cmExecutableCommand
20 bool cmAddExecutableCommand
21 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
23 if(args.size() < 2 )
25 this->SetError("called with incorrect number of arguments");
26 return false;
28 std::vector<std::string>::const_iterator s = args.begin();
30 std::string exename = *s;
32 ++s;
33 bool use_win32 = false;
34 bool use_macbundle = false;
35 bool excludeFromAll = false;
36 bool importTarget = false;
37 while ( s != args.end() )
39 if (*s == "WIN32")
41 ++s;
42 use_win32 = true;
44 else if ( *s == "MACOSX_BUNDLE" )
46 ++s;
47 use_macbundle = true;
49 else if(*s == "EXCLUDE_FROM_ALL")
51 ++s;
52 excludeFromAll = true;
54 else if(*s == "IMPORTED")
56 ++s;
57 importTarget = true;
59 else
61 break;
65 // Special modifiers are not allowed with IMPORTED signature.
66 if(importTarget && (use_win32 || use_macbundle || excludeFromAll))
68 if(use_win32)
70 this->SetError("may not be given WIN32 for an IMPORTED target.");
72 else if(use_macbundle)
74 this->SetError(
75 "may not be given MACOSX_BUNDLE for an IMPORTED target.");
77 else // if(excludeFromAll)
79 this->SetError(
80 "may not be given EXCLUDE_FROM_ALL for an IMPORTED target.");
82 return false;
85 // Check for an existing target with this name.
86 cmTarget* existing = this->Makefile->FindTargetToUse(exename.c_str());
87 if(importTarget)
89 // Make sure the target does not already exist.
90 if(existing)
92 cmOStringStream e;
93 e << "cannot create imported target \"" << exename
94 << "\" because another target with the same name already exists.";
95 this->SetError(e.str().c_str());
96 return false;
99 // Create the imported target.
100 this->Makefile->AddImportedTarget(exename.c_str(), cmTarget::EXECUTABLE);
101 return true;
103 else
105 // Make sure the target does not conflict with an imported target.
106 // This should really enforce global name uniqueness for targets
107 // built within the project too, but that may break compatiblity
108 // with projects in which it was accidentally working.
109 if(existing && existing->IsImported())
111 cmOStringStream e;
112 e << "cannot create target \"" << exename
113 << "\" because an imported target with the same name already exists.";
114 this->SetError(e.str().c_str());
115 return false;
119 if (s == args.end())
121 this->SetError
122 ("called with incorrect number of arguments, no sources provided");
123 return false;
126 std::vector<std::string> srclists(s, args.end());
127 cmTarget* tgt = this->Makefile->AddExecutable(exename.c_str(), srclists,
128 excludeFromAll);
129 if ( use_win32 )
131 tgt->SetProperty("WIN32_EXECUTABLE", "ON");
133 if ( use_macbundle)
135 tgt->SetProperty("MACOSX_BUNDLE", "ON");
138 return true;