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 "cmExportFileGenerator.h"
|
|
|
|
|
2012-09-15 23:55:24 +04:00
|
|
|
#include "cmExportSet.h"
|
2008-01-28 16:38:36 +03:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2012-09-15 23:55:24 +04:00
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmInstallExportGenerator.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
2008-01-28 16:38:36 +03:00
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmTarget.h"
|
2012-09-15 23:55:24 +04:00
|
|
|
#include "cmTargetExport.h"
|
2008-03-14 00:04:32 +03:00
|
|
|
#include "cmVersion.h"
|
2013-01-20 20:09:29 +04:00
|
|
|
#include "cmComputeLinkInformation.h"
|
2008-01-28 16:38:36 +03:00
|
|
|
|
2008-01-28 21:21:42 +03:00
|
|
|
#include <cmsys/auto_ptr.hxx>
|
2014-01-04 09:47:13 +04:00
|
|
|
#include <cmsys/FStream.hxx>
|
2013-03-25 00:18:17 +04:00
|
|
|
#include <assert.h>
|
2008-01-28 21:21:42 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmExportFileGenerator::cmExportFileGenerator()
|
|
|
|
{
|
|
|
|
this->AppendMode = false;
|
2013-06-04 18:47:57 +04:00
|
|
|
this->ExportOld = false;
|
2008-01-28 21:21:42 +03:00
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmExportFileGenerator::AddConfiguration(const char* config)
|
|
|
|
{
|
|
|
|
this->Configurations.push_back(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmExportFileGenerator::SetExportFile(const char* mainFile)
|
|
|
|
{
|
|
|
|
this->MainImportFile = mainFile;
|
|
|
|
this->FileDir =
|
|
|
|
cmSystemTools::GetFilenamePath(this->MainImportFile);
|
|
|
|
this->FileBase =
|
|
|
|
cmSystemTools::GetFilenameWithoutLastExtension(this->MainImportFile);
|
|
|
|
this->FileExt =
|
|
|
|
cmSystemTools::GetFilenameLastExtension(this->MainImportFile);
|
|
|
|
}
|
|
|
|
|
2012-10-06 19:27:40 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
const char* cmExportFileGenerator::GetMainExportFileName() const
|
|
|
|
{
|
|
|
|
return this->MainImportFile.c_str();
|
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmExportFileGenerator::GenerateImportFile()
|
|
|
|
{
|
|
|
|
// Open the output file to generate it.
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::auto_ptr<cmsys::ofstream> foutPtr;
|
2008-01-28 21:21:42 +03:00
|
|
|
if(this->AppendMode)
|
|
|
|
{
|
|
|
|
// Open for append.
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::auto_ptr<cmsys::ofstream>
|
|
|
|
ap(new cmsys::ofstream(this->MainImportFile.c_str(), std::ios::app));
|
2008-01-28 21:21:42 +03:00
|
|
|
foutPtr = ap;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Generate atomically and with copy-if-different.
|
|
|
|
cmsys::auto_ptr<cmGeneratedFileStream>
|
|
|
|
ap(new cmGeneratedFileStream(this->MainImportFile.c_str(), true));
|
|
|
|
ap->SetCopyIfDifferent(true);
|
|
|
|
foutPtr = ap;
|
|
|
|
}
|
|
|
|
if(!foutPtr.get() || !*foutPtr)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
|
|
|
std::string se = cmSystemTools::GetLastSystemError();
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "cannot write to file \"" << this->MainImportFile
|
|
|
|
<< "\": " << se;
|
|
|
|
cmSystemTools::Error(e.str().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-28 21:21:42 +03:00
|
|
|
std::ostream& os = *foutPtr;
|
2008-01-28 16:38:36 +03:00
|
|
|
|
2008-04-27 15:30:46 +04:00
|
|
|
// Protect that file against use with older CMake versions.
|
|
|
|
os << "# Generated by CMake " << cmVersion::GetCMakeVersion() << "\n\n";
|
2013-01-20 21:02:13 +04:00
|
|
|
os << "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.5)\n"
|
|
|
|
<< " message(FATAL_ERROR \"CMake >= 2.6.0 required\")\n"
|
|
|
|
<< "endif()\n";
|
2008-04-27 15:30:46 +04:00
|
|
|
|
2008-03-31 21:48:50 +04:00
|
|
|
// Isolate the file policy level.
|
|
|
|
// We use 2.6 here instead of the current version because newer
|
|
|
|
// versions of CMake should be able to export files imported by 2.6
|
|
|
|
// until the import format changes.
|
2013-01-20 21:02:13 +04:00
|
|
|
os << "cmake_policy(PUSH)\n"
|
|
|
|
<< "cmake_policy(VERSION 2.6)\n";
|
2008-03-31 21:48:50 +04:00
|
|
|
|
|
|
|
// Start with the import file header.
|
2008-01-28 16:38:36 +03:00
|
|
|
this->GenerateImportHeaderCode(os);
|
|
|
|
|
|
|
|
// Create all the imported targets.
|
|
|
|
bool result = this->GenerateMainFile(os);
|
|
|
|
|
|
|
|
// End with the import file footer.
|
|
|
|
this->GenerateImportFooterCode(os);
|
2013-01-20 21:02:13 +04:00
|
|
|
os << "cmake_policy(POP)\n";
|
2008-01-28 16:38:36 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmExportFileGenerator::GenerateImportConfig(std::ostream& os,
|
2013-01-13 12:44:52 +04:00
|
|
|
const char* config,
|
|
|
|
std::vector<std::string> &missingTargets)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
|
|
|
// Construct the property configuration suffix.
|
|
|
|
std::string suffix = "_";
|
|
|
|
if(config && *config)
|
|
|
|
{
|
|
|
|
suffix += cmSystemTools::UpperCase(config);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
suffix += "NOCONFIG";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the per-config target information.
|
2013-01-13 12:44:52 +04:00
|
|
|
this->GenerateImportTargetsConfig(os, config, suffix, missingTargets);
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
|
2013-01-12 15:13:19 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName,
|
|
|
|
cmTarget *target,
|
|
|
|
ImportPropertyMap &properties)
|
|
|
|
{
|
|
|
|
const char *input = target->GetProperty(propName);
|
|
|
|
if (input)
|
|
|
|
{
|
|
|
|
properties[propName] = input;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-11 02:05:11 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName,
|
|
|
|
const char *outputName,
|
|
|
|
cmTarget *target,
|
|
|
|
cmGeneratorExpression::PreprocessContext preprocessRule,
|
|
|
|
ImportPropertyMap &properties,
|
|
|
|
std::vector<std::string> &missingTargets)
|
|
|
|
{
|
|
|
|
const char *input = target->GetProperty(propName);
|
|
|
|
if (input)
|
|
|
|
{
|
|
|
|
if (!*input)
|
|
|
|
{
|
|
|
|
// Set to empty
|
|
|
|
properties[outputName] = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string prepro = cmGeneratorExpression::Preprocess(input,
|
|
|
|
preprocessRule);
|
|
|
|
if (!prepro.empty())
|
|
|
|
{
|
2013-02-12 14:56:58 +04:00
|
|
|
this->ResolveTargetsInGeneratorExpressions(prepro, target,
|
2012-12-11 02:05:11 +04:00
|
|
|
missingTargets);
|
|
|
|
properties[outputName] = prepro;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-04 18:47:57 +04:00
|
|
|
void cmExportFileGenerator::GenerateRequiredCMakeVersion(std::ostream& os,
|
|
|
|
const char *versionString)
|
|
|
|
{
|
|
|
|
os << "if(CMAKE_VERSION VERSION_LESS " << versionString << ")\n"
|
|
|
|
" message(FATAL_ERROR \"This file relies on consumers using "
|
|
|
|
"CMake " << versionString << " or greater.\")\n"
|
|
|
|
"endif()\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmExportFileGenerator::PopulateInterfaceLinkLibrariesProperty(
|
|
|
|
cmTarget *target,
|
|
|
|
cmGeneratorExpression::PreprocessContext preprocessRule,
|
|
|
|
ImportPropertyMap &properties,
|
|
|
|
std::vector<std::string> &missingTargets)
|
|
|
|
{
|
2013-11-02 22:49:49 +04:00
|
|
|
if(!target->IsLinkable())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-04 18:47:57 +04:00
|
|
|
const char *input = target->GetProperty("INTERFACE_LINK_LIBRARIES");
|
|
|
|
if (input)
|
|
|
|
{
|
|
|
|
std::string prepro = cmGeneratorExpression::Preprocess(input,
|
|
|
|
preprocessRule);
|
|
|
|
if (!prepro.empty())
|
|
|
|
{
|
|
|
|
this->ResolveTargetsInGeneratorExpressions(prepro, target,
|
|
|
|
missingTargets,
|
|
|
|
ReplaceFreeTargets);
|
|
|
|
properties["INTERFACE_LINK_LIBRARIES"] = prepro;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-25 00:18:17 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
static bool isSubDirectory(const char* a, const char* b)
|
|
|
|
{
|
|
|
|
return (cmSystemTools::ComparePath(a, b) ||
|
|
|
|
cmSystemTools::IsSubDirectory(a, b));
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
static bool checkInterfaceDirs(const std::string &prepro,
|
|
|
|
cmTarget *target)
|
|
|
|
{
|
|
|
|
const char* installDir =
|
|
|
|
target->GetMakefile()->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
|
|
|
|
const char* topSourceDir = target->GetMakefile()->GetHomeDirectory();
|
|
|
|
const char* topBinaryDir = target->GetMakefile()->GetHomeOutputDirectory();
|
|
|
|
|
|
|
|
std::vector<std::string> parts;
|
|
|
|
cmGeneratorExpression::Split(prepro, parts);
|
|
|
|
|
|
|
|
const bool inSourceBuild = strcmp(topSourceDir, topBinaryDir) == 0;
|
|
|
|
|
2013-11-26 14:24:47 +04:00
|
|
|
bool hadFatalError = false;
|
|
|
|
|
2013-03-25 00:18:17 +04:00
|
|
|
for(std::vector<std::string>::iterator li = parts.begin();
|
|
|
|
li != parts.end(); ++li)
|
|
|
|
{
|
2013-11-26 14:24:47 +04:00
|
|
|
size_t genexPos = cmGeneratorExpression::Find(*li);
|
|
|
|
if (genexPos == 0)
|
2013-03-25 00:18:17 +04:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-26 14:24:47 +04:00
|
|
|
cmake::MessageType messageType = cmake::FATAL_ERROR;
|
|
|
|
cmOStringStream e;
|
|
|
|
if (genexPos != std::string::npos)
|
|
|
|
{
|
|
|
|
switch (target->GetPolicyStatusCMP0041())
|
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
|
|
|
messageType = cmake::WARNING;
|
|
|
|
e << target->GetMakefile()->GetPolicies()
|
|
|
|
->GetPolicyWarning(cmPolicies::CMP0041) << "\n";
|
|
|
|
break;
|
|
|
|
case cmPolicies::OLD:
|
|
|
|
continue;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
hadFatalError = true;
|
|
|
|
break; // Issue fatal message.
|
|
|
|
}
|
|
|
|
}
|
2013-11-20 05:12:00 +04:00
|
|
|
if (cmHasLiteralPrefix(li->c_str(), "${_IMPORT_PREFIX}"))
|
2013-03-25 00:18:17 +04:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!cmSystemTools::FileIsFullPath(li->c_str()))
|
|
|
|
{
|
|
|
|
e << "Target \"" << target->GetName() << "\" "
|
|
|
|
"INTERFACE_INCLUDE_DIRECTORIES property contains relative path:\n"
|
|
|
|
" \"" << *li << "\"";
|
2013-11-26 14:24:47 +04:00
|
|
|
target->GetMakefile()->IssueMessage(messageType, e.str().c_str());
|
2013-03-25 00:18:17 +04:00
|
|
|
}
|
|
|
|
if (isSubDirectory(li->c_str(), installDir))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isSubDirectory(li->c_str(), topBinaryDir))
|
|
|
|
{
|
|
|
|
e << "Target \"" << target->GetName() << "\" "
|
|
|
|
"INTERFACE_INCLUDE_DIRECTORIES property contains path:\n"
|
|
|
|
" \"" << *li << "\"\nwhich is prefixed in the build directory.";
|
2013-11-26 14:24:47 +04:00
|
|
|
target->GetMakefile()->IssueMessage(messageType, e.str().c_str());
|
2013-03-25 00:18:17 +04:00
|
|
|
}
|
|
|
|
if (!inSourceBuild)
|
|
|
|
{
|
|
|
|
if (isSubDirectory(li->c_str(), topSourceDir))
|
|
|
|
{
|
|
|
|
e << "Target \"" << target->GetName() << "\" "
|
|
|
|
"INTERFACE_INCLUDE_DIRECTORIES property contains path:\n"
|
|
|
|
" \"" << *li << "\"\nwhich is prefixed in the source directory.";
|
2013-11-26 14:24:47 +04:00
|
|
|
target->GetMakefile()->IssueMessage(messageType, e.str().c_str());
|
2013-03-25 00:18:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-26 14:24:47 +04:00
|
|
|
return !hadFatalError;
|
2013-03-25 00:18:17 +04:00
|
|
|
}
|
|
|
|
|
2013-11-26 13:34:44 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
static void prefixItems(std::string &exportDirs)
|
|
|
|
{
|
|
|
|
std::vector<std::string> entries;
|
|
|
|
cmGeneratorExpression::Split(exportDirs, entries);
|
|
|
|
exportDirs = "";
|
|
|
|
const char *sep = "";
|
|
|
|
for(std::vector<std::string>::const_iterator ei = entries.begin();
|
|
|
|
ei != entries.end(); ++ei)
|
|
|
|
{
|
|
|
|
exportDirs += sep;
|
|
|
|
sep = ";";
|
|
|
|
if (!cmSystemTools::FileIsFullPath(ei->c_str())
|
|
|
|
&& ei->find("${_IMPORT_PREFIX}") == std::string::npos)
|
|
|
|
{
|
|
|
|
exportDirs += "${_IMPORT_PREFIX}/";
|
|
|
|
}
|
|
|
|
exportDirs += *ei;
|
|
|
|
}
|
2013-03-25 00:18:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
|
2013-01-05 15:13:49 +04:00
|
|
|
cmTargetExport *tei,
|
2013-03-25 00:18:17 +04:00
|
|
|
cmGeneratorExpression::PreprocessContext preprocessRule,
|
|
|
|
ImportPropertyMap &properties,
|
|
|
|
std::vector<std::string> &missingTargets)
|
|
|
|
{
|
2013-01-05 15:13:49 +04:00
|
|
|
cmTarget *target = tei->Target;
|
2013-03-25 00:18:17 +04:00
|
|
|
assert(preprocessRule == cmGeneratorExpression::InstallInterface);
|
|
|
|
|
|
|
|
const char *propName = "INTERFACE_INCLUDE_DIRECTORIES";
|
|
|
|
const char *input = target->GetProperty(propName);
|
2013-07-31 18:40:35 +04:00
|
|
|
|
|
|
|
cmListFileBacktrace lfbt;
|
|
|
|
cmGeneratorExpression ge(lfbt);
|
|
|
|
|
2013-11-26 13:39:23 +04:00
|
|
|
std::string dirs = cmGeneratorExpression::Preprocess(
|
|
|
|
tei->InterfaceIncludeDirectories,
|
|
|
|
preprocessRule,
|
|
|
|
true);
|
2013-07-31 18:40:35 +04:00
|
|
|
this->ReplaceInstallPrefix(dirs);
|
|
|
|
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs);
|
|
|
|
std::string exportDirs = cge->Evaluate(target->GetMakefile(), 0,
|
|
|
|
false, target);
|
|
|
|
|
|
|
|
if (cge->GetHadContextSensitiveCondition())
|
|
|
|
{
|
|
|
|
cmMakefile* mf = target->GetMakefile();
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "Target \"" << target->GetName() << "\" is installed with "
|
|
|
|
"INCLUDES DESTINATION set to a context sensitive path. Paths which "
|
|
|
|
"depend on the configuration, policy values or the link interface are "
|
|
|
|
"not supported. Consider using target_include_directories instead.";
|
|
|
|
mf->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!input && exportDirs.empty())
|
2013-03-25 00:18:17 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-07-31 18:40:35 +04:00
|
|
|
if ((input && !*input) && exportDirs.empty())
|
2013-03-25 00:18:17 +04:00
|
|
|
{
|
|
|
|
// Set to empty
|
|
|
|
properties[propName] = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-26 13:34:44 +04:00
|
|
|
prefixItems(exportDirs);
|
|
|
|
|
2013-01-05 15:13:49 +04:00
|
|
|
std::string includes = (input?input:"");
|
|
|
|
const char* sep = input ? ";" : "";
|
2013-07-31 18:40:35 +04:00
|
|
|
includes += sep + exportDirs;
|
2013-01-05 15:13:49 +04:00
|
|
|
std::string prepro = cmGeneratorExpression::Preprocess(includes,
|
2013-07-25 11:05:03 +04:00
|
|
|
preprocessRule,
|
|
|
|
true);
|
2013-03-25 00:18:17 +04:00
|
|
|
if (!prepro.empty())
|
|
|
|
{
|
|
|
|
this->ResolveTargetsInGeneratorExpressions(prepro, target,
|
|
|
|
missingTargets);
|
|
|
|
|
|
|
|
if (!checkInterfaceDirs(prepro, target))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
properties[propName] = prepro;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-11 02:05:11 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName,
|
|
|
|
cmTarget *target,
|
|
|
|
cmGeneratorExpression::PreprocessContext preprocessRule,
|
|
|
|
ImportPropertyMap &properties,
|
|
|
|
std::vector<std::string> &missingTargets)
|
|
|
|
{
|
|
|
|
this->PopulateInterfaceProperty(propName, propName, target, preprocessRule,
|
|
|
|
properties, missingTargets);
|
|
|
|
}
|
|
|
|
|
2013-01-20 20:09:29 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2013-12-10 18:30:41 +04:00
|
|
|
void getPropertyContents(cmTarget const* tgt, const char *prop,
|
2013-01-20 20:09:29 +04:00
|
|
|
std::set<std::string> &ifaceProperties)
|
|
|
|
{
|
|
|
|
const char *p = tgt->GetProperty(prop);
|
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::vector<std::string> content;
|
|
|
|
cmSystemTools::ExpandListArgument(p, content);
|
|
|
|
for (std::vector<std::string>::const_iterator ci = content.begin();
|
|
|
|
ci != content.end(); ++ci)
|
|
|
|
{
|
|
|
|
ifaceProperties.insert(*ci);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void getCompatibleInterfaceProperties(cmTarget *target,
|
|
|
|
std::set<std::string> &ifaceProperties,
|
|
|
|
const char *config)
|
|
|
|
{
|
|
|
|
cmComputeLinkInformation *info = target->GetLinkInformation(config);
|
|
|
|
|
2013-07-23 01:25:21 +04:00
|
|
|
if (!info)
|
|
|
|
{
|
2013-11-20 15:44:04 +04:00
|
|
|
cmMakefile* mf = target->GetMakefile();
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "Exporting the target \"" << target->GetName() << "\" is not "
|
|
|
|
"allowed since its linker language cannot be determined";
|
|
|
|
mf->IssueMessage(cmake::FATAL_ERROR, e.str());
|
2013-07-23 01:25:21 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-20 20:09:29 +04:00
|
|
|
const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
|
|
|
|
|
|
|
|
for(cmComputeLinkInformation::ItemVector::const_iterator li =
|
|
|
|
deps.begin();
|
|
|
|
li != deps.end(); ++li)
|
|
|
|
{
|
|
|
|
if (!li->Target)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
getPropertyContents(li->Target,
|
|
|
|
"COMPATIBLE_INTERFACE_BOOL",
|
|
|
|
ifaceProperties);
|
2013-01-06 16:49:20 +04:00
|
|
|
getPropertyContents(li->Target,
|
|
|
|
"COMPATIBLE_INTERFACE_STRING",
|
|
|
|
ifaceProperties);
|
cmTarget: Add interface for compatible numeric properties
When using the boost MPL library, one can set a define to increase
the limit of how many variadic elements should be supported. The
default for BOOST_MPL_LIMIT_VECTOR_SIZE is 20:
http://www.boost.org/doc/libs/1_36_0/libs/mpl/doc/refmanual/limit-vector-size.html
If the foo library requires that to be set to 30, and the independent
bar library requires it to be set to 40, consumers of both need to set
it to 40.
add_library(foo INTERFACE)
set_property(TARGET foo PROPERTY INTERFACE_boost_mpl_vector_size 30)
set_property(TARGET foo PROPERTY COMPATIBLE_INTERFACE_NUMBER_MAX boost_mpl_vector_size)
target_compile_definitions(foo INTERFACE BOOST_MPL_LIMIT_VECTOR_SIZE=$<TARGET_PROPERTY:boost_mpl_vector_size>)
add_library(bar INTERFACE)
set_property(TARGET bar PROPERTY INTERFACE_boost_mpl_vector_size 40)
# Technically the next two lines are redundant, but as foo and bar are
# independent, they both set these interfaces.
set_property(TARGET bar PROPERTY COMPATIBLE_INTERFACE_NUMBER_MAX boost_mpl_vector_size)
target_compile_definitions(bar INTERFACE BOOST_MPL_LIMIT_VECTOR_SIZE=$<TARGET_PROPERTY:boost_mpl_vector_size>)
add_executable(user)
target_link_libraries(user foo bar)
Because the TARGET_PROPERTY reads the boost_mpl_vector_size property
from the HEAD of the dependency graph (the user target), and because
that property appears in the COMPATIBLE_INTERFACE_NUMBER_MAX of
the dependencies of the user target, the maximum value for it is
chosen for the compile definition, ie, 40.
There are also use-cases for choosing the minimum value of a number.
In Qt, deprecated API can be disabled by version. Setting the
definition QT_DISABLE_DEPRECATED_BEFORE=0 disables no deprecated
API. Setting it to 0x501000 disables API which was deprecated before
Qt 5.1 etc.
If two dependencies require the use of API which was deprecated in
different Qt versions, then COMPATIBLE_INTERFACE_NUMBER_MIN can be
used to ensure that both can compile.
2013-10-22 21:51:36 +04:00
|
|
|
getPropertyContents(li->Target,
|
|
|
|
"COMPATIBLE_INTERFACE_NUMBER_MIN",
|
|
|
|
ifaceProperties);
|
|
|
|
getPropertyContents(li->Target,
|
|
|
|
"COMPATIBLE_INTERFACE_NUMBER_MAX",
|
|
|
|
ifaceProperties);
|
2013-01-20 20:09:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmExportFileGenerator::PopulateCompatibleInterfaceProperties(
|
|
|
|
cmTarget *target,
|
|
|
|
ImportPropertyMap &properties)
|
|
|
|
{
|
|
|
|
this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_BOOL",
|
|
|
|
target, properties);
|
2013-01-06 16:49:20 +04:00
|
|
|
this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_STRING",
|
|
|
|
target, properties);
|
cmTarget: Add interface for compatible numeric properties
When using the boost MPL library, one can set a define to increase
the limit of how many variadic elements should be supported. The
default for BOOST_MPL_LIMIT_VECTOR_SIZE is 20:
http://www.boost.org/doc/libs/1_36_0/libs/mpl/doc/refmanual/limit-vector-size.html
If the foo library requires that to be set to 30, and the independent
bar library requires it to be set to 40, consumers of both need to set
it to 40.
add_library(foo INTERFACE)
set_property(TARGET foo PROPERTY INTERFACE_boost_mpl_vector_size 30)
set_property(TARGET foo PROPERTY COMPATIBLE_INTERFACE_NUMBER_MAX boost_mpl_vector_size)
target_compile_definitions(foo INTERFACE BOOST_MPL_LIMIT_VECTOR_SIZE=$<TARGET_PROPERTY:boost_mpl_vector_size>)
add_library(bar INTERFACE)
set_property(TARGET bar PROPERTY INTERFACE_boost_mpl_vector_size 40)
# Technically the next two lines are redundant, but as foo and bar are
# independent, they both set these interfaces.
set_property(TARGET bar PROPERTY COMPATIBLE_INTERFACE_NUMBER_MAX boost_mpl_vector_size)
target_compile_definitions(bar INTERFACE BOOST_MPL_LIMIT_VECTOR_SIZE=$<TARGET_PROPERTY:boost_mpl_vector_size>)
add_executable(user)
target_link_libraries(user foo bar)
Because the TARGET_PROPERTY reads the boost_mpl_vector_size property
from the HEAD of the dependency graph (the user target), and because
that property appears in the COMPATIBLE_INTERFACE_NUMBER_MAX of
the dependencies of the user target, the maximum value for it is
chosen for the compile definition, ie, 40.
There are also use-cases for choosing the minimum value of a number.
In Qt, deprecated API can be disabled by version. Setting the
definition QT_DISABLE_DEPRECATED_BEFORE=0 disables no deprecated
API. Setting it to 0x501000 disables API which was deprecated before
Qt 5.1 etc.
If two dependencies require the use of API which was deprecated in
different Qt versions, then COMPATIBLE_INTERFACE_NUMBER_MIN can be
used to ensure that both can compile.
2013-10-22 21:51:36 +04:00
|
|
|
this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_NUMBER_MIN",
|
|
|
|
target, properties);
|
|
|
|
this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_NUMBER_MAX",
|
|
|
|
target, properties);
|
2013-01-20 20:09:29 +04:00
|
|
|
|
|
|
|
std::set<std::string> ifaceProperties;
|
|
|
|
|
|
|
|
getPropertyContents(target, "COMPATIBLE_INTERFACE_BOOL", ifaceProperties);
|
2013-01-06 16:49:20 +04:00
|
|
|
getPropertyContents(target, "COMPATIBLE_INTERFACE_STRING", ifaceProperties);
|
cmTarget: Add interface for compatible numeric properties
When using the boost MPL library, one can set a define to increase
the limit of how many variadic elements should be supported. The
default for BOOST_MPL_LIMIT_VECTOR_SIZE is 20:
http://www.boost.org/doc/libs/1_36_0/libs/mpl/doc/refmanual/limit-vector-size.html
If the foo library requires that to be set to 30, and the independent
bar library requires it to be set to 40, consumers of both need to set
it to 40.
add_library(foo INTERFACE)
set_property(TARGET foo PROPERTY INTERFACE_boost_mpl_vector_size 30)
set_property(TARGET foo PROPERTY COMPATIBLE_INTERFACE_NUMBER_MAX boost_mpl_vector_size)
target_compile_definitions(foo INTERFACE BOOST_MPL_LIMIT_VECTOR_SIZE=$<TARGET_PROPERTY:boost_mpl_vector_size>)
add_library(bar INTERFACE)
set_property(TARGET bar PROPERTY INTERFACE_boost_mpl_vector_size 40)
# Technically the next two lines are redundant, but as foo and bar are
# independent, they both set these interfaces.
set_property(TARGET bar PROPERTY COMPATIBLE_INTERFACE_NUMBER_MAX boost_mpl_vector_size)
target_compile_definitions(bar INTERFACE BOOST_MPL_LIMIT_VECTOR_SIZE=$<TARGET_PROPERTY:boost_mpl_vector_size>)
add_executable(user)
target_link_libraries(user foo bar)
Because the TARGET_PROPERTY reads the boost_mpl_vector_size property
from the HEAD of the dependency graph (the user target), and because
that property appears in the COMPATIBLE_INTERFACE_NUMBER_MAX of
the dependencies of the user target, the maximum value for it is
chosen for the compile definition, ie, 40.
There are also use-cases for choosing the minimum value of a number.
In Qt, deprecated API can be disabled by version. Setting the
definition QT_DISABLE_DEPRECATED_BEFORE=0 disables no deprecated
API. Setting it to 0x501000 disables API which was deprecated before
Qt 5.1 etc.
If two dependencies require the use of API which was deprecated in
different Qt versions, then COMPATIBLE_INTERFACE_NUMBER_MIN can be
used to ensure that both can compile.
2013-10-22 21:51:36 +04:00
|
|
|
getPropertyContents(target, "COMPATIBLE_INTERFACE_NUMBER_MIN",
|
|
|
|
ifaceProperties);
|
|
|
|
getPropertyContents(target, "COMPATIBLE_INTERFACE_NUMBER_MAX",
|
|
|
|
ifaceProperties);
|
2013-01-20 20:09:29 +04:00
|
|
|
|
2013-11-20 15:44:04 +04:00
|
|
|
if (target->GetType() != cmTarget::INTERFACE_LIBRARY)
|
|
|
|
{
|
|
|
|
getCompatibleInterfaceProperties(target, ifaceProperties, 0);
|
2013-01-20 20:09:29 +04:00
|
|
|
|
2013-11-20 15:44:04 +04:00
|
|
|
std::vector<std::string> configNames;
|
|
|
|
target->GetMakefile()->GetConfigurations(configNames);
|
2013-01-20 20:09:29 +04:00
|
|
|
|
2013-11-20 15:44:04 +04:00
|
|
|
for (std::vector<std::string>::const_iterator ci = configNames.begin();
|
|
|
|
ci != configNames.end(); ++ci)
|
|
|
|
{
|
|
|
|
getCompatibleInterfaceProperties(target, ifaceProperties, ci->c_str());
|
|
|
|
}
|
2013-01-20 20:09:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (std::set<std::string>::const_iterator it = ifaceProperties.begin();
|
|
|
|
it != ifaceProperties.end(); ++it)
|
|
|
|
{
|
|
|
|
this->PopulateInterfaceProperty(("INTERFACE_" + *it).c_str(),
|
|
|
|
target, properties);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-11 02:05:11 +04:00
|
|
|
//----------------------------------------------------------------------------
|
2013-10-30 01:21:20 +04:00
|
|
|
void cmExportFileGenerator::GenerateInterfaceProperties(cmTarget const* target,
|
2012-12-11 02:05:11 +04:00
|
|
|
std::ostream& os,
|
|
|
|
const ImportPropertyMap &properties)
|
|
|
|
{
|
|
|
|
if (!properties.empty())
|
|
|
|
{
|
|
|
|
std::string targetName = this->Namespace;
|
2013-05-17 12:12:02 +04:00
|
|
|
targetName += target->GetExportName();
|
2013-02-12 15:00:41 +04:00
|
|
|
os << "set_target_properties(" << targetName << " PROPERTIES\n";
|
2012-12-11 02:05:11 +04:00
|
|
|
for(ImportPropertyMap::const_iterator pi = properties.begin();
|
|
|
|
pi != properties.end(); ++pi)
|
|
|
|
{
|
2013-02-12 15:00:41 +04:00
|
|
|
os << " " << pi->first << " \"" << pi->second << "\"\n";
|
2012-12-11 02:05:11 +04:00
|
|
|
}
|
2013-02-12 15:00:41 +04:00
|
|
|
os << ")\n\n";
|
2012-12-11 02:05:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-08 23:58:33 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
cmExportFileGenerator::AddTargetNamespace(std::string &input,
|
|
|
|
cmTarget* target,
|
|
|
|
std::vector<std::string> &missingTargets)
|
|
|
|
{
|
|
|
|
cmMakefile *mf = target->GetMakefile();
|
|
|
|
|
|
|
|
cmTarget *tgt = mf->FindTargetToUse(input.c_str());
|
|
|
|
if (!tgt)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tgt->IsImported())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(this->ExportedTargets.find(tgt) != this->ExportedTargets.end())
|
|
|
|
{
|
2013-05-17 12:12:02 +04:00
|
|
|
input = this->Namespace + tgt->GetExportName();
|
2013-01-08 23:58:33 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string namespacedTarget;
|
|
|
|
this->HandleMissingTarget(namespacedTarget, missingTargets,
|
|
|
|
mf, target, tgt);
|
|
|
|
if (!namespacedTarget.empty())
|
|
|
|
{
|
|
|
|
input = namespacedTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-11 02:07:09 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmExportFileGenerator::ResolveTargetsInGeneratorExpressions(
|
2013-01-04 18:56:13 +04:00
|
|
|
std::string &input,
|
2013-02-12 14:56:58 +04:00
|
|
|
cmTarget* target,
|
2013-01-04 18:56:13 +04:00
|
|
|
std::vector<std::string> &missingTargets,
|
|
|
|
FreeTargetsReplace replace)
|
|
|
|
{
|
|
|
|
if (replace == NoReplaceFreeTargets)
|
|
|
|
{
|
2013-02-12 14:56:58 +04:00
|
|
|
this->ResolveTargetsInGeneratorExpression(input, target, missingTargets);
|
2013-01-04 18:56:13 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::vector<std::string> parts;
|
|
|
|
cmGeneratorExpression::Split(input, parts);
|
|
|
|
|
|
|
|
std::string sep;
|
|
|
|
input = "";
|
|
|
|
for(std::vector<std::string>::iterator li = parts.begin();
|
|
|
|
li != parts.end(); ++li)
|
|
|
|
{
|
2013-02-06 16:18:10 +04:00
|
|
|
if (cmGeneratorExpression::Find(*li) == std::string::npos)
|
2013-01-04 18:56:13 +04:00
|
|
|
{
|
|
|
|
this->AddTargetNamespace(*li, target, missingTargets);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->ResolveTargetsInGeneratorExpression(
|
|
|
|
*li,
|
2013-02-12 14:56:58 +04:00
|
|
|
target,
|
2013-01-04 18:56:13 +04:00
|
|
|
missingTargets);
|
|
|
|
}
|
|
|
|
input += sep + *li;
|
|
|
|
sep = ";";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
|
2012-12-11 02:07:09 +04:00
|
|
|
std::string &input,
|
2013-02-12 14:56:58 +04:00
|
|
|
cmTarget* target,
|
2012-12-11 02:07:09 +04:00
|
|
|
std::vector<std::string> &missingTargets)
|
|
|
|
{
|
|
|
|
std::string::size_type pos = 0;
|
|
|
|
std::string::size_type lastPos = pos;
|
|
|
|
|
|
|
|
cmMakefile *mf = target->GetMakefile();
|
|
|
|
|
|
|
|
while((pos = input.find("$<TARGET_PROPERTY:", lastPos)) != input.npos)
|
|
|
|
{
|
|
|
|
std::string::size_type nameStartPos = pos +
|
|
|
|
sizeof("$<TARGET_PROPERTY:") - 1;
|
|
|
|
std::string::size_type closePos = input.find(">", nameStartPos);
|
|
|
|
std::string::size_type commaPos = input.find(",", nameStartPos);
|
|
|
|
std::string::size_type nextOpenPos = input.find("$<", nameStartPos);
|
|
|
|
if (commaPos == input.npos // Implied 'this' target
|
|
|
|
|| closePos == input.npos // Imcomplete expression.
|
|
|
|
|| closePos < commaPos // Implied 'this' target
|
|
|
|
|| nextOpenPos < commaPos) // Non-literal
|
|
|
|
{
|
|
|
|
lastPos = nameStartPos;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-08 23:58:33 +04:00
|
|
|
std::string targetName = input.substr(nameStartPos,
|
2012-12-11 02:07:09 +04:00
|
|
|
commaPos - nameStartPos);
|
|
|
|
|
2013-01-26 14:04:12 +04:00
|
|
|
if (this->AddTargetNamespace(targetName, target, missingTargets))
|
2012-12-11 02:07:09 +04:00
|
|
|
{
|
2013-01-26 14:04:12 +04:00
|
|
|
input.replace(nameStartPos, commaPos - nameStartPos, targetName);
|
2012-12-11 02:07:09 +04:00
|
|
|
}
|
2013-01-31 02:31:54 +04:00
|
|
|
lastPos = nameStartPos + targetName.size() + 1;
|
2012-12-11 02:07:09 +04:00
|
|
|
}
|
|
|
|
|
2013-01-26 14:04:12 +04:00
|
|
|
std::string errorString;
|
2012-12-11 02:07:09 +04:00
|
|
|
pos = 0;
|
|
|
|
lastPos = pos;
|
|
|
|
while((pos = input.find("$<TARGET_NAME:", lastPos)) != input.npos)
|
|
|
|
{
|
|
|
|
std::string::size_type nameStartPos = pos + sizeof("$<TARGET_NAME:") - 1;
|
|
|
|
std::string::size_type endPos = input.find(">", nameStartPos);
|
|
|
|
if (endPos == input.npos)
|
|
|
|
{
|
|
|
|
errorString = "$<TARGET_NAME:...> expression incomplete";
|
2013-01-08 23:58:33 +04:00
|
|
|
break;
|
2012-12-11 02:07:09 +04:00
|
|
|
}
|
2013-01-08 23:58:33 +04:00
|
|
|
std::string targetName = input.substr(nameStartPos,
|
2012-12-11 02:07:09 +04:00
|
|
|
endPos - nameStartPos);
|
2013-01-09 00:06:24 +04:00
|
|
|
if(targetName.find("$<") != input.npos)
|
2012-12-11 02:07:09 +04:00
|
|
|
{
|
|
|
|
errorString = "$<TARGET_NAME:...> requires its parameter to be a "
|
|
|
|
"literal.";
|
2013-01-08 23:58:33 +04:00
|
|
|
break;
|
2012-12-11 02:07:09 +04:00
|
|
|
}
|
2013-01-08 23:58:33 +04:00
|
|
|
if (!this->AddTargetNamespace(targetName, target, missingTargets))
|
2012-12-11 02:07:09 +04:00
|
|
|
{
|
|
|
|
errorString = "$<TARGET_NAME:...> requires its parameter to be a "
|
|
|
|
"reachable target.";
|
|
|
|
break;
|
|
|
|
}
|
2013-01-08 23:58:33 +04:00
|
|
|
input.replace(pos, endPos - pos + 1, targetName);
|
|
|
|
lastPos = endPos;
|
2012-12-11 02:07:09 +04:00
|
|
|
}
|
2013-01-27 12:43:44 +04:00
|
|
|
|
|
|
|
this->ReplaceInstallPrefix(input);
|
|
|
|
|
2012-12-11 02:07:09 +04:00
|
|
|
if (!errorString.empty())
|
|
|
|
{
|
|
|
|
mf->IssueMessage(cmake::FATAL_ERROR, errorString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-27 12:43:44 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmExportFileGenerator::ReplaceInstallPrefix(std::string &)
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
2013-01-04 18:58:16 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmExportFileGenerator
|
|
|
|
::SetImportLinkInterface(const char* config, std::string const& suffix,
|
|
|
|
cmGeneratorExpression::PreprocessContext preprocessRule,
|
|
|
|
cmTarget* target, ImportPropertyMap& properties,
|
|
|
|
std::vector<std::string>& missingTargets)
|
|
|
|
{
|
|
|
|
// Add the transitive link dependencies for this configuration.
|
|
|
|
cmTarget::LinkInterface const* iface = target->GetLinkInterface(config,
|
|
|
|
target);
|
|
|
|
if (!iface)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
Allow generator expressions in LINK_INTERFACE_LIBRARIES.
The Config and IMPORTED_ variants may also contain generator
expressions.
If 'the implementation is the interface', then the result of
evaluating the expressions at generate time is used to populate
the IMPORTED_LINK_INTERFACE_LIBRARIES property.
1) In the case of non-static libraries, this is fine because the
user still has the option to populate the LINK_INTERFACE_LIBRARIES
with generator expressions if that is what is wanted.
2) In the case of static libraries, this prevents a footgun,
enforcing that the interface and the implementation are really
the same.
Otherwise, the LINK_LIBRARIES could contain a generator
expression which is evaluated with a different context at build
time, and when used as an imported target. That would mean that the
result of evaluating the INTERFACE_LINK_LIBRARIES property for
a static library would not necessarily be the 'link implementation'.
For example:
add_library(libone STATIC libone.cpp)
add_library(libtwo STATIC libtwo.cpp)
add_library(libthree STATIC libthree.cpp)
target_link_libraries(libtwo
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>:libone>)
target_link_libraries(libthree libtwo)
If the LINK_LIBRARIES content was simply copied to the
IMPORTED_LINK_INTERFACE_LIBRARIES, then libthree links to libone, but
executables linking to libthree will not link to libone.
3) As the 'implementation is the interface' concept is to be
deprecated in the future anyway, this should be fine.
2013-01-04 16:36:18 +04:00
|
|
|
|
|
|
|
if (iface->ImplementationIsInterface)
|
|
|
|
{
|
2013-11-02 20:36:23 +04:00
|
|
|
// Policy CMP0022 must not be NEW.
|
Allow generator expressions in LINK_INTERFACE_LIBRARIES.
The Config and IMPORTED_ variants may also contain generator
expressions.
If 'the implementation is the interface', then the result of
evaluating the expressions at generate time is used to populate
the IMPORTED_LINK_INTERFACE_LIBRARIES property.
1) In the case of non-static libraries, this is fine because the
user still has the option to populate the LINK_INTERFACE_LIBRARIES
with generator expressions if that is what is wanted.
2) In the case of static libraries, this prevents a footgun,
enforcing that the interface and the implementation are really
the same.
Otherwise, the LINK_LIBRARIES could contain a generator
expression which is evaluated with a different context at build
time, and when used as an imported target. That would mean that the
result of evaluating the INTERFACE_LINK_LIBRARIES property for
a static library would not necessarily be the 'link implementation'.
For example:
add_library(libone STATIC libone.cpp)
add_library(libtwo STATIC libtwo.cpp)
add_library(libthree STATIC libthree.cpp)
target_link_libraries(libtwo
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>:libone>)
target_link_libraries(libthree libtwo)
If the LINK_LIBRARIES content was simply copied to the
IMPORTED_LINK_INTERFACE_LIBRARIES, then libthree links to libone, but
executables linking to libthree will not link to libone.
3) As the 'implementation is the interface' concept is to be
deprecated in the future anyway, this should be fine.
2013-01-04 16:36:18 +04:00
|
|
|
this->SetImportLinkProperty(suffix, target,
|
|
|
|
"IMPORTED_LINK_INTERFACE_LIBRARIES",
|
|
|
|
iface->Libraries, properties, missingTargets);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *propContent;
|
|
|
|
|
|
|
|
if (const char *prop_suffixed = target->GetProperty(
|
|
|
|
("LINK_INTERFACE_LIBRARIES" + suffix).c_str()))
|
|
|
|
{
|
|
|
|
propContent = prop_suffixed;
|
|
|
|
}
|
|
|
|
else if (const char *prop = target->GetProperty(
|
|
|
|
"LINK_INTERFACE_LIBRARIES"))
|
|
|
|
{
|
|
|
|
propContent = prop;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-04 18:47:57 +04:00
|
|
|
const bool newCMP0022Behavior =
|
|
|
|
target->GetPolicyStatusCMP0022() != cmPolicies::WARN
|
|
|
|
&& target->GetPolicyStatusCMP0022() != cmPolicies::OLD;
|
|
|
|
|
|
|
|
if(newCMP0022Behavior && !this->ExportOld)
|
|
|
|
{
|
|
|
|
cmMakefile *mf = target->GetMakefile();
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "Target \"" << target->GetName() << "\" has policy CMP0022 enabled, "
|
2013-07-26 14:12:13 +04:00
|
|
|
"but also has old-style LINK_INTERFACE_LIBRARIES properties "
|
2013-06-04 18:47:57 +04:00
|
|
|
"populated, but it was exported without the "
|
|
|
|
"EXPORT_LINK_INTERFACE_LIBRARIES to export the old-style properties";
|
|
|
|
mf->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Allow generator expressions in LINK_INTERFACE_LIBRARIES.
The Config and IMPORTED_ variants may also contain generator
expressions.
If 'the implementation is the interface', then the result of
evaluating the expressions at generate time is used to populate
the IMPORTED_LINK_INTERFACE_LIBRARIES property.
1) In the case of non-static libraries, this is fine because the
user still has the option to populate the LINK_INTERFACE_LIBRARIES
with generator expressions if that is what is wanted.
2) In the case of static libraries, this prevents a footgun,
enforcing that the interface and the implementation are really
the same.
Otherwise, the LINK_LIBRARIES could contain a generator
expression which is evaluated with a different context at build
time, and when used as an imported target. That would mean that the
result of evaluating the INTERFACE_LINK_LIBRARIES property for
a static library would not necessarily be the 'link implementation'.
For example:
add_library(libone STATIC libone.cpp)
add_library(libtwo STATIC libtwo.cpp)
add_library(libthree STATIC libthree.cpp)
target_link_libraries(libtwo
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>:libone>)
target_link_libraries(libthree libtwo)
If the LINK_LIBRARIES content was simply copied to the
IMPORTED_LINK_INTERFACE_LIBRARIES, then libthree links to libone, but
executables linking to libthree will not link to libone.
3) As the 'implementation is the interface' concept is to be
deprecated in the future anyway, this should be fine.
2013-01-04 16:36:18 +04:00
|
|
|
if (!*propContent)
|
|
|
|
{
|
|
|
|
properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string prepro = cmGeneratorExpression::Preprocess(propContent,
|
|
|
|
preprocessRule);
|
|
|
|
if (!prepro.empty())
|
|
|
|
{
|
2013-02-12 14:56:58 +04:00
|
|
|
this->ResolveTargetsInGeneratorExpressions(prepro, target,
|
Allow generator expressions in LINK_INTERFACE_LIBRARIES.
The Config and IMPORTED_ variants may also contain generator
expressions.
If 'the implementation is the interface', then the result of
evaluating the expressions at generate time is used to populate
the IMPORTED_LINK_INTERFACE_LIBRARIES property.
1) In the case of non-static libraries, this is fine because the
user still has the option to populate the LINK_INTERFACE_LIBRARIES
with generator expressions if that is what is wanted.
2) In the case of static libraries, this prevents a footgun,
enforcing that the interface and the implementation are really
the same.
Otherwise, the LINK_LIBRARIES could contain a generator
expression which is evaluated with a different context at build
time, and when used as an imported target. That would mean that the
result of evaluating the INTERFACE_LINK_LIBRARIES property for
a static library would not necessarily be the 'link implementation'.
For example:
add_library(libone STATIC libone.cpp)
add_library(libtwo STATIC libtwo.cpp)
add_library(libthree STATIC libthree.cpp)
target_link_libraries(libtwo
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>:libone>)
target_link_libraries(libthree libtwo)
If the LINK_LIBRARIES content was simply copied to the
IMPORTED_LINK_INTERFACE_LIBRARIES, then libthree links to libone, but
executables linking to libthree will not link to libone.
3) As the 'implementation is the interface' concept is to be
deprecated in the future anyway, this should be fine.
2013-01-04 16:36:18 +04:00
|
|
|
missingTargets,
|
|
|
|
ReplaceFreeTargets);
|
|
|
|
properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = prepro;
|
|
|
|
}
|
2013-01-04 18:58:16 +04:00
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmExportFileGenerator
|
|
|
|
::SetImportDetailProperties(const char* config, std::string const& suffix,
|
2012-09-16 00:38:30 +04:00
|
|
|
cmTarget* target, ImportPropertyMap& properties,
|
|
|
|
std::vector<std::string>& missingTargets
|
|
|
|
)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
|
|
|
// Get the makefile in which to lookup target information.
|
|
|
|
cmMakefile* mf = target->GetMakefile();
|
|
|
|
|
|
|
|
// Add the soname for unix shared libraries.
|
|
|
|
if(target->GetType() == cmTarget::SHARED_LIBRARY ||
|
|
|
|
target->GetType() == cmTarget::MODULE_LIBRARY)
|
|
|
|
{
|
|
|
|
// Check whether this is a DLL platform.
|
|
|
|
bool dll_platform =
|
|
|
|
(mf->IsOn("WIN32") || mf->IsOn("CYGWIN") || mf->IsOn("MINGW"));
|
|
|
|
if(!dll_platform)
|
|
|
|
{
|
2012-04-22 17:42:55 +04:00
|
|
|
std::string prop;
|
|
|
|
std::string value;
|
|
|
|
if(target->HasSOName(config))
|
|
|
|
{
|
2013-05-21 02:57:58 +04:00
|
|
|
if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
|
|
|
|
{
|
|
|
|
value = this->InstallNameDir(target, config);
|
|
|
|
}
|
2012-04-22 17:42:55 +04:00
|
|
|
prop = "IMPORTED_SONAME";
|
2013-05-21 02:57:58 +04:00
|
|
|
value += target->GetSOName(config);
|
2012-04-22 17:42:55 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prop = "IMPORTED_NO_SONAME";
|
|
|
|
value = "TRUE";
|
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
prop += suffix;
|
2012-04-22 17:42:55 +04:00
|
|
|
properties[prop] = value;
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the transitive link dependencies for this configuration.
|
2013-01-04 16:31:01 +04:00
|
|
|
if(cmTarget::LinkInterface const* iface = target->GetLinkInterface(config,
|
|
|
|
target))
|
2008-01-28 21:37:59 +03:00
|
|
|
{
|
2009-07-11 18:12:05 +04:00
|
|
|
this->SetImportLinkProperty(suffix, target,
|
|
|
|
"IMPORTED_LINK_INTERFACE_LANGUAGES",
|
2012-09-16 00:38:30 +04:00
|
|
|
iface->Languages, properties, missingTargets);
|
2013-01-04 18:58:16 +04:00
|
|
|
|
2013-09-24 17:06:56 +04:00
|
|
|
std::vector<std::string> dummy;
|
2008-01-31 23:45:31 +03:00
|
|
|
this->SetImportLinkProperty(suffix, target,
|
|
|
|
"IMPORTED_LINK_DEPENDENT_LIBRARIES",
|
2013-09-24 17:06:56 +04:00
|
|
|
iface->SharedDeps, properties, dummy);
|
2009-09-01 18:37:37 +04:00
|
|
|
if(iface->Multiplicity > 0)
|
|
|
|
{
|
|
|
|
std::string prop = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
|
|
|
|
prop += suffix;
|
|
|
|
cmOStringStream m;
|
|
|
|
m << iface->Multiplicity;
|
|
|
|
properties[prop] = m.str();
|
|
|
|
}
|
2008-01-31 01:25:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmExportFileGenerator
|
2008-01-31 23:45:31 +03:00
|
|
|
::SetImportLinkProperty(std::string const& suffix,
|
|
|
|
cmTarget* target,
|
|
|
|
const char* propName,
|
2013-12-31 01:01:02 +04:00
|
|
|
std::vector<std::string> const& entries,
|
2012-09-16 00:38:30 +04:00
|
|
|
ImportPropertyMap& properties,
|
|
|
|
std::vector<std::string>& missingTargets
|
|
|
|
)
|
2008-01-31 01:25:52 +03:00
|
|
|
{
|
2013-12-31 01:01:02 +04:00
|
|
|
// Skip the property if there are no entries.
|
|
|
|
if(entries.empty())
|
2008-01-31 23:45:31 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-31 01:25:52 +03:00
|
|
|
// Construct the property value.
|
2013-12-31 01:01:02 +04:00
|
|
|
std::string link_entries;
|
2008-01-31 01:25:52 +03:00
|
|
|
const char* sep = "";
|
2013-12-31 01:01:02 +04:00
|
|
|
for(std::vector<std::string>::const_iterator li = entries.begin();
|
|
|
|
li != entries.end(); ++li)
|
2008-01-31 01:25:52 +03:00
|
|
|
{
|
2008-01-31 01:57:54 +03:00
|
|
|
// Separate this from the previous entry.
|
2013-12-31 01:01:02 +04:00
|
|
|
link_entries += sep;
|
2008-01-31 01:57:54 +03:00
|
|
|
sep = ";";
|
|
|
|
|
2013-01-08 23:58:33 +04:00
|
|
|
std::string temp = *li;
|
|
|
|
this->AddTargetNamespace(temp, target, missingTargets);
|
2013-12-31 01:01:02 +04:00
|
|
|
link_entries += temp;
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Store the property.
|
2008-01-31 23:45:31 +03:00
|
|
|
std::string prop = propName;
|
2008-01-28 16:38:36 +03:00
|
|
|
prop += suffix;
|
2013-12-31 01:01:02 +04:00
|
|
|
properties[prop] = link_entries;
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
|
2012-09-15 23:55:24 +04:00
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmExportFileGenerator::GenerateImportHeaderCode(std::ostream& os,
|
|
|
|
const char* config)
|
|
|
|
{
|
|
|
|
os << "#----------------------------------------------------------------\n"
|
|
|
|
<< "# Generated CMake target import file";
|
|
|
|
if(config)
|
|
|
|
{
|
|
|
|
os << " for configuration \"" << config << "\".\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
os << ".\n";
|
|
|
|
}
|
|
|
|
os << "#----------------------------------------------------------------\n"
|
|
|
|
<< "\n";
|
|
|
|
this->GenerateImportVersionCode(os);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmExportFileGenerator::GenerateImportFooterCode(std::ostream& os)
|
|
|
|
{
|
|
|
|
os << "# Commands beyond this point should not need to know the version.\n"
|
2013-01-20 21:02:13 +04:00
|
|
|
<< "set(CMAKE_IMPORT_FILE_VERSION)\n";
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmExportFileGenerator::GenerateImportVersionCode(std::ostream& os)
|
|
|
|
{
|
|
|
|
// Store an import file format version. This will let us change the
|
|
|
|
// format later while still allowing old import files to work.
|
|
|
|
os << "# Commands may need to know the format version.\n"
|
2013-01-20 21:02:13 +04:00
|
|
|
<< "set(CMAKE_IMPORT_FILE_VERSION 1)\n"
|
2008-01-28 16:38:36 +03:00
|
|
|
<< "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2012-11-30 12:26:09 +04:00
|
|
|
void cmExportFileGenerator::GenerateExpectedTargetsCode(std::ostream& os,
|
|
|
|
const std::string &expectedTargets)
|
|
|
|
{
|
2013-07-20 00:57:33 +04:00
|
|
|
os << "# Protect against multiple inclusion, which would fail when already "
|
|
|
|
"imported targets are added once more.\n"
|
|
|
|
"set(_targetsDefined)\n"
|
2013-01-20 21:02:13 +04:00
|
|
|
"set(_targetsNotDefined)\n"
|
|
|
|
"set(_expectedTargets)\n"
|
|
|
|
"foreach(_expectedTarget " << expectedTargets << ")\n"
|
|
|
|
" list(APPEND _expectedTargets ${_expectedTarget})\n"
|
|
|
|
" if(NOT TARGET ${_expectedTarget})\n"
|
|
|
|
" list(APPEND _targetsNotDefined ${_expectedTarget})\n"
|
|
|
|
" endif()\n"
|
|
|
|
" if(TARGET ${_expectedTarget})\n"
|
|
|
|
" list(APPEND _targetsDefined ${_expectedTarget})\n"
|
|
|
|
" endif()\n"
|
|
|
|
"endforeach()\n"
|
|
|
|
"if(\"${_targetsDefined}\" STREQUAL \"${_expectedTargets}\")\n"
|
|
|
|
" set(CMAKE_IMPORT_FILE_VERSION)\n"
|
|
|
|
" cmake_policy(POP)\n"
|
|
|
|
" return()\n"
|
|
|
|
"endif()\n"
|
|
|
|
"if(NOT \"${_targetsDefined}\" STREQUAL \"\")\n"
|
|
|
|
" message(FATAL_ERROR \"Some (but not all) targets in this export "
|
2012-11-30 12:26:09 +04:00
|
|
|
"set were already defined.\\nTargets Defined: ${_targetsDefined}\\n"
|
|
|
|
"Targets not yet defined: ${_targetsNotDefined}\\n\")\n"
|
2013-01-20 21:02:13 +04:00
|
|
|
"endif()\n"
|
|
|
|
"unset(_targetsDefined)\n"
|
|
|
|
"unset(_targetsNotDefined)\n"
|
|
|
|
"unset(_expectedTargets)\n"
|
2012-11-30 12:26:09 +04:00
|
|
|
"\n\n";
|
|
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
2008-01-28 16:38:36 +03:00
|
|
|
void
|
|
|
|
cmExportFileGenerator
|
2013-10-30 01:21:20 +04:00
|
|
|
::GenerateImportTargetCode(std::ostream& os, cmTarget const* target)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
|
|
|
// Construct the imported target name.
|
|
|
|
std::string targetName = this->Namespace;
|
2013-05-17 12:12:02 +04:00
|
|
|
|
|
|
|
targetName += target->GetExportName();
|
2008-01-28 16:38:36 +03:00
|
|
|
|
|
|
|
// Create the imported target.
|
|
|
|
os << "# Create imported target " << targetName << "\n";
|
|
|
|
switch(target->GetType())
|
|
|
|
{
|
|
|
|
case cmTarget::EXECUTABLE:
|
2013-01-20 21:02:13 +04:00
|
|
|
os << "add_executable(" << targetName << " IMPORTED)\n";
|
2008-01-28 16:38:36 +03:00
|
|
|
break;
|
|
|
|
case cmTarget::STATIC_LIBRARY:
|
2013-01-20 21:02:13 +04:00
|
|
|
os << "add_library(" << targetName << " STATIC IMPORTED)\n";
|
2008-01-28 16:38:36 +03:00
|
|
|
break;
|
|
|
|
case cmTarget::SHARED_LIBRARY:
|
2013-01-20 21:02:13 +04:00
|
|
|
os << "add_library(" << targetName << " SHARED IMPORTED)\n";
|
2008-01-28 16:38:36 +03:00
|
|
|
break;
|
|
|
|
case cmTarget::MODULE_LIBRARY:
|
2013-01-20 21:02:13 +04:00
|
|
|
os << "add_library(" << targetName << " MODULE IMPORTED)\n";
|
2008-01-28 16:38:36 +03:00
|
|
|
break;
|
2013-02-07 20:36:29 +04:00
|
|
|
case cmTarget::UNKNOWN_LIBRARY:
|
|
|
|
os << "add_library(" << targetName << " UNKNOWN IMPORTED)\n";
|
|
|
|
break;
|
2012-11-20 13:58:15 +04:00
|
|
|
case cmTarget::INTERFACE_LIBRARY:
|
|
|
|
os << "add_library(" << targetName << " INTERFACE IMPORTED)\n";
|
|
|
|
break;
|
2008-01-28 16:38:36 +03:00
|
|
|
default: // should never happen
|
|
|
|
break;
|
|
|
|
}
|
2008-01-28 21:05:58 +03:00
|
|
|
|
|
|
|
// Mark the imported executable if it has exports.
|
2008-01-28 16:38:36 +03:00
|
|
|
if(target->IsExecutableWithExports())
|
|
|
|
{
|
2013-01-20 21:02:13 +04:00
|
|
|
os << "set_property(TARGET " << targetName
|
2008-01-28 21:05:58 +03:00
|
|
|
<< " PROPERTY ENABLE_EXPORTS 1)\n";
|
|
|
|
}
|
|
|
|
|
2008-01-28 22:46:16 +03:00
|
|
|
// Mark the imported library if it is a framework.
|
|
|
|
if(target->IsFrameworkOnApple())
|
2008-01-28 21:05:58 +03:00
|
|
|
{
|
2013-01-20 21:02:13 +04:00
|
|
|
os << "set_property(TARGET " << targetName
|
2008-01-28 21:05:58 +03:00
|
|
|
<< " PROPERTY FRAMEWORK 1)\n";
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
2008-01-28 22:46:16 +03:00
|
|
|
|
|
|
|
// Mark the imported executable if it is an application bundle.
|
|
|
|
if(target->IsAppBundleOnApple())
|
|
|
|
{
|
2013-01-20 21:02:13 +04:00
|
|
|
os << "set_property(TARGET " << targetName
|
2008-01-28 22:46:16 +03:00
|
|
|
<< " PROPERTY MACOSX_BUNDLE 1)\n";
|
|
|
|
}
|
2010-10-07 06:43:04 +04:00
|
|
|
|
|
|
|
if (target->IsCFBundleOnApple())
|
|
|
|
{
|
2013-01-20 21:02:13 +04:00
|
|
|
os << "set_property(TARGET " << targetName
|
2010-10-07 06:43:04 +04:00
|
|
|
<< " PROPERTY BUNDLE 1)\n";
|
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
os << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmExportFileGenerator
|
|
|
|
::GenerateImportPropertyCode(std::ostream& os, const char* config,
|
2013-10-30 01:21:20 +04:00
|
|
|
cmTarget const* target,
|
2008-01-28 16:38:36 +03:00
|
|
|
ImportPropertyMap const& properties)
|
|
|
|
{
|
|
|
|
// Construct the imported target name.
|
|
|
|
std::string targetName = this->Namespace;
|
2013-05-17 12:12:02 +04:00
|
|
|
|
|
|
|
targetName += target->GetExportName();
|
2008-01-28 16:38:36 +03:00
|
|
|
|
|
|
|
// Set the import properties.
|
|
|
|
os << "# Import target \"" << targetName << "\" for configuration \""
|
|
|
|
<< config << "\"\n";
|
2013-01-20 21:02:13 +04:00
|
|
|
os << "set_property(TARGET " << targetName
|
2008-01-28 16:38:36 +03:00
|
|
|
<< " APPEND PROPERTY IMPORTED_CONFIGURATIONS ";
|
|
|
|
if(config && *config)
|
|
|
|
{
|
|
|
|
os << cmSystemTools::UpperCase(config);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
os << "NOCONFIG";
|
|
|
|
}
|
|
|
|
os << ")\n";
|
2013-01-20 21:02:13 +04:00
|
|
|
os << "set_target_properties(" << targetName << " PROPERTIES\n";
|
2008-01-28 16:38:36 +03:00
|
|
|
for(ImportPropertyMap::const_iterator pi = properties.begin();
|
|
|
|
pi != properties.end(); ++pi)
|
|
|
|
{
|
|
|
|
os << " " << pi->first << " \"" << pi->second << "\"\n";
|
|
|
|
}
|
|
|
|
os << " )\n"
|
|
|
|
<< "\n";
|
|
|
|
}
|
2011-11-12 21:12:07 +04:00
|
|
|
|
|
|
|
|
2012-09-16 00:38:30 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os,
|
|
|
|
const std::vector<std::string>& missingTargets)
|
|
|
|
{
|
2013-01-13 12:42:07 +04:00
|
|
|
if (missingTargets.empty())
|
|
|
|
{
|
2013-02-12 01:18:48 +04:00
|
|
|
os << "# This file does not depend on other imported targets which have\n"
|
|
|
|
"# been exported from the same project but in a separate "
|
|
|
|
"export set.\n\n";
|
2013-01-13 12:42:07 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-09-16 00:38:30 +04:00
|
|
|
os << "# Make sure the targets which have been exported in some other \n"
|
2013-02-12 01:18:48 +04:00
|
|
|
"# export set exist.\n"
|
|
|
|
"unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
|
|
|
|
"foreach(_target ";
|
2013-01-13 12:42:47 +04:00
|
|
|
std::set<std::string> emitted;
|
2012-09-16 00:38:30 +04:00
|
|
|
for(unsigned int i=0; i<missingTargets.size(); ++i)
|
|
|
|
{
|
2013-01-13 12:42:47 +04:00
|
|
|
if (emitted.insert(missingTargets[i]).second)
|
|
|
|
{
|
2013-02-12 01:18:48 +04:00
|
|
|
os << "\"" << missingTargets[i] << "\" ";
|
2013-01-13 12:42:47 +04:00
|
|
|
}
|
2012-09-16 00:38:30 +04:00
|
|
|
}
|
2013-02-12 01:18:48 +04:00
|
|
|
os << ")\n"
|
|
|
|
" if(NOT TARGET \"${_target}\" )\n"
|
|
|
|
" set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets \""
|
|
|
|
"${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets} ${_target}\")"
|
|
|
|
"\n"
|
|
|
|
" endif()\n"
|
|
|
|
"endforeach()\n"
|
|
|
|
"\n"
|
|
|
|
"if(DEFINED ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
|
|
|
|
" if(CMAKE_FIND_PACKAGE_NAME)\n"
|
|
|
|
" set( ${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)\n"
|
|
|
|
" set( ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "
|
|
|
|
"\"The following imported targets are "
|
|
|
|
"referenced, but are missing: "
|
|
|
|
"${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
|
|
|
|
" else()\n"
|
|
|
|
" message(FATAL_ERROR \"The following imported targets are "
|
|
|
|
"referenced, but are missing: "
|
|
|
|
"${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
|
|
|
|
" endif()\n"
|
|
|
|
"endif()\n"
|
|
|
|
"unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
|
|
|
|
"\n";
|
2012-09-16 00:38:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-12 21:12:07 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
|
|
|
|
{
|
|
|
|
// Add code which verifies at cmake time that the file which is being
|
|
|
|
// imported actually exists on disk. This should in theory always be theory
|
|
|
|
// case, but still when packages are split into normal and development
|
|
|
|
// packages this might get broken (e.g. the Config.cmake could be part of
|
|
|
|
// the non-development package, something similar happened to me without
|
|
|
|
// on SUSE with a mysql pkg-config file, which claimed everything is fine,
|
|
|
|
// but the development package was not installed.).
|
|
|
|
os << "# Loop over all imported files and verify that they actually exist\n"
|
2013-01-20 21:02:13 +04:00
|
|
|
"foreach(target ${_IMPORT_CHECK_TARGETS} )\n"
|
|
|
|
" foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )\n"
|
|
|
|
" if(NOT EXISTS \"${file}\" )\n"
|
|
|
|
" message(FATAL_ERROR \"The imported target \\\"${target}\\\""
|
2011-11-18 01:39:24 +04:00
|
|
|
" references the file\n"
|
|
|
|
" \\\"${file}\\\"\n"
|
|
|
|
"but this file does not exist. Possible reasons include:\n"
|
|
|
|
"* The file was deleted, renamed, or moved to another location.\n"
|
|
|
|
"* An install or uninstall procedure did not complete successfully.\n"
|
|
|
|
"* The installation package was faulty and contained\n"
|
|
|
|
" \\\"${CMAKE_CURRENT_LIST_FILE}\\\"\n"
|
|
|
|
"but not all the files it references.\n"
|
|
|
|
"\")\n"
|
2013-01-20 21:02:13 +04:00
|
|
|
" endif()\n"
|
|
|
|
" endforeach()\n"
|
|
|
|
" unset(_IMPORT_CHECK_FILES_FOR_${target})\n"
|
|
|
|
"endforeach()\n"
|
|
|
|
"unset(_IMPORT_CHECK_TARGETS)\n"
|
2011-11-12 21:12:07 +04:00
|
|
|
"\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmExportFileGenerator
|
|
|
|
::GenerateImportedFileChecksCode(std::ostream& os, cmTarget* target,
|
|
|
|
ImportPropertyMap const& properties,
|
|
|
|
const std::set<std::string>& importedLocations)
|
|
|
|
{
|
|
|
|
// Construct the imported target name.
|
|
|
|
std::string targetName = this->Namespace;
|
2013-05-17 12:12:02 +04:00
|
|
|
targetName += target->GetExportName();
|
2011-11-12 21:12:07 +04:00
|
|
|
|
2013-01-20 21:02:13 +04:00
|
|
|
os << "list(APPEND _IMPORT_CHECK_TARGETS " << targetName << " )\n"
|
|
|
|
"list(APPEND _IMPORT_CHECK_FILES_FOR_" << targetName << " ";
|
2011-11-12 21:12:07 +04:00
|
|
|
|
|
|
|
for(std::set<std::string>::const_iterator li = importedLocations.begin();
|
|
|
|
li != importedLocations.end();
|
|
|
|
++li)
|
|
|
|
{
|
|
|
|
ImportPropertyMap::const_iterator pi = properties.find(*li);
|
|
|
|
if (pi != properties.end())
|
|
|
|
{
|
|
|
|
os << "\"" << pi->second << "\" ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
os << ")\n\n";
|
|
|
|
}
|