2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2008-01-28 16:38:36 +03: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.
|
2008-01-28 16:38:36 +03: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.
|
|
|
|
============================================================================*/
|
2008-01-28 16:38:36 +03:00
|
|
|
#include "cmExportBuildFileGenerator.h"
|
|
|
|
|
2013-10-10 13:18:10 +04:00
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
2013-12-23 20:07:26 +04:00
|
|
|
#include "cmExportSet.h"
|
|
|
|
#include "cmTargetExport.h"
|
2008-01-31 01:25:52 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmExportBuildFileGenerator::cmExportBuildFileGenerator()
|
2015-05-30 14:17:55 +03:00
|
|
|
: Backtrace()
|
2008-01-31 01:25:52 +03:00
|
|
|
{
|
2012-10-06 19:16:11 +04:00
|
|
|
this->Makefile = 0;
|
2013-12-23 20:07:26 +04:00
|
|
|
this->ExportSet = 0;
|
2008-01-31 01:25:52 +03:00
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
|
|
|
|
{
|
2012-11-30 12:26:09 +04:00
|
|
|
{
|
|
|
|
std::string expectedTargets;
|
|
|
|
std::string sep;
|
2013-12-23 20:07:26 +04:00
|
|
|
std::vector<std::string> targets;
|
|
|
|
this->GetTargets(targets);
|
2012-10-06 19:27:40 +04:00
|
|
|
for(std::vector<std::string>::const_iterator
|
2013-12-23 20:07:26 +04:00
|
|
|
tei = targets.begin();
|
|
|
|
tei != targets.end(); ++tei)
|
2012-11-30 12:26:09 +04:00
|
|
|
{
|
2012-10-06 19:44:17 +04:00
|
|
|
cmGeneratorTarget *te = this->Makefile
|
|
|
|
->FindGeneratorTargetToUse(*tei);
|
|
|
|
expectedTargets += sep + this->Namespace + te->Target->GetExportName();
|
2012-11-30 12:26:09 +04:00
|
|
|
sep = " ";
|
2012-10-06 19:44:17 +04:00
|
|
|
if(this->ExportedTargets.insert(te->Target).second)
|
2008-02-06 22:20:36 +03:00
|
|
|
{
|
2012-10-06 19:27:40 +04:00
|
|
|
this->Exports.push_back(te);
|
2008-02-06 22:20:36 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2012-10-06 19:16:11 +04:00
|
|
|
e << "given target \"" << te->GetName() << "\" more than once.";
|
|
|
|
this->Makefile->GetCMakeInstance()
|
2014-03-11 03:04:11 +04:00
|
|
|
->IssueMessage(cmake::FATAL_ERROR, e.str(), this->Backtrace);
|
2008-02-06 22:20:36 +03:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-20 13:58:15 +04:00
|
|
|
if (te->GetType() == cmTarget::INTERFACE_LIBRARY)
|
|
|
|
{
|
2014-02-19 18:15:33 +04:00
|
|
|
this->GenerateRequiredCMakeVersion(os, "3.0.0");
|
2012-11-20 13:58:15 +04:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
|
2012-12-31 01:06:12 +04:00
|
|
|
this->GenerateExpectedTargetsCode(os, expectedTargets);
|
|
|
|
}
|
|
|
|
|
2012-09-23 15:45:17 +04:00
|
|
|
std::vector<std::string> missingTargets;
|
|
|
|
|
2012-12-31 01:06:12 +04:00
|
|
|
// Create all the imported targets.
|
2012-10-06 19:44:17 +04:00
|
|
|
for(std::vector<cmGeneratorTarget*>::const_iterator
|
2012-10-06 19:27:40 +04:00
|
|
|
tei = this->Exports.begin();
|
|
|
|
tei != this->Exports.end(); ++tei)
|
2012-12-31 01:06:12 +04:00
|
|
|
{
|
2012-10-06 19:44:17 +04:00
|
|
|
cmTarget* te = (*tei)->Target;
|
2012-12-31 01:06:12 +04:00
|
|
|
this->GenerateImportTargetCode(os, te);
|
2012-09-23 15:45:17 +04:00
|
|
|
|
2013-01-12 15:11:29 +04:00
|
|
|
te->AppendBuildInterfaceIncludes();
|
|
|
|
|
2012-09-23 15:45:17 +04:00
|
|
|
ImportPropertyMap properties;
|
|
|
|
|
|
|
|
this->PopulateInterfaceProperty("INTERFACE_INCLUDE_DIRECTORIES", te,
|
|
|
|
cmGeneratorExpression::BuildInterface,
|
|
|
|
properties, missingTargets);
|
2014-11-28 20:58:38 +03:00
|
|
|
this->PopulateInterfaceProperty("INTERFACE_SOURCES", te,
|
|
|
|
cmGeneratorExpression::BuildInterface,
|
|
|
|
properties, missingTargets);
|
2012-09-23 15:45:17 +04:00
|
|
|
this->PopulateInterfaceProperty("INTERFACE_COMPILE_DEFINITIONS", te,
|
|
|
|
cmGeneratorExpression::BuildInterface,
|
|
|
|
properties, missingTargets);
|
2013-06-10 18:20:22 +04:00
|
|
|
this->PopulateInterfaceProperty("INTERFACE_COMPILE_OPTIONS", te,
|
|
|
|
cmGeneratorExpression::BuildInterface,
|
|
|
|
properties, missingTargets);
|
2013-11-20 17:54:39 +04:00
|
|
|
this->PopulateInterfaceProperty("INTERFACE_AUTOUIC_OPTIONS", te,
|
|
|
|
cmGeneratorExpression::BuildInterface,
|
2013-12-17 22:23:40 +04:00
|
|
|
properties, missingTargets);
|
|
|
|
this->PopulateInterfaceProperty("INTERFACE_COMPILE_FEATURES", te,
|
|
|
|
cmGeneratorExpression::BuildInterface,
|
2013-11-20 17:54:39 +04:00
|
|
|
properties, missingTargets);
|
2013-01-12 15:13:19 +04:00
|
|
|
this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE",
|
|
|
|
te, properties);
|
2013-06-04 18:47:57 +04:00
|
|
|
const bool newCMP0022Behavior =
|
|
|
|
te->GetPolicyStatusCMP0022() != cmPolicies::WARN
|
|
|
|
&& te->GetPolicyStatusCMP0022() != cmPolicies::OLD;
|
|
|
|
if (newCMP0022Behavior)
|
|
|
|
{
|
|
|
|
this->PopulateInterfaceLinkLibrariesProperty(te,
|
|
|
|
cmGeneratorExpression::BuildInterface,
|
|
|
|
properties, missingTargets);
|
|
|
|
}
|
2013-01-20 20:09:29 +04:00
|
|
|
this->PopulateCompatibleInterfaceProperties(te, properties);
|
2012-09-23 15:45:17 +04:00
|
|
|
|
|
|
|
this->GenerateInterfaceProperties(te, os, properties);
|
2012-12-31 01:06:12 +04:00
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
// Generate import file content for each configuration.
|
|
|
|
for(std::vector<std::string>::const_iterator
|
|
|
|
ci = this->Configurations.begin();
|
|
|
|
ci != this->Configurations.end(); ++ci)
|
|
|
|
{
|
2014-03-11 03:04:11 +04:00
|
|
|
this->GenerateImportConfig(os, *ci, missingTargets);
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
|
2013-01-13 12:44:52 +04:00
|
|
|
this->GenerateMissingTargetsCheckCode(os, missingTargets);
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmExportBuildFileGenerator
|
|
|
|
::GenerateImportTargetsConfig(std::ostream& os,
|
2014-02-10 07:48:34 +04:00
|
|
|
const std::string& config,
|
|
|
|
std::string const& suffix,
|
|
|
|
std::vector<std::string> &missingTargets)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
2012-10-06 19:44:17 +04:00
|
|
|
for(std::vector<cmGeneratorTarget*>::const_iterator
|
2012-10-06 19:27:40 +04:00
|
|
|
tei = this->Exports.begin();
|
|
|
|
tei != this->Exports.end(); ++tei)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
|
|
|
// Collect import properties for this target.
|
2012-10-06 19:44:17 +04:00
|
|
|
cmGeneratorTarget* target = *tei;
|
2008-01-28 16:38:36 +03:00
|
|
|
ImportPropertyMap properties;
|
2012-11-20 13:58:15 +04:00
|
|
|
|
|
|
|
if (target->GetType() != cmTarget::INTERFACE_LIBRARY)
|
|
|
|
{
|
|
|
|
this->SetImportLocationProperty(config, suffix, target, properties);
|
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
if(!properties.empty())
|
|
|
|
{
|
|
|
|
// Get the rest of the target details.
|
2012-11-20 13:58:15 +04:00
|
|
|
if (target->GetType() != cmTarget::INTERFACE_LIBRARY)
|
|
|
|
{
|
|
|
|
this->SetImportDetailProperties(config, suffix,
|
2012-10-06 19:51:07 +04:00
|
|
|
target,
|
2012-10-06 19:44:17 +04:00
|
|
|
properties, missingTargets);
|
2012-11-20 13:58:15 +04:00
|
|
|
this->SetImportLinkInterface(config, suffix,
|
2012-10-06 19:44:17 +04:00
|
|
|
cmGeneratorExpression::BuildInterface,
|
2012-10-06 19:51:07 +04:00
|
|
|
target,
|
2012-10-06 19:44:17 +04:00
|
|
|
properties, missingTargets);
|
2012-11-20 13:58:15 +04:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
|
|
|
|
// TOOD: PUBLIC_HEADER_LOCATION
|
2008-01-28 23:22:07 +03:00
|
|
|
// This should wait until the build feature propagation stuff
|
|
|
|
// is done. Then this can be a propagated include directory.
|
2008-01-28 16:38:36 +03:00
|
|
|
// this->GenerateImportProperty(config, te->HeaderGenerator,
|
|
|
|
// properties);
|
|
|
|
|
|
|
|
// Generate code in the export file.
|
2012-10-06 19:44:17 +04:00
|
|
|
this->GenerateImportPropertyCode(os, config, target->Target,
|
|
|
|
properties);
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-23 20:07:26 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmExportBuildFileGenerator::SetExportSet(cmExportSet *exportSet)
|
|
|
|
{
|
|
|
|
this->ExportSet = exportSet;
|
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmExportBuildFileGenerator
|
2014-02-10 07:48:34 +04:00
|
|
|
::SetImportLocationProperty(const std::string& config,
|
|
|
|
std::string const& suffix,
|
2012-10-06 19:44:17 +04:00
|
|
|
cmGeneratorTarget* target,
|
|
|
|
ImportPropertyMap& properties)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
|
|
|
// Get the makefile in which to lookup target information.
|
2012-10-06 19:44:17 +04:00
|
|
|
cmMakefile* mf = target->Makefile;
|
2012-10-06 20:30:43 +04:00
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
// Add the main target file.
|
|
|
|
{
|
|
|
|
std::string prop = "IMPORTED_LOCATION";
|
|
|
|
prop += suffix;
|
2008-02-06 22:20:36 +03:00
|
|
|
std::string value;
|
2012-10-06 19:44:17 +04:00
|
|
|
if(target->Target->IsAppBundleOnApple())
|
2008-01-28 22:46:16 +03:00
|
|
|
{
|
2012-10-06 19:44:17 +04:00
|
|
|
value = target->GetFullPath(config, false);
|
2008-02-06 22:20:36 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-06 19:44:17 +04:00
|
|
|
value = target->GetFullPath(config, false, true);
|
2008-02-06 22:20:36 +03:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
properties[prop] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether this is a DLL platform.
|
|
|
|
bool dll_platform =
|
|
|
|
(mf->IsOn("WIN32") || mf->IsOn("CYGWIN") || mf->IsOn("MINGW"));
|
|
|
|
|
|
|
|
// Add the import library for windows DLLs.
|
|
|
|
if(dll_platform &&
|
|
|
|
(target->GetType() == cmTarget::SHARED_LIBRARY ||
|
2012-10-06 19:44:17 +04:00
|
|
|
target->Target->IsExecutableWithExports()) &&
|
2008-01-28 16:38:36 +03:00
|
|
|
mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
|
|
|
|
{
|
|
|
|
std::string prop = "IMPORTED_IMPLIB";
|
|
|
|
prop += suffix;
|
2012-10-06 19:44:17 +04:00
|
|
|
std::string value = target->GetFullPath(config, true);
|
|
|
|
target->Target->GetImplibGNUtoMS(value, value,
|
2011-12-06 01:39:07 +04:00
|
|
|
"${CMAKE_IMPORT_LIBRARY_SUFFIX}");
|
2008-01-28 16:38:36 +03:00
|
|
|
properties[prop] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-28 23:47:37 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmExportBuildFileGenerator::HandleMissingTarget(
|
2013-10-10 13:18:10 +04:00
|
|
|
std::string& link_libs, std::vector<std::string>& missingTargets,
|
|
|
|
cmMakefile* mf, cmTarget* depender, cmTarget* dependee)
|
2012-09-28 23:47:37 +04:00
|
|
|
{
|
|
|
|
// The target is not in the export.
|
|
|
|
if(!this->AppendMode)
|
|
|
|
{
|
2013-10-10 13:18:10 +04:00
|
|
|
const std::string name = dependee->GetName();
|
|
|
|
std::vector<std::string> namespaces = this->FindNamespaces(mf, name);
|
|
|
|
|
|
|
|
int targetOccurrences = (int)namespaces.size();
|
|
|
|
if (targetOccurrences == 1)
|
|
|
|
{
|
|
|
|
std::string missingTarget = namespaces[0];
|
|
|
|
|
|
|
|
missingTarget += dependee->GetExportName();
|
|
|
|
link_libs += missingTarget;
|
|
|
|
missingTargets.push_back(missingTarget);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We are not appending, so all exported targets should be
|
|
|
|
// known here. This is probably user-error.
|
|
|
|
this->ComplainAboutMissingTarget(depender, dependee, targetOccurrences);
|
|
|
|
}
|
2012-09-28 23:47:37 +04:00
|
|
|
}
|
|
|
|
// Assume the target will be exported by another command.
|
|
|
|
// Append it with the export namespace.
|
|
|
|
link_libs += this->Namespace;
|
2013-05-17 12:12:02 +04:00
|
|
|
link_libs += dependee->GetExportName();
|
2013-10-10 13:18:10 +04:00
|
|
|
}
|
|
|
|
|
2013-12-23 20:07:26 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmExportBuildFileGenerator
|
|
|
|
::GetTargets(std::vector<std::string> &targets) const
|
|
|
|
{
|
|
|
|
if (this->ExportSet)
|
|
|
|
{
|
|
|
|
for(std::vector<cmTargetExport*>::const_iterator
|
|
|
|
tei = this->ExportSet->GetTargetExports()->begin();
|
|
|
|
tei != this->ExportSet->GetTargetExports()->end(); ++tei)
|
|
|
|
{
|
|
|
|
targets.push_back((*tei)->Target->GetName());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
targets = this->Targets;
|
|
|
|
}
|
|
|
|
|
2013-10-10 13:18:10 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::vector<std::string>
|
|
|
|
cmExportBuildFileGenerator
|
|
|
|
::FindNamespaces(cmMakefile* mf, const std::string& name)
|
|
|
|
{
|
|
|
|
std::vector<std::string> namespaces;
|
2015-05-03 12:10:30 +03:00
|
|
|
cmGlobalGenerator* gg = mf->GetGlobalGenerator();
|
2013-10-10 13:18:10 +04:00
|
|
|
|
|
|
|
std::map<std::string, cmExportBuildFileGenerator*>& exportSets
|
|
|
|
= gg->GetBuildExportSets();
|
|
|
|
|
|
|
|
for(std::map<std::string, cmExportBuildFileGenerator*>::const_iterator
|
|
|
|
expIt = exportSets.begin(); expIt != exportSets.end(); ++expIt)
|
|
|
|
{
|
|
|
|
const cmExportBuildFileGenerator* exportSet = expIt->second;
|
2013-12-23 20:07:26 +04:00
|
|
|
std::vector<std::string> targets;
|
|
|
|
exportSet->GetTargets(targets);
|
2013-10-10 13:18:10 +04:00
|
|
|
if (std::find(targets.begin(), targets.end(), name) != targets.end())
|
|
|
|
{
|
|
|
|
namespaces.push_back(exportSet->GetNamespace());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return namespaces;
|
2012-09-28 23:47:37 +04:00
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmExportBuildFileGenerator
|
2008-02-01 16:56:00 +03:00
|
|
|
::ComplainAboutMissingTarget(cmTarget* depender,
|
2013-10-10 13:18:10 +04:00
|
|
|
cmTarget* dependee,
|
|
|
|
int occurrences)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
2012-10-06 19:16:11 +04:00
|
|
|
if(cmSystemTools::GetErrorOccuredFlag())
|
2008-01-31 01:25:52 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2012-10-06 19:16:11 +04:00
|
|
|
e << "export called with target \"" << depender->GetName()
|
2013-10-10 13:18:10 +04:00
|
|
|
<< "\" which requires target \"" << dependee->GetName() << "\" ";
|
|
|
|
if (occurrences == 0)
|
|
|
|
{
|
|
|
|
e << "that is not in the export set.\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e << "that is not in this export set, but " << occurrences
|
|
|
|
<< " times in others.\n";
|
|
|
|
}
|
|
|
|
e << "If the required target is not easy to reference in this call, "
|
2012-09-28 23:47:37 +04:00
|
|
|
<< "consider using the APPEND option with multiple separate calls.";
|
2012-10-06 19:16:11 +04:00
|
|
|
|
|
|
|
this->Makefile->GetCMakeInstance()
|
2014-03-11 03:04:11 +04:00
|
|
|
->IssueMessage(cmake::FATAL_ERROR, e.str(), this->Backtrace);
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
2013-05-21 02:57:58 +04:00
|
|
|
|
|
|
|
std::string
|
|
|
|
cmExportBuildFileGenerator::InstallNameDir(cmTarget* target,
|
|
|
|
const std::string& config)
|
|
|
|
{
|
|
|
|
std::string install_name_dir;
|
|
|
|
|
|
|
|
cmMakefile* mf = target->GetMakefile();
|
|
|
|
if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
|
|
|
|
{
|
|
|
|
install_name_dir =
|
2014-03-11 03:04:11 +04:00
|
|
|
target->GetInstallNameDirForBuildTree(config);
|
2013-05-21 02:57:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return install_name_dir;
|
|
|
|
}
|