Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmTargetLinkLibrariesCommand.cxx
blob43a89185c11248db4675f5b60dde901a012ba217
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmTargetLinkLibrariesCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008/01/23 15:27:59 $
7 Version: $Revision: 1.25 $
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 "cmTargetLinkLibrariesCommand.h"
19 // cmTargetLinkLibrariesCommand
20 bool cmTargetLinkLibrariesCommand
21 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
23 // must have one argument
24 if(args.size() < 1)
26 this->SetError("called with incorrect number of arguments");
27 return false;
30 // but we might not have any libs after variable expansion
31 if(args.size() < 2)
33 return true;
35 // add libraries, nothe that there is an optional prefix
36 // of debug and optimized than can be used
37 std::vector<std::string>::const_iterator i = args.begin();
39 for(++i; i != args.end(); ++i)
41 if (*i == "debug")
43 ++i;
44 if(i == args.end())
46 this->SetError
47 ("The \"debug\" argument must be followed by a library");
48 return false;
50 this->Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
51 cmTarget::DEBUG);
53 else if (*i == "optimized")
55 ++i;
56 if(i == args.end())
58 this->SetError(
59 "The \"optimized\" argument must be followed by a library");
60 return false;
62 this->Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
63 cmTarget::OPTIMIZED);
65 else if (*i == "general")
67 ++i;
68 if(i == args.end())
70 this->SetError(
71 "The \"general\" argument must be followed by a library");
72 return false;
74 this->Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
75 cmTarget::GENERAL);
77 else
79 // make sure the type is correct if it is currently general. So if you
80 // do a target_link_libraries(foo optimized bar) it will stay optimized
81 // and not use the lookup. As there maybe the case where someone has
82 // specifed that a library is both debug and optimized. (this check is
83 // only there for backwards compatibility when mixing projects built
84 // with old versions of CMake and new)
85 cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
86 std::string linkType = args[0];
87 linkType += "_LINK_TYPE";
88 const char* linkTypeString =
89 this->Makefile->GetDefinition( linkType.c_str() );
90 if(linkTypeString)
92 if(strcmp(linkTypeString, "debug") == 0)
94 llt = cmTarget::DEBUG;
96 if(strcmp(linkTypeString, "optimized") == 0)
98 llt = cmTarget::OPTIMIZED;
101 this->Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),llt);
104 return true;