Add label summary times to ctest default output. Also, remove parallel time output...
[cmake.git] / Source / cmAddLibraryCommand.cxx
blob7a32f1d96995dd3b3d8e259a7788d548efcfb546
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmAddLibraryCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008-08-18 15:39:22 $
7 Version: $Revision: 1.37 $
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 "cmAddLibraryCommand.h"
19 #include "cmake.h"
21 // cmLibraryCommand
22 bool cmAddLibraryCommand
23 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
25 if(args.size() < 1 )
27 this->SetError("called with incorrect number of arguments");
28 return false;
30 // Library type defaults to value of BUILD_SHARED_LIBS, if it exists,
31 // otherwise it defaults to static library.
32 cmTarget::TargetType type = cmTarget::SHARED_LIBRARY;
33 if (cmSystemTools::IsOff(this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
35 type = cmTarget::STATIC_LIBRARY;
37 bool excludeFromAll = false;
38 bool importTarget = false;
40 std::vector<std::string>::const_iterator s = args.begin();
42 std::string libName = *s;
44 ++s;
46 // If the second argument is "SHARED" or "STATIC", then it controls
47 // the type of library. Otherwise, it is treated as a source or
48 // source list name. There may be two keyword arguments, check for them
49 bool haveSpecifiedType = false;
50 while ( s != args.end() )
52 std::string libType = *s;
53 if(libType == "STATIC")
55 ++s;
56 type = cmTarget::STATIC_LIBRARY;
57 haveSpecifiedType = true;
59 else if(libType == "SHARED")
61 ++s;
62 type = cmTarget::SHARED_LIBRARY;
63 haveSpecifiedType = true;
65 else if(libType == "MODULE")
67 ++s;
68 type = cmTarget::MODULE_LIBRARY;
69 haveSpecifiedType = true;
71 else if(libType == "UNKNOWN")
73 ++s;
74 type = cmTarget::UNKNOWN_LIBRARY;
75 haveSpecifiedType = true;
77 else if(*s == "EXCLUDE_FROM_ALL")
79 ++s;
80 excludeFromAll = true;
82 else if(*s == "IMPORTED")
84 ++s;
85 importTarget = true;
87 else
89 break;
93 /* ideally we should check whether for the linker language of the target
94 CMAKE_${LANG}_CREATE_SHARED_LIBRARY is defined and if not default to
95 STATIC. But at this point we know only the name of the target, but not
96 yet its linker language. */
97 if ((type != cmTarget::STATIC_LIBRARY) &&
98 (this->Makefile->GetCMakeInstance()->GetPropertyAsBool(
99 "TARGET_SUPPORTS_SHARED_LIBS") == false))
101 std::string msg = "ADD_LIBRARY for library ";
102 msg += args[0];
103 msg += " is used with the ";
104 msg += type==cmTarget::SHARED_LIBRARY ? "SHARED" : "MODULE";
105 msg += " option, but the target platform supports only STATIC libraries. "
106 "Building it STATIC instead. This may lead to problems.";
107 cmSystemTools::Message(msg.c_str() ,"Warning");
108 type = cmTarget::STATIC_LIBRARY;
111 // The IMPORTED signature requires a type to be specified explicitly.
112 if(importTarget && !haveSpecifiedType)
114 this->SetError("called with IMPORTED argument but no library type.");
115 return false;
118 // Handle imported target creation.
119 if(importTarget)
121 // Make sure the target does not already exist.
122 if(this->Makefile->FindTargetToUse(libName.c_str()))
124 cmOStringStream e;
125 e << "cannot create imported target \"" << libName
126 << "\" because another target with the same name already exists.";
127 this->SetError(e.str().c_str());
128 return false;
131 // Create the imported target.
132 this->Makefile->AddImportedTarget(libName.c_str(), type);
133 return true;
136 // A non-imported target may not have UNKNOWN type.
137 if(type == cmTarget::UNKNOWN_LIBRARY)
139 this->Makefile->IssueMessage(
140 cmake::FATAL_ERROR,
141 "The UNKNOWN library type may be used only for IMPORTED libraries."
143 return true;
146 // Enforce name uniqueness.
148 std::string msg;
149 if(!this->Makefile->EnforceUniqueName(libName, msg))
151 this->SetError(msg.c_str());
152 return false;
156 if (s == args.end())
158 std::string msg = "You have called ADD_LIBRARY for library ";
159 msg += args[0];
160 msg += " without any source files. This typically indicates a problem ";
161 msg += "with your CMakeLists.txt file";
162 cmSystemTools::Message(msg.c_str() ,"Warning");
165 std::vector<std::string> srclists;
166 while (s != args.end())
168 srclists.push_back(*s);
169 ++s;
172 this->Makefile->AddLibrary(libName.c_str(), type, srclists,
173 excludeFromAll);
175 return true;