KWSys Nightly Date Stamp
[cmake.git] / Source / cmAddExecutableCommand.cxx
blob3a165e38a9a7b844995a965c922c0982cd255d6b
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmAddExecutableCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008-02-11 22:33:46 $
7 Version: $Revision: 1.35 $
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 // Handle imported target creation.
86 if(importTarget)
88 // Make sure the target does not already exist.
89 if(this->Makefile->FindTargetToUse(exename.c_str()))
91 cmOStringStream e;
92 e << "cannot create imported target \"" << exename
93 << "\" because another target with the same name already exists.";
94 this->SetError(e.str().c_str());
95 return false;
98 // Create the imported target.
99 this->Makefile->AddImportedTarget(exename.c_str(), cmTarget::EXECUTABLE);
100 return true;
103 // Enforce name uniqueness.
105 std::string msg;
106 if(!this->Makefile->EnforceUniqueName(exename, msg))
108 this->SetError(msg.c_str());
109 return false;
113 if (s == args.end())
115 this->SetError
116 ("called with incorrect number of arguments, no sources provided");
117 return false;
120 std::vector<std::string> srclists(s, args.end());
121 cmTarget* tgt = this->Makefile->AddExecutable(exename.c_str(), srclists,
122 excludeFromAll);
123 if ( use_win32 )
125 tgt->SetProperty("WIN32_EXECUTABLE", "ON");
127 if ( use_macbundle)
129 tgt->SetProperty("MACOSX_BUNDLE", "ON");
132 return true;