2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2001-04-30 18:44:00 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2001-04-30 18:44:00 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2001-04-30 18:44:00 +04:00
|
|
|
#include "cmTargetLinkLibrariesCommand.h"
|
|
|
|
|
2008-08-08 01:51:29 +04:00
|
|
|
const char* cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[3] =
|
|
|
|
{
|
|
|
|
"general",
|
|
|
|
"debug",
|
|
|
|
"optimized"
|
|
|
|
};
|
|
|
|
|
2001-04-30 18:44:00 +04:00
|
|
|
// cmTargetLinkLibrariesCommand
|
2008-01-23 18:28:26 +03:00
|
|
|
bool cmTargetLinkLibrariesCommand
|
|
|
|
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
|
2001-04-30 18:44:00 +04:00
|
|
|
{
|
2002-07-19 22:40:49 +04:00
|
|
|
// must have one argument
|
2002-12-12 02:13:33 +03:00
|
|
|
if(args.size() < 1)
|
2001-04-30 18:44:00 +04:00
|
|
|
{
|
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
2003-08-08 00:09:19 +04:00
|
|
|
|
2008-08-12 00:23:02 +04:00
|
|
|
// Lookup the target for which libraries are specified.
|
|
|
|
this->Target =
|
|
|
|
this->Makefile->GetCMakeInstance()
|
|
|
|
->GetGlobalGenerator()->FindTarget(0, args[0].c_str());
|
|
|
|
if(!this->Target)
|
|
|
|
{
|
2010-08-28 18:06:45 +04:00
|
|
|
cmake::MessageType t = cmake::FATAL_ERROR; // fail by default
|
2008-08-12 00:23:02 +04:00
|
|
|
cmOStringStream e;
|
|
|
|
e << "Cannot specify link libraries for target \"" << args[0] << "\" "
|
|
|
|
<< "which is not built by this project.";
|
2010-08-28 18:06:45 +04:00
|
|
|
// The bad target is the only argument. Check how policy CMP0016 is set,
|
|
|
|
// and accept, warn or fail respectively:
|
2010-08-26 23:54:43 +04:00
|
|
|
if (args.size() < 2)
|
|
|
|
{
|
2010-08-28 18:06:45 +04:00
|
|
|
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0016))
|
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
|
|
|
t = cmake::AUTHOR_WARNING;
|
|
|
|
// Print the warning.
|
|
|
|
e << "\n"
|
|
|
|
<< "CMake does not support this but it used to work accidentally "
|
|
|
|
<< "and is being allowed for compatibility."
|
|
|
|
<< "\n" << this->Makefile->GetPolicies()->
|
|
|
|
GetPolicyWarning(cmPolicies::CMP0016);
|
|
|
|
break;
|
|
|
|
case cmPolicies::OLD: // OLD behavior does not warn.
|
|
|
|
t = cmake::MESSAGE;
|
|
|
|
break;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
e << "\n" << this->Makefile->GetPolicies()->
|
|
|
|
GetRequiredPolicyError(cmPolicies::CMP0016);
|
|
|
|
break;
|
|
|
|
case cmPolicies::NEW: // NEW behavior prints the error.
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-08-26 23:54:43 +04:00
|
|
|
}
|
2010-08-28 18:06:45 +04:00
|
|
|
|
|
|
|
// now actually print the message
|
|
|
|
switch(t)
|
2010-08-26 23:54:43 +04:00
|
|
|
{
|
2010-08-28 18:06:45 +04:00
|
|
|
case cmake::AUTHOR_WARNING:
|
|
|
|
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
|
|
|
|
break;
|
|
|
|
case cmake::FATAL_ERROR:
|
|
|
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2010-08-26 23:54:43 +04:00
|
|
|
}
|
2008-08-12 00:23:02 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-12 18:47:40 +04:00
|
|
|
if(this->Target->GetType() == cmTarget::OBJECT_LIBRARY)
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "Object library target \"" << args[0] << "\" "
|
|
|
|
<< "may not link to anything.";
|
|
|
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-26 23:02:40 +04:00
|
|
|
// but we might not have any libs after variable expansion
|
|
|
|
if(args.size() < 2)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-08 01:51:29 +04:00
|
|
|
// Keep track of link configuration specifiers.
|
|
|
|
cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
|
|
|
|
bool haveLLT = false;
|
|
|
|
|
2008-08-12 00:23:02 +04:00
|
|
|
// Start with primary linking and switch to link interface
|
2011-10-07 04:41:37 +04:00
|
|
|
// specification if the keyword is encountered as the first argument.
|
|
|
|
this->CurrentProcessingState = ProcessingLinkLibraries;
|
2008-08-12 00:23:02 +04:00
|
|
|
|
2012-09-23 17:02:29 +04:00
|
|
|
// add libraries, note that there is an optional prefix
|
|
|
|
// of debug and optimized that can be used
|
2008-08-18 18:11:29 +04:00
|
|
|
for(unsigned int i=1; i < args.size(); ++i)
|
2001-04-30 18:44:00 +04:00
|
|
|
{
|
2008-08-18 18:11:29 +04:00
|
|
|
if(args[i] == "LINK_INTERFACE_LIBRARIES")
|
2008-08-12 00:23:02 +04:00
|
|
|
{
|
2011-10-07 04:41:37 +04:00
|
|
|
this->CurrentProcessingState = ProcessingLinkInterface;
|
2008-08-18 18:11:29 +04:00
|
|
|
if(i != 1)
|
|
|
|
{
|
|
|
|
this->Makefile->IssueMessage(
|
|
|
|
cmake::FATAL_ERROR,
|
|
|
|
"The LINK_INTERFACE_LIBRARIES option must appear as the second "
|
|
|
|
"argument, just after the target name."
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
2008-08-12 00:23:02 +04:00
|
|
|
}
|
2011-10-07 04:41:37 +04:00
|
|
|
else if(args[i] == "LINK_PUBLIC")
|
|
|
|
{
|
|
|
|
if(i != 1 && this->CurrentProcessingState != ProcessingPrivateInterface)
|
|
|
|
{
|
|
|
|
this->Makefile->IssueMessage(
|
|
|
|
cmake::FATAL_ERROR,
|
|
|
|
"The LINK_PUBLIC or LINK_PRIVATE option must appear as the second "
|
|
|
|
"argument, just after the target name."
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
this->CurrentProcessingState = ProcessingPublicInterface;
|
|
|
|
}
|
|
|
|
else if(args[i] == "LINK_PRIVATE")
|
|
|
|
{
|
|
|
|
if(i != 1 && this->CurrentProcessingState != ProcessingPublicInterface)
|
|
|
|
{
|
|
|
|
this->Makefile->IssueMessage(
|
|
|
|
cmake::FATAL_ERROR,
|
|
|
|
"The LINK_PUBLIC or LINK_PRIVATE option must appear as the second "
|
|
|
|
"argument, just after the target name."
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
this->CurrentProcessingState = ProcessingPrivateInterface;
|
|
|
|
}
|
2008-08-18 18:11:29 +04:00
|
|
|
else if(args[i] == "debug")
|
2001-04-30 18:44:00 +04:00
|
|
|
{
|
2008-08-08 01:51:29 +04:00
|
|
|
if(haveLLT)
|
2004-07-29 19:45:14 +04:00
|
|
|
{
|
2008-08-08 01:51:29 +04:00
|
|
|
this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::DEBUG);
|
2004-07-29 19:45:14 +04:00
|
|
|
}
|
2008-08-08 01:51:29 +04:00
|
|
|
llt = cmTarget::DEBUG;
|
|
|
|
haveLLT = true;
|
2001-04-30 18:44:00 +04:00
|
|
|
}
|
2008-08-18 18:11:29 +04:00
|
|
|
else if(args[i] == "optimized")
|
2001-04-30 18:44:00 +04:00
|
|
|
{
|
2008-08-08 01:51:29 +04:00
|
|
|
if(haveLLT)
|
2004-07-29 19:45:14 +04:00
|
|
|
{
|
2008-08-08 01:51:29 +04:00
|
|
|
this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::OPTIMIZED);
|
2004-07-29 19:45:14 +04:00
|
|
|
}
|
2008-08-08 01:51:29 +04:00
|
|
|
llt = cmTarget::OPTIMIZED;
|
|
|
|
haveLLT = true;
|
2001-04-30 18:44:00 +04:00
|
|
|
}
|
2008-08-18 18:11:29 +04:00
|
|
|
else if(args[i] == "general")
|
2001-04-30 18:44:00 +04:00
|
|
|
{
|
2008-08-08 01:51:29 +04:00
|
|
|
if(haveLLT)
|
2006-11-29 19:00:17 +03:00
|
|
|
{
|
2008-08-08 01:51:29 +04:00
|
|
|
this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::GENERAL);
|
2006-11-29 19:00:17 +03:00
|
|
|
}
|
2008-08-08 01:51:29 +04:00
|
|
|
llt = cmTarget::GENERAL;
|
|
|
|
haveLLT = true;
|
|
|
|
}
|
|
|
|
else if(haveLLT)
|
|
|
|
{
|
|
|
|
// The link type was specified by the previous argument.
|
|
|
|
haveLLT = false;
|
2008-08-18 18:11:29 +04:00
|
|
|
this->HandleLibrary(args[i].c_str(), llt);
|
2006-11-29 19:00:17 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-08 01:51:29 +04:00
|
|
|
// Lookup old-style cache entry if type is unspecified. So if you
|
2006-11-29 19:00:17 +03:00
|
|
|
// do a target_link_libraries(foo optimized bar) it will stay optimized
|
|
|
|
// and not use the lookup. As there maybe the case where someone has
|
|
|
|
// specifed that a library is both debug and optimized. (this check is
|
|
|
|
// only there for backwards compatibility when mixing projects built
|
|
|
|
// with old versions of CMake and new)
|
2008-08-08 01:51:29 +04:00
|
|
|
llt = cmTarget::GENERAL;
|
2006-11-29 19:00:17 +03:00
|
|
|
std::string linkType = args[0];
|
|
|
|
linkType += "_LINK_TYPE";
|
2010-08-26 23:01:58 +04:00
|
|
|
const char* linkTypeString =
|
2006-11-29 19:00:17 +03:00
|
|
|
this->Makefile->GetDefinition( linkType.c_str() );
|
|
|
|
if(linkTypeString)
|
|
|
|
{
|
|
|
|
if(strcmp(linkTypeString, "debug") == 0)
|
|
|
|
{
|
|
|
|
llt = cmTarget::DEBUG;
|
|
|
|
}
|
|
|
|
if(strcmp(linkTypeString, "optimized") == 0)
|
|
|
|
{
|
|
|
|
llt = cmTarget::OPTIMIZED;
|
|
|
|
}
|
|
|
|
}
|
2008-08-18 18:11:29 +04:00
|
|
|
this->HandleLibrary(args[i].c_str(), llt);
|
2001-04-30 18:44:00 +04:00
|
|
|
}
|
2010-08-26 23:01:58 +04:00
|
|
|
}
|
2008-08-08 01:51:29 +04:00
|
|
|
|
|
|
|
// Make sure the last argument was not a library type specifier.
|
|
|
|
if(haveLLT)
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "The \"" << this->LinkLibraryTypeNames[llt]
|
|
|
|
<< "\" argument must be followed by a library.";
|
|
|
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
}
|
|
|
|
|
2011-10-07 04:41:37 +04:00
|
|
|
// If any of the LINK_ options were given, make sure the
|
|
|
|
// LINK_INTERFACE_LIBRARIES target property exists.
|
|
|
|
// Use of any of the new keywords implies awareness of
|
|
|
|
// this property. And if no libraries are named, it should
|
|
|
|
// result in an empty link interface.
|
2011-11-23 02:20:23 +04:00
|
|
|
if(this->CurrentProcessingState != ProcessingLinkLibraries &&
|
|
|
|
!this->Target->GetProperty("LINK_INTERFACE_LIBRARIES"))
|
2008-08-12 00:23:02 +04:00
|
|
|
{
|
|
|
|
this->Target->SetProperty("LINK_INTERFACE_LIBRARIES", "");
|
|
|
|
}
|
|
|
|
|
2001-04-30 18:44:00 +04:00
|
|
|
return true;
|
|
|
|
}
|
2008-08-08 01:51:29 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmTargetLinkLibrariesCommand
|
|
|
|
::LinkLibraryTypeSpecifierWarning(int left, int right)
|
|
|
|
{
|
|
|
|
cmOStringStream w;
|
|
|
|
w << "Link library type specifier \""
|
|
|
|
<< this->LinkLibraryTypeNames[left] << "\" is followed by specifier \""
|
|
|
|
<< this->LinkLibraryTypeNames[right] << "\" instead of a library name. "
|
|
|
|
<< "The first specifier will be ignored.";
|
|
|
|
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
|
|
|
|
}
|
2008-08-12 00:23:02 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmTargetLinkLibrariesCommand::HandleLibrary(const char* lib,
|
|
|
|
cmTarget::LinkLibraryType llt)
|
|
|
|
{
|
|
|
|
// Handle normal case first.
|
2011-10-07 04:41:37 +04:00
|
|
|
if(this->CurrentProcessingState != ProcessingLinkInterface)
|
2008-08-12 00:23:02 +04:00
|
|
|
{
|
|
|
|
this->Makefile
|
|
|
|
->AddLinkLibraryForTarget(this->Target->GetName(), lib, llt);
|
2011-11-23 02:20:23 +04:00
|
|
|
if (this->CurrentProcessingState != ProcessingPublicInterface)
|
2011-10-07 04:41:37 +04:00
|
|
|
{
|
2011-11-23 02:20:23 +04:00
|
|
|
// Not LINK_INTERFACE_LIBRARIES or LINK_PUBLIC, do not add to interface.
|
2011-10-07 04:41:37 +04:00
|
|
|
return;
|
|
|
|
}
|
2008-08-12 00:23:02 +04:00
|
|
|
}
|
|
|
|
|
2008-09-05 01:34:25 +04:00
|
|
|
// Get the list of configurations considered to be DEBUG.
|
|
|
|
std::vector<std::string> const& debugConfigs =
|
|
|
|
this->Makefile->GetCMakeInstance()->GetDebugConfigs();
|
|
|
|
std::string prop;
|
|
|
|
|
2008-08-12 00:23:02 +04:00
|
|
|
// Include this library in the link interface for the target.
|
2008-09-05 01:34:25 +04:00
|
|
|
if(llt == cmTarget::DEBUG || llt == cmTarget::GENERAL)
|
2008-08-12 00:23:02 +04:00
|
|
|
{
|
2008-09-05 01:34:25 +04:00
|
|
|
// Put in the DEBUG configuration interfaces.
|
|
|
|
for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
|
|
|
|
i != debugConfigs.end(); ++i)
|
|
|
|
{
|
|
|
|
prop = "LINK_INTERFACE_LIBRARIES_";
|
|
|
|
prop += *i;
|
|
|
|
this->Target->AppendProperty(prop.c_str(), lib);
|
|
|
|
}
|
2008-08-12 00:23:02 +04:00
|
|
|
}
|
2008-09-05 01:34:25 +04:00
|
|
|
if(llt == cmTarget::OPTIMIZED || llt == cmTarget::GENERAL)
|
2008-08-12 00:23:02 +04:00
|
|
|
{
|
2008-09-05 01:34:25 +04:00
|
|
|
// Put in the non-DEBUG configuration interfaces.
|
2008-08-12 00:23:02 +04:00
|
|
|
this->Target->AppendProperty("LINK_INTERFACE_LIBRARIES", lib);
|
|
|
|
|
2008-09-05 01:34:25 +04:00
|
|
|
// Make sure the DEBUG configuration interfaces exist so that the
|
|
|
|
// general one will not be used as a fall-back.
|
|
|
|
for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
|
|
|
|
i != debugConfigs.end(); ++i)
|
2008-08-12 00:23:02 +04:00
|
|
|
{
|
2008-09-05 01:34:25 +04:00
|
|
|
prop = "LINK_INTERFACE_LIBRARIES_";
|
|
|
|
prop += *i;
|
|
|
|
if(!this->Target->GetProperty(prop.c_str()))
|
|
|
|
{
|
|
|
|
this->Target->SetProperty(prop.c_str(), "");
|
|
|
|
}
|
2008-08-12 00:23:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|