packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmAddDependenciesCommand.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
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 "cmAddDependenciesCommand.h"
13 #include "cmLocalGenerator.h"
14 #include "cmGlobalGenerator.h"
15
16 // cmDependenciesCommand
17 bool cmAddDependenciesCommand
18 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
19 {
20   if(args.size() < 2 )
21     {
22     this->SetError("called with incorrect number of arguments");
23     return false;
24     }
25
26   std::string target_name = args[0];
27   if(this->Makefile->IsAlias(target_name.c_str()))
28     {
29     cmOStringStream e;
30     e << "Cannot add target-level dependencies to alias target \""
31       << target_name << "\".\n";
32     this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
33     }
34   if(cmTarget* target = this->Makefile->FindTargetToUse(target_name.c_str()))
35     {
36     std::vector<std::string>::const_iterator s = args.begin();
37     ++s; // skip over target_name
38     for (; s != args.end(); ++s)
39       {
40       target->AddUtility(s->c_str());
41       }
42     }
43   else
44     {
45     cmOStringStream e;
46     e << "Cannot add target-level dependencies to non-existent target \""
47       << target_name << "\".\n"
48       << "The add_dependencies works for top-level logical targets created "
49       << "by the add_executable, add_library, or add_custom_target commands.  "
50       << "If you want to add file-level dependencies see the DEPENDS option "
51       << "of the add_custom_target and add_custom_command commands.";
52     this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
53     }
54
55   return true;
56 }
57