2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2008-01-28 16:38:36 +03:00
|
|
|
#include "cmExportBuildFileGenerator.h"
|
|
|
|
|
2013-12-23 20:07:26 +04:00
|
|
|
#include "cmExportSet.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmGeneratorExpression.h"
|
|
|
|
#include "cmGeneratorTarget.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmPolicies.h"
|
|
|
|
#include "cmState.h"
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmTarget.h"
|
2013-12-23 20:07:26 +04:00
|
|
|
#include "cmTargetExport.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmake.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <sstream>
|
|
|
|
#include <utility>
|
2008-01-31 01:25:52 +03:00
|
|
|
|
|
|
|
cmExportBuildFileGenerator::cmExportBuildFileGenerator()
|
|
|
|
{
|
2016-06-27 23:44:16 +03:00
|
|
|
this->LG = CM_NULLPTR;
|
|
|
|
this->ExportSet = CM_NULLPTR;
|
2008-01-31 01:25:52 +03:00
|
|
|
}
|
|
|
|
|
2015-09-16 23:08:22 +03:00
|
|
|
void cmExportBuildFileGenerator::Compute(cmLocalGenerator* lg)
|
|
|
|
{
|
|
|
|
this->LG = lg;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->ExportSet) {
|
2015-10-17 14:31:33 +03:00
|
|
|
this->ExportSet->Compute(lg);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-16 23:08:22 +03:00
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
|
|
|
|
{
|
2012-11-30 12:26:09 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string expectedTargets;
|
|
|
|
std::string sep;
|
|
|
|
std::vector<std::string> targets;
|
|
|
|
this->GetTargets(targets);
|
|
|
|
for (std::vector<std::string>::const_iterator tei = targets.begin();
|
|
|
|
tei != targets.end(); ++tei) {
|
|
|
|
cmGeneratorTarget* te = this->LG->FindGeneratorTargetToUse(*tei);
|
|
|
|
expectedTargets += sep + this->Namespace + te->GetExportName();
|
|
|
|
sep = " ";
|
|
|
|
if (this->ExportedTargets.insert(te).second) {
|
|
|
|
this->Exports.push_back(te);
|
|
|
|
} else {
|
|
|
|
std::ostringstream e;
|
|
|
|
e << "given target \"" << te->GetName() << "\" more than once.";
|
|
|
|
this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
|
|
|
|
cmake::FATAL_ERROR, e.str(),
|
|
|
|
this->LG->GetMakefile()->GetBacktrace());
|
|
|
|
return false;
|
2008-02-06 22:20:36 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
if (te->GetType() == cmState::INTERFACE_LIBRARY) {
|
|
|
|
this->GenerateRequiredCMakeVersion(os, "3.0.0");
|
2012-11-20 13:58:15 +04:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GenerateExpectedTargetsCode(os, expectedTargets);
|
2012-12-31 01:06:12 +04:00
|
|
|
}
|
|
|
|
|
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.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmGeneratorTarget*>::const_iterator tei =
|
|
|
|
this->Exports.begin();
|
|
|
|
tei != this->Exports.end(); ++tei) {
|
2015-08-04 20:19:42 +03:00
|
|
|
cmGeneratorTarget* gte = *tei;
|
2015-10-17 15:33:51 +03:00
|
|
|
this->GenerateImportTargetCode(os, gte);
|
2012-09-23 15:45:17 +04:00
|
|
|
|
2015-10-17 15:33:51 +03:00
|
|
|
gte->Target->AppendBuildInterfaceIncludes();
|
2013-01-12 15:11:29 +04:00
|
|
|
|
2012-09-23 15:45:17 +04:00
|
|
|
ImportPropertyMap properties;
|
|
|
|
|
2015-10-17 15:33:51 +03:00
|
|
|
this->PopulateInterfaceProperty("INTERFACE_INCLUDE_DIRECTORIES", gte,
|
2012-09-23 15:45:17 +04:00
|
|
|
cmGeneratorExpression::BuildInterface,
|
|
|
|
properties, missingTargets);
|
2015-10-17 15:33:51 +03:00
|
|
|
this->PopulateInterfaceProperty("INTERFACE_SOURCES", gte,
|
2014-11-28 20:58:38 +03:00
|
|
|
cmGeneratorExpression::BuildInterface,
|
|
|
|
properties, missingTargets);
|
2015-10-17 15:33:51 +03:00
|
|
|
this->PopulateInterfaceProperty("INTERFACE_COMPILE_DEFINITIONS", gte,
|
2012-09-23 15:45:17 +04:00
|
|
|
cmGeneratorExpression::BuildInterface,
|
|
|
|
properties, missingTargets);
|
2015-10-17 15:33:51 +03:00
|
|
|
this->PopulateInterfaceProperty("INTERFACE_COMPILE_OPTIONS", gte,
|
2013-06-10 18:20:22 +04:00
|
|
|
cmGeneratorExpression::BuildInterface,
|
|
|
|
properties, missingTargets);
|
2015-10-17 15:33:51 +03:00
|
|
|
this->PopulateInterfaceProperty("INTERFACE_AUTOUIC_OPTIONS", gte,
|
2013-11-20 17:54:39 +04:00
|
|
|
cmGeneratorExpression::BuildInterface,
|
2013-12-17 22:23:40 +04:00
|
|
|
properties, missingTargets);
|
2015-10-17 15:33:51 +03:00
|
|
|
this->PopulateInterfaceProperty("INTERFACE_COMPILE_FEATURES", gte,
|
2013-12-17 22:23:40 +04:00
|
|
|
cmGeneratorExpression::BuildInterface,
|
2013-11-20 17:54:39 +04:00
|
|
|
properties, missingTargets);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE", gte,
|
|
|
|
properties);
|
2013-06-04 18:47:57 +04:00
|
|
|
const bool newCMP0022Behavior =
|
2016-05-16 17:34:04 +03:00
|
|
|
gte->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
|
|
|
|
gte->GetPolicyStatusCMP0022() != cmPolicies::OLD;
|
|
|
|
if (newCMP0022Behavior) {
|
|
|
|
this->PopulateInterfaceLinkLibrariesProperty(
|
|
|
|
gte, cmGeneratorExpression::BuildInterface, properties,
|
|
|
|
missingTargets);
|
|
|
|
}
|
2015-08-04 20:19:42 +03:00
|
|
|
this->PopulateCompatibleInterfaceProperties(gte, properties);
|
2012-09-23 15:45:17 +04:00
|
|
|
|
2015-10-17 15:33:51 +03:00
|
|
|
this->GenerateInterfaceProperties(gte, os, properties);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-12-31 01:06:12 +04:00
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
// Generate import file content for each configuration.
|
2016-05-16 17:34:04 +03:00
|
|
|
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);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmExportBuildFileGenerator::GenerateImportTargetsConfig(
|
|
|
|
std::ostream& os, const std::string& config, std::string const& suffix,
|
|
|
|
std::vector<std::string>& missingTargets)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmGeneratorTarget*>::const_iterator 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
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->GetType() != cmState::INTERFACE_LIBRARY) {
|
2012-11-20 13:58:15 +04:00
|
|
|
this->SetImportLocationProperty(config, suffix, target, properties);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!properties.empty()) {
|
2008-01-28 16:38:36 +03:00
|
|
|
// Get the rest of the target details.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->GetType() != cmState::INTERFACE_LIBRARY) {
|
|
|
|
this->SetImportDetailProperties(config, suffix, target, properties,
|
|
|
|
missingTargets);
|
2012-11-20 13:58:15 +04:00
|
|
|
this->SetImportLinkInterface(config, suffix,
|
2012-10-06 19:44:17 +04:00
|
|
|
cmGeneratorExpression::BuildInterface,
|
2016-05-16 17:34:04 +03:00
|
|
|
target, properties, missingTargets);
|
|
|
|
}
|
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.
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GenerateImportPropertyCode(os, config, target, properties);
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmExportBuildFileGenerator::SetExportSet(cmExportSet* exportSet)
|
2013-12-23 20:07:26 +04:00
|
|
|
{
|
|
|
|
this->ExportSet = exportSet;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmExportBuildFileGenerator::SetImportLocationProperty(
|
|
|
|
const std::string& config, std::string const& suffix,
|
|
|
|
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.
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string prop = "IMPORTED_LOCATION";
|
|
|
|
prop += suffix;
|
|
|
|
std::string value;
|
|
|
|
if (target->IsAppBundleOnApple()) {
|
|
|
|
value = target->GetFullPath(config, false);
|
|
|
|
} else {
|
|
|
|
value = target->GetFullPath(config, false, true);
|
2008-02-06 22:20:36 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
properties[prop] = value;
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add the import library for windows DLLs.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->IsDLLPlatform() &&
|
|
|
|
(target->GetType() == cmState::SHARED_LIBRARY ||
|
|
|
|
target->IsExecutableWithExports()) &&
|
|
|
|
mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
|
2008-01-28 16:38:36 +03:00
|
|
|
std::string prop = "IMPORTED_IMPLIB";
|
|
|
|
prop += suffix;
|
2012-10-06 19:44:17 +04:00
|
|
|
std::string value = target->GetFullPath(config, true);
|
2016-05-16 17:34:04 +03:00
|
|
|
target->GetImplibGNUtoMS(value, value, "${CMAKE_IMPORT_LIBRARY_SUFFIX}");
|
2008-01-28 16:38:36 +03:00
|
|
|
properties[prop] = value;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmExportBuildFileGenerator::HandleMissingTarget(
|
|
|
|
std::string& link_libs, std::vector<std::string>& missingTargets,
|
|
|
|
cmGeneratorTarget* depender, cmGeneratorTarget* dependee)
|
2012-09-28 23:47:37 +04:00
|
|
|
{
|
|
|
|
// The target is not in the export.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->AppendMode) {
|
2013-10-10 13:18:10 +04:00
|
|
|
const std::string name = dependee->GetName();
|
2015-10-17 16:05:46 +03:00
|
|
|
cmGlobalGenerator* gg =
|
2016-05-16 17:34:04 +03:00
|
|
|
dependee->GetLocalGenerator()->GetGlobalGenerator();
|
2015-10-17 16:01:25 +03:00
|
|
|
std::vector<std::string> namespaces = this->FindNamespaces(gg, name);
|
2013-10-10 13:18:10 +04:00
|
|
|
|
|
|
|
int targetOccurrences = (int)namespaces.size();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (targetOccurrences == 1) {
|
2013-10-10 13:18:10 +04:00
|
|
|
std::string missingTarget = namespaces[0];
|
|
|
|
|
2015-10-17 16:08:13 +03:00
|
|
|
missingTarget += dependee->GetExportName();
|
2013-10-10 13:18:10 +04:00
|
|
|
link_libs += missingTarget;
|
|
|
|
missingTargets.push_back(missingTarget);
|
|
|
|
return;
|
2012-09-28 23:47:37 +04:00
|
|
|
}
|
2016-08-18 21:36:29 +03:00
|
|
|
// We are not appending, so all exported targets should be
|
|
|
|
// known here. This is probably user-error.
|
|
|
|
this->ComplainAboutMissingTarget(depender, dependee, targetOccurrences);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
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;
|
2015-10-17 16:08:13 +03:00
|
|
|
link_libs += dependee->GetExportName();
|
2013-10-10 13:18:10 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmExportBuildFileGenerator::GetTargets(
|
|
|
|
std::vector<std::string>& targets) const
|
2013-12-23 20:07:26 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->ExportSet) {
|
|
|
|
for (std::vector<cmTargetExport*>::const_iterator tei =
|
|
|
|
this->ExportSet->GetTargetExports()->begin();
|
|
|
|
tei != this->ExportSet->GetTargetExports()->end(); ++tei) {
|
2015-10-17 14:31:33 +03:00
|
|
|
targets.push_back((*tei)->TargetName);
|
2013-12-23 20:07:26 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return;
|
|
|
|
}
|
2013-12-23 20:07:26 +04:00
|
|
|
targets = this->Targets;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::vector<std::string> cmExportBuildFileGenerator::FindNamespaces(
|
|
|
|
cmGlobalGenerator* gg, const std::string& name)
|
2013-10-10 13:18:10 +04:00
|
|
|
{
|
|
|
|
std::vector<std::string> namespaces;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::map<std::string, cmExportBuildFileGenerator*>& exportSets =
|
|
|
|
gg->GetBuildExportSets();
|
2013-10-10 13:18:10 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<std::string, cmExportBuildFileGenerator*>::const_iterator
|
|
|
|
expIt = exportSets.begin();
|
|
|
|
expIt != exportSets.end(); ++expIt) {
|
2013-10-10 13:18:10 +04:00
|
|
|
const cmExportBuildFileGenerator* exportSet = expIt->second;
|
2013-12-23 20:07:26 +04:00
|
|
|
std::vector<std::string> targets;
|
|
|
|
exportSet->GetTargets(targets);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (std::find(targets.begin(), targets.end(), name) != targets.end()) {
|
2013-10-10 13:18:10 +04:00
|
|
|
namespaces.push_back(exportSet->GetNamespace());
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-10 13:18:10 +04:00
|
|
|
|
|
|
|
return namespaces;
|
2012-09-28 23:47:37 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmExportBuildFileGenerator::ComplainAboutMissingTarget(
|
|
|
|
cmGeneratorTarget* depender, cmGeneratorTarget* dependee, int occurrences)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::GetErrorOccuredFlag()) {
|
2008-01-31 01:25:52 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-31 01:25:52 +03:00
|
|
|
|
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() << "\" ";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (occurrences == 0) {
|
2013-10-10 13:18:10 +04:00
|
|
|
e << "that is not in the export set.\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-10-10 13:18:10 +04:00
|
|
|
e << "that is not in this export set, but " << occurrences
|
2016-05-16 17:34:04 +03:00
|
|
|
<< " times in others.\n";
|
|
|
|
}
|
2013-10-10 13:18:10 +04:00
|
|
|
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
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
|
|
|
|
cmake::FATAL_ERROR, e.str(), this->LG->GetMakefile()->GetBacktrace());
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
2013-05-21 02:57:58 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmExportBuildFileGenerator::InstallNameDir(
|
|
|
|
cmGeneratorTarget* target, const std::string& config)
|
2013-05-21 02:57:58 +04:00
|
|
|
{
|
|
|
|
std::string install_name_dir;
|
|
|
|
|
2015-08-04 20:19:47 +03:00
|
|
|
cmMakefile* mf = target->Target->GetMakefile();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
|
|
|
|
install_name_dir = target->GetInstallNameDirForBuildTree(config);
|
|
|
|
}
|
2013-05-21 02:57:58 +04:00
|
|
|
|
|
|
|
return install_name_dir;
|
|
|
|
}
|