Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmAddLibraryCommand.cxx
blobf73f4956f408a282384d56b41e87be8b5699449d
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmAddLibraryCommand.cxx,v $
5 Language: C++
6 <<<<<<< cmAddLibraryCommand.cxx
7 Date: $Date: 2008/02/11 22:33:46 $
8 Version: $Revision: 1.36 $
9 =======
10 Date: $Date: 2008-08-18 15:39:22 $
11 Version: $Revision: 1.37 $
12 >>>>>>> 1.37
14 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
15 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
17 This software is distributed WITHOUT ANY WARRANTY; without even
18 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 PURPOSE. See the above copyright notices for more information.
21 =========================================================================*/
22 #include "cmAddLibraryCommand.h"
24 #include "cmake.h"
26 // cmLibraryCommand
27 bool cmAddLibraryCommand
28 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
30 if(args.size() < 1 )
32 this->SetError("called with incorrect number of arguments");
33 return false;
35 // Library type defaults to value of BUILD_SHARED_LIBS, if it exists,
36 // otherwise it defaults to static library.
37 cmTarget::TargetType type = cmTarget::SHARED_LIBRARY;
38 if (cmSystemTools::IsOff(this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
40 type = cmTarget::STATIC_LIBRARY;
42 bool excludeFromAll = false;
43 bool importTarget = false;
45 std::vector<std::string>::const_iterator s = args.begin();
47 std::string libName = *s;
49 ++s;
51 // If the second argument is "SHARED" or "STATIC", then it controls
52 // the type of library. Otherwise, it is treated as a source or
53 // source list name. There may be two keyword arguments, check for them
54 bool haveSpecifiedType = false;
55 while ( s != args.end() )
57 std::string libType = *s;
58 if(libType == "STATIC")
60 ++s;
61 type = cmTarget::STATIC_LIBRARY;
62 haveSpecifiedType = true;
64 else if(libType == "SHARED")
66 ++s;
67 type = cmTarget::SHARED_LIBRARY;
68 haveSpecifiedType = true;
70 else if(libType == "MODULE")
72 ++s;
73 type = cmTarget::MODULE_LIBRARY;
74 haveSpecifiedType = true;
76 else if(libType == "UNKNOWN")
78 ++s;
79 type = cmTarget::UNKNOWN_LIBRARY;
80 haveSpecifiedType = true;
82 else if(*s == "EXCLUDE_FROM_ALL")
84 ++s;
85 excludeFromAll = true;
87 else if(*s == "IMPORTED")
89 ++s;
90 importTarget = true;
92 else
94 break;
98 /* ideally we should check whether for the linker language of the target
99 CMAKE_${LANG}_CREATE_SHARED_LIBRARY is defined and if not default to
100 STATIC. But at this point we know only the name of the target, but not
101 yet its linker language. */
102 if ((type != cmTarget::STATIC_LIBRARY) &&
103 (this->Makefile->GetCMakeInstance()->GetPropertyAsBool(
104 "TARGET_SUPPORTS_SHARED_LIBS") == false))
106 std::string msg = "ADD_LIBRARY for library ";
107 msg += args[0];
108 msg += " is used with the ";
109 msg += type==cmTarget::SHARED_LIBRARY ? "SHARED" : "MODULE";
110 msg += " option, but the target platform supports only STATIC libraries. "
111 "Building it STATIC instead. This may lead to problems.";
112 cmSystemTools::Message(msg.c_str() ,"Warning");
113 type = cmTarget::STATIC_LIBRARY;
116 // The IMPORTED signature requires a type to be specified explicitly.
117 if(importTarget && !haveSpecifiedType)
119 this->SetError("called with IMPORTED argument but no library type.");
120 return false;
123 // Handle imported target creation.
124 if(importTarget)
126 // Make sure the target does not already exist.
127 if(this->Makefile->FindTargetToUse(libName.c_str()))
129 cmOStringStream e;
130 e << "cannot create imported target \"" << libName
131 << "\" because another target with the same name already exists.";
132 this->SetError(e.str().c_str());
133 return false;
136 // Create the imported target.
137 this->Makefile->AddImportedTarget(libName.c_str(), type);
138 return true;
141 // A non-imported target may not have UNKNOWN type.
142 if(type == cmTarget::UNKNOWN_LIBRARY)
144 this->Makefile->IssueMessage(
145 cmake::FATAL_ERROR,
146 "The UNKNOWN library type may be used only for IMPORTED libraries."
148 return true;
151 // Enforce name uniqueness.
153 std::string msg;
154 if(!this->Makefile->EnforceUniqueName(libName, msg))
156 this->SetError(msg.c_str());
157 return false;
161 if (s == args.end())
163 std::string msg = "You have called ADD_LIBRARY for library ";
164 msg += args[0];
165 msg += " without any source files. This typically indicates a problem ";
166 msg += "with your CMakeLists.txt file";
167 cmSystemTools::Message(msg.c_str() ,"Warning");
170 std::vector<std::string> srclists;
171 while (s != args.end())
173 srclists.push_back(*s);
174 ++s;
177 this->Makefile->AddLibrary(libName.c_str(), type, srclists,
178 excludeFromAll);
180 return true;