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 "cmExportInstallFileGenerator.h"
|
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmAlgorithms.h"
|
2012-09-28 23:47:37 +04:00
|
|
|
#include "cmExportSet.h"
|
|
|
|
#include "cmExportSetMap.h"
|
2008-01-28 16:38:36 +03:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2012-09-28 23:47:37 +04:00
|
|
|
#include "cmGlobalGenerator.h"
|
2008-01-28 16:38:36 +03:00
|
|
|
#include "cmInstallExportGenerator.h"
|
|
|
|
#include "cmInstallTargetGenerator.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmLocalGenerator.h"
|
2012-02-27 00:05:17 +04:00
|
|
|
#include "cmTargetExport.h"
|
2008-01-28 16:38:36 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmExportInstallFileGenerator::cmExportInstallFileGenerator(
|
|
|
|
cmInstallExportGenerator* iegen)
|
|
|
|
: IEGen(iegen)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-01-07 22:16:28 +03:00
|
|
|
std::string cmExportInstallFileGenerator::GetConfigImportFileGlob()
|
|
|
|
{
|
|
|
|
std::string glob = this->FileBase;
|
|
|
|
glob += "-*";
|
|
|
|
glob += this->FileExt;
|
|
|
|
return glob;
|
|
|
|
}
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
|
|
|
|
{
|
2013-01-05 15:13:49 +04:00
|
|
|
std::vector<cmTargetExport*> allTargets;
|
2012-11-30 12:26:09 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string expectedTargets;
|
|
|
|
std::string sep;
|
|
|
|
for (std::vector<cmTargetExport*>::const_iterator tei =
|
|
|
|
this->IEGen->GetExportSet()->GetTargetExports()->begin();
|
|
|
|
tei != this->IEGen->GetExportSet()->GetTargetExports()->end();
|
|
|
|
++tei) {
|
|
|
|
expectedTargets +=
|
2015-10-17 16:08:13 +03:00
|
|
|
sep + this->Namespace + (*tei)->Target->GetExportName();
|
2016-05-16 17:34:04 +03:00
|
|
|
sep = " ";
|
|
|
|
cmTargetExport* te = *tei;
|
|
|
|
if (this->ExportedTargets.insert(te->Target).second) {
|
|
|
|
allTargets.push_back(te);
|
|
|
|
} else {
|
|
|
|
std::ostringstream e;
|
|
|
|
e << "install(EXPORT \"" << this->IEGen->GetExportSet()->GetName()
|
|
|
|
<< "\" ...) "
|
|
|
|
<< "includes target \"" << te->Target->GetName()
|
|
|
|
<< "\" more than once in the export set.";
|
|
|
|
cmSystemTools::Error(e.str().c_str());
|
|
|
|
return false;
|
2008-02-06 22:20:36 +03: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
|
|
|
}
|
|
|
|
|
2014-12-15 17:52:48 +03:00
|
|
|
// Set an _IMPORT_PREFIX variable for import location properties
|
|
|
|
// to reference if they are relative to the install prefix.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string installPrefix =
|
|
|
|
this->IEGen->GetLocalGenerator()->GetMakefile()->GetSafeDefinition(
|
|
|
|
"CMAKE_INSTALL_PREFIX");
|
2015-02-11 19:45:41 +03:00
|
|
|
std::string const& expDest = this->IEGen->GetDestination();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsFullPath(expDest)) {
|
2014-12-15 17:52:48 +03:00
|
|
|
// The export file is being installed to an absolute path so the
|
|
|
|
// package is not relocatable. Use the configured install prefix.
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2014-12-15 17:52:48 +03:00
|
|
|
os <<
|
|
|
|
"# The installation prefix configured by this project.\n"
|
|
|
|
"set(_IMPORT_PREFIX \"" << installPrefix << "\")\n"
|
|
|
|
"\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-12-15 17:52:48 +03:00
|
|
|
// Add code to compute the installation prefix relative to the
|
|
|
|
// import file location.
|
2015-02-11 19:45:41 +03:00
|
|
|
std::string absDest = installPrefix + "/" + expDest;
|
2013-04-03 18:54:08 +04:00
|
|
|
std::string absDestS = absDest + "/";
|
|
|
|
os << "# Compute the installation prefix relative to this file.\n"
|
|
|
|
<< "get_filename_component(_IMPORT_PREFIX"
|
|
|
|
<< " \"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmHasLiteralPrefix(absDestS.c_str(), "/lib/") ||
|
|
|
|
cmHasLiteralPrefix(absDestS.c_str(), "/lib64/") ||
|
|
|
|
cmHasLiteralPrefix(absDestS.c_str(), "/usr/lib/") ||
|
|
|
|
cmHasLiteralPrefix(absDestS.c_str(), "/usr/lib64/")) {
|
2013-04-03 18:54:08 +04:00
|
|
|
// Handle "/usr move" symlinks created by some Linux distros.
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2013-04-03 18:54:08 +04:00
|
|
|
os <<
|
|
|
|
"# Use original install prefix when loaded through a\n"
|
|
|
|
"# cross-prefix symbolic link such as /lib -> /usr/lib.\n"
|
|
|
|
"get_filename_component(_realCurr \"${_IMPORT_PREFIX}\" REALPATH)\n"
|
|
|
|
"get_filename_component(_realOrig \"" << absDest << "\" REALPATH)\n"
|
|
|
|
"if(_realCurr STREQUAL _realOrig)\n"
|
|
|
|
" set(_IMPORT_PREFIX \"" << absDest << "\")\n"
|
|
|
|
"endif()\n"
|
|
|
|
"unset(_realOrig)\n"
|
|
|
|
"unset(_realCurr)\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-11 19:45:41 +03:00
|
|
|
std::string dest = expDest;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (!dest.empty()) {
|
|
|
|
os << "get_filename_component(_IMPORT_PREFIX \"${_IMPORT_PREFIX}\" "
|
|
|
|
"PATH)\n";
|
2013-04-03 18:54:08 +04:00
|
|
|
dest = cmSystemTools::GetFilenamePath(dest);
|
2013-01-27 12:42:54 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
os << "\n";
|
|
|
|
}
|
2013-01-27 12:42:54 +04:00
|
|
|
|
2012-09-23 15:45:17 +04:00
|
|
|
std::vector<std::string> missingTargets;
|
|
|
|
|
2013-06-04 18:47:57 +04:00
|
|
|
bool require2_8_12 = false;
|
2013-12-10 21:59:21 +04:00
|
|
|
bool require3_0_0 = false;
|
2014-11-28 20:58:38 +03:00
|
|
|
bool require3_1_0 = false;
|
2013-12-26 11:19:33 +04:00
|
|
|
bool requiresConfigFiles = false;
|
2012-12-31 01:06:12 +04:00
|
|
|
// Create all the imported targets.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmTargetExport*>::const_iterator tei = allTargets.begin();
|
|
|
|
tei != allTargets.end(); ++tei) {
|
2015-10-17 14:31:33 +03:00
|
|
|
cmGeneratorTarget* gt = (*tei)->Target;
|
2013-12-26 11:19:33 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
requiresConfigFiles =
|
|
|
|
requiresConfigFiles || gt->GetType() != cmState::INTERFACE_LIBRARY;
|
2013-12-26 11:19:33 +04:00
|
|
|
|
2015-10-17 15:33:51 +03:00
|
|
|
this->GenerateImportTargetCode(os, gt);
|
2012-09-23 15:45:17 +04:00
|
|
|
|
|
|
|
ImportPropertyMap properties;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->PopulateIncludeDirectoriesInterface(
|
|
|
|
*tei, cmGeneratorExpression::InstallInterface, properties,
|
|
|
|
missingTargets);
|
2014-11-28 20:58:38 +03:00
|
|
|
this->PopulateSourcesInterface(*tei,
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratorExpression::InstallInterface,
|
|
|
|
properties, missingTargets);
|
|
|
|
this->PopulateInterfaceProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", gt,
|
|
|
|
cmGeneratorExpression::InstallInterface,
|
|
|
|
properties, missingTargets);
|
|
|
|
this->PopulateInterfaceProperty("INTERFACE_COMPILE_DEFINITIONS", gt,
|
|
|
|
cmGeneratorExpression::InstallInterface,
|
|
|
|
properties, missingTargets);
|
|
|
|
this->PopulateInterfaceProperty("INTERFACE_COMPILE_OPTIONS", gt,
|
|
|
|
cmGeneratorExpression::InstallInterface,
|
|
|
|
properties, missingTargets);
|
|
|
|
this->PopulateInterfaceProperty("INTERFACE_AUTOUIC_OPTIONS", gt,
|
|
|
|
cmGeneratorExpression::InstallInterface,
|
|
|
|
properties, missingTargets);
|
|
|
|
this->PopulateInterfaceProperty("INTERFACE_COMPILE_FEATURES", gt,
|
|
|
|
cmGeneratorExpression::InstallInterface,
|
|
|
|
properties, missingTargets);
|
2013-06-04 18:47:57 +04:00
|
|
|
|
|
|
|
const bool newCMP0022Behavior =
|
2016-05-16 17:34:04 +03:00
|
|
|
gt->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
|
|
|
|
gt->GetPolicyStatusCMP0022() != cmPolicies::OLD;
|
|
|
|
if (newCMP0022Behavior) {
|
|
|
|
if (this->PopulateInterfaceLinkLibrariesProperty(
|
|
|
|
gt, cmGeneratorExpression::InstallInterface, properties,
|
|
|
|
missingTargets) &&
|
|
|
|
!this->ExportOld) {
|
2013-06-04 18:47:57 +04:00
|
|
|
require2_8_12 = true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (gt->GetType() == cmState::INTERFACE_LIBRARY) {
|
2013-12-10 21:59:21 +04:00
|
|
|
require3_0_0 = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (gt->GetProperty("INTERFACE_SOURCES")) {
|
2014-11-28 20:58:38 +03:00
|
|
|
// We can only generate INTERFACE_SOURCES in CMake 3.3, but CMake 3.1
|
|
|
|
// can consume them.
|
|
|
|
require3_1_0 = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-11-28 20:58:38 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE", gt,
|
|
|
|
properties);
|
2015-08-04 20:19:42 +03:00
|
|
|
|
2015-10-17 14:31:33 +03:00
|
|
|
this->PopulateCompatibleInterfaceProperties(gt, properties);
|
2012-09-23 15:45:17 +04:00
|
|
|
|
2015-10-17 15:33:51 +03:00
|
|
|
this->GenerateInterfaceProperties(gt, os, properties);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-12-31 01:06:12 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (require3_1_0) {
|
2014-11-28 20:58:38 +03:00
|
|
|
this->GenerateRequiredCMakeVersion(os, "3.1.0");
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (require3_0_0) {
|
2014-02-19 18:15:33 +04:00
|
|
|
this->GenerateRequiredCMakeVersion(os, "3.0.0");
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (require2_8_12) {
|
2013-08-15 18:53:16 +04:00
|
|
|
this->GenerateRequiredCMakeVersion(os, "2.8.12");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-23 15:45:17 +04:00
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
// Now load per-configuration properties for them.
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2008-01-28 16:38:36 +03:00
|
|
|
os << "# Load information for each installed configuration.\n"
|
2013-01-20 21:02:13 +04:00
|
|
|
<< "get_filename_component(_DIR \"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n"
|
|
|
|
<< "file(GLOB CONFIG_FILES \"${_DIR}/"
|
2009-01-07 22:16:28 +03:00
|
|
|
<< this->GetConfigImportFileGlob() << "\")\n"
|
2013-01-20 21:02:13 +04:00
|
|
|
<< "foreach(f ${CONFIG_FILES})\n"
|
|
|
|
<< " include(${f})\n"
|
|
|
|
<< "endforeach()\n"
|
2008-01-28 16:38:36 +03:00
|
|
|
<< "\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2008-01-28 16:38:36 +03:00
|
|
|
|
2013-01-27 12:42:54 +04:00
|
|
|
// Cleanup the import prefix variable.
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2014-12-15 17:52:48 +03:00
|
|
|
os << "# Cleanup temporary variables.\n"
|
|
|
|
<< "set(_IMPORT_PREFIX)\n"
|
|
|
|
<< "\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2013-01-13 12:48:45 +04:00
|
|
|
this->GenerateImportedFileCheckLoop(os);
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
bool result = true;
|
2013-12-26 11:19:33 +04:00
|
|
|
// Generate an import file for each configuration.
|
|
|
|
// Don't do this if we only export INTERFACE_LIBRARY targets.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (requiresConfigFiles) {
|
|
|
|
for (std::vector<std::string>::const_iterator ci =
|
|
|
|
this->Configurations.begin();
|
|
|
|
ci != this->Configurations.end(); ++ci) {
|
|
|
|
if (!this->GenerateImportFileConfig(*ci, missingTargets)) {
|
2013-12-26 11:19:33 +04:00
|
|
|
result = false;
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-01-13 12:44:52 +04:00
|
|
|
|
|
|
|
this->GenerateMissingTargetsCheckCode(os, missingTargets);
|
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmExportInstallFileGenerator::ReplaceInstallPrefix(std::string& input)
|
2013-01-27 12:43:44 +04:00
|
|
|
{
|
|
|
|
std::string::size_type pos = 0;
|
|
|
|
std::string::size_type lastPos = pos;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
while ((pos = input.find("$<INSTALL_PREFIX>", lastPos)) != input.npos) {
|
2013-01-27 12:43:44 +04:00
|
|
|
std::string::size_type endPos = pos + sizeof("$<INSTALL_PREFIX>") - 1;
|
|
|
|
input.replace(pos, endPos - pos, "${_IMPORT_PREFIX}");
|
|
|
|
lastPos = endPos;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-01-27 12:43:44 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmExportInstallFileGenerator::GenerateImportFileConfig(
|
|
|
|
const std::string& config, std::vector<std::string>& missingTargets)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
|
|
|
// Skip configurations not enabled for this export.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->IEGen->InstallsForConfig(config)) {
|
2008-01-28 16:38:36 +03:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
|
|
|
|
// Construct the name of the file to generate.
|
|
|
|
std::string fileName = this->FileDir;
|
|
|
|
fileName += "/";
|
|
|
|
fileName += this->FileBase;
|
|
|
|
fileName += "-";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!config.empty()) {
|
2008-01-28 16:38:36 +03:00
|
|
|
fileName += cmSystemTools::LowerCase(config);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-01-28 16:38:36 +03:00
|
|
|
fileName += "noconfig";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
fileName += this->FileExt;
|
|
|
|
|
|
|
|
// Open the output file to generate it.
|
|
|
|
cmGeneratedFileStream exportFileStream(fileName.c_str(), true);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!exportFileStream) {
|
2008-01-28 16:38:36 +03:00
|
|
|
std::string se = cmSystemTools::GetLastSystemError();
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2016-05-16 17:34:04 +03:00
|
|
|
e << "cannot write to file \"" << fileName << "\": " << se;
|
2008-01-28 16:38:36 +03:00
|
|
|
cmSystemTools::Error(e.str().c_str());
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
std::ostream& os = exportFileStream;
|
|
|
|
|
|
|
|
// Start with the import file header.
|
|
|
|
this->GenerateImportHeaderCode(os, config);
|
|
|
|
|
|
|
|
// Generate the per-config target information.
|
2013-01-13 12:44:52 +04:00
|
|
|
this->GenerateImportConfig(os, config, missingTargets);
|
2008-01-28 16:38:36 +03:00
|
|
|
|
|
|
|
// End with the import file footer.
|
|
|
|
this->GenerateImportFooterCode(os);
|
|
|
|
|
|
|
|
// Record this per-config import file.
|
|
|
|
this->ConfigImportFiles[config] = fileName;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmExportInstallFileGenerator::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
|
|
|
{
|
|
|
|
// Add each target in the set to the export.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmTargetExport*>::const_iterator tei =
|
|
|
|
this->IEGen->GetExportSet()->GetTargetExports()->begin();
|
|
|
|
tei != this->IEGen->GetExportSet()->GetTargetExports()->end(); ++tei) {
|
2008-01-28 16:38:36 +03:00
|
|
|
// Collect import properties for this target.
|
2012-02-27 10:09:40 +04:00
|
|
|
cmTargetExport const* te = *tei;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (te->Target->GetType() == cmState::INTERFACE_LIBRARY) {
|
2012-11-20 14:06:29 +04:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-12-19 17:24:46 +04:00
|
|
|
|
|
|
|
ImportPropertyMap properties;
|
|
|
|
std::set<std::string> importedLocations;
|
|
|
|
|
2011-11-12 21:12:07 +04:00
|
|
|
this->SetImportLocationProperty(config, suffix, te->ArchiveGenerator,
|
|
|
|
properties, importedLocations);
|
|
|
|
this->SetImportLocationProperty(config, suffix, te->LibraryGenerator,
|
|
|
|
properties, importedLocations);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->SetImportLocationProperty(config, suffix, te->RuntimeGenerator,
|
|
|
|
properties, importedLocations);
|
2011-11-12 21:12:07 +04:00
|
|
|
this->SetImportLocationProperty(config, suffix, te->FrameworkGenerator,
|
|
|
|
properties, importedLocations);
|
|
|
|
this->SetImportLocationProperty(config, suffix, te->BundleGenerator,
|
|
|
|
properties, importedLocations);
|
2008-01-28 16:38:36 +03:00
|
|
|
|
|
|
|
// If any file location was set for the target add it to the
|
|
|
|
// import file.
|
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
|
|
|
cmGeneratorTarget* gtgt = te->Target;
|
|
|
|
this->SetImportDetailProperties(config, suffix, gtgt, properties,
|
|
|
|
missingTargets);
|
2008-01-28 16:38:36 +03:00
|
|
|
|
2013-01-04 18:58:16 +04:00
|
|
|
this->SetImportLinkInterface(config, suffix,
|
|
|
|
cmGeneratorExpression::InstallInterface,
|
2012-10-06 19:51:07 +04:00
|
|
|
gtgt, properties, missingTargets);
|
2013-01-04 18:58:16 +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.
|
2015-10-17 16:10:32 +03:00
|
|
|
this->GenerateImportPropertyCode(os, config, gtgt, properties);
|
|
|
|
this->GenerateImportedFileChecksCode(os, gtgt, properties,
|
2011-11-12 21:12:07 +04:00
|
|
|
importedLocations);
|
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 cmExportInstallFileGenerator::SetImportLocationProperty(
|
|
|
|
const std::string& config, std::string const& suffix,
|
|
|
|
cmInstallTargetGenerator* itgen, ImportPropertyMap& properties,
|
|
|
|
std::set<std::string>& importedLocations)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
|
|
|
// Skip rules that do not match this configuration.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!(itgen && itgen->InstallsForConfig(config))) {
|
2008-01-28 16:38:36 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
|
2008-02-06 22:20:36 +03:00
|
|
|
// Get the target to be installed.
|
2015-10-17 15:54:15 +03:00
|
|
|
cmGeneratorTarget* target = itgen->GetTarget();
|
2008-01-28 16:38:36 +03:00
|
|
|
|
|
|
|
// Construct the installed location of the target.
|
2015-02-11 22:02:45 +03:00
|
|
|
std::string dest = itgen->GetDestination(config);
|
2008-01-28 16:38:36 +03:00
|
|
|
std::string value;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileIsFullPath(dest.c_str())) {
|
2008-01-28 16:38:36 +03:00
|
|
|
// The target is installed relative to the installation prefix.
|
2014-12-15 17:52:48 +03:00
|
|
|
value = "${_IMPORT_PREFIX}/";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-28 16:38:36 +03:00
|
|
|
value += dest;
|
|
|
|
value += "/";
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (itgen->IsImportLibrary()) {
|
2008-02-06 22:20:36 +03:00
|
|
|
// Construct the property name.
|
|
|
|
std::string prop = "IMPORTED_IMPLIB";
|
|
|
|
prop += suffix;
|
|
|
|
|
|
|
|
// Append the installed file name.
|
|
|
|
value += itgen->GetInstallFilename(target, config,
|
|
|
|
cmInstallTargetGenerator::NameImplib);
|
|
|
|
|
|
|
|
// Store the property.
|
|
|
|
properties[prop] = value;
|
2011-11-12 21:12:07 +04:00
|
|
|
importedLocations.insert(prop);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-02-06 22:20:36 +03:00
|
|
|
// Construct the property name.
|
|
|
|
std::string prop = "IMPORTED_LOCATION";
|
|
|
|
prop += suffix;
|
2008-01-28 16:38:36 +03:00
|
|
|
|
2008-02-06 22:20:36 +03:00
|
|
|
// Append the installed file name.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->IsAppBundleOnApple()) {
|
2008-02-06 22:20:36 +03:00
|
|
|
value += itgen->GetInstallFilename(target, config);
|
|
|
|
value += ".app/Contents/MacOS/";
|
|
|
|
value += itgen->GetInstallFilename(target, config);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-02-06 22:20:36 +03:00
|
|
|
value += itgen->GetInstallFilename(target, config,
|
|
|
|
cmInstallTargetGenerator::NameReal);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-02-06 22:20:36 +03:00
|
|
|
|
|
|
|
// Store the property.
|
|
|
|
properties[prop] = value;
|
2011-11-12 21:12:07 +04:00
|
|
|
importedLocations.insert(prop);
|
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 cmExportInstallFileGenerator::HandleMissingTarget(
|
|
|
|
std::string& link_libs, std::vector<std::string>& missingTargets,
|
2015-10-17 16:05:46 +03:00
|
|
|
cmGeneratorTarget* depender, cmGeneratorTarget* dependee)
|
2012-09-28 23:47:37 +04:00
|
|
|
{
|
2013-05-17 12:12:02 +04:00
|
|
|
const std::string name = dependee->GetName();
|
2015-10-17 16:05:46 +03:00
|
|
|
cmGlobalGenerator* gg = dependee->GetLocalGenerator()->GetGlobalGenerator();
|
2015-10-17 16:01:25 +03:00
|
|
|
std::vector<std::string> namespaces = this->FindNamespaces(gg, name);
|
2012-09-28 23:47:37 +04:00
|
|
|
int targetOccurrences = (int)namespaces.size();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (targetOccurrences == 1) {
|
2012-09-28 23:47:37 +04:00
|
|
|
std::string missingTarget = namespaces[0];
|
2013-05-17 12:12:02 +04:00
|
|
|
|
2015-10-17 16:08:13 +03:00
|
|
|
missingTarget += dependee->GetExportName();
|
2012-09-28 23:47:37 +04:00
|
|
|
link_libs += missingTarget;
|
|
|
|
missingTargets.push_back(missingTarget);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-10-10 13:14:11 +04:00
|
|
|
// All exported targets should be known here and should be unique.
|
|
|
|
// This is probably user-error.
|
2012-09-28 23:47:37 +04:00
|
|
|
this->ComplainAboutMissingTarget(depender, dependee, targetOccurrences);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-28 23:47:37 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::vector<std::string> cmExportInstallFileGenerator::FindNamespaces(
|
|
|
|
cmGlobalGenerator* gg, const std::string& name)
|
2012-09-28 23:47:37 +04:00
|
|
|
{
|
|
|
|
std::vector<std::string> namespaces;
|
|
|
|
const cmExportSetMap& exportSets = gg->GetExportSets();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cmExportSetMap::const_iterator expIt = exportSets.begin();
|
|
|
|
expIt != exportSets.end(); ++expIt) {
|
2012-09-28 23:47:37 +04:00
|
|
|
const cmExportSet* exportSet = expIt->second;
|
|
|
|
std::vector<cmTargetExport*> const* targets =
|
2016-05-16 17:34:04 +03:00
|
|
|
exportSet->GetTargetExports();
|
2012-09-28 23:47:37 +04:00
|
|
|
|
|
|
|
bool containsTarget = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int i = 0; i < targets->size(); i++) {
|
|
|
|
if (name == (*targets)[i]->TargetName) {
|
2012-09-28 23:47:37 +04:00
|
|
|
containsTarget = true;
|
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-28 23:47:37 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (containsTarget) {
|
2012-09-28 23:47:37 +04:00
|
|
|
std::vector<cmInstallExportGenerator const*> const* installs =
|
2016-05-16 17:34:04 +03:00
|
|
|
exportSet->GetInstallations();
|
|
|
|
for (unsigned int i = 0; i < installs->size(); i++) {
|
2012-09-28 23:47:37 +04:00
|
|
|
namespaces.push_back((*installs)[i]->GetNamespace());
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-28 23:47:37 +04:00
|
|
|
|
|
|
|
return namespaces;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmExportInstallFileGenerator::ComplainAboutMissingTarget(
|
|
|
|
cmGeneratorTarget* depender, cmGeneratorTarget* dependee, int occurrences)
|
2008-01-28 16:38:36 +03:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2016-05-16 17:34:04 +03:00
|
|
|
e << "install(EXPORT \"" << this->IEGen->GetExportSet()->GetName()
|
2012-03-01 14:52:32 +04:00
|
|
|
<< "\" ...) "
|
2008-02-01 16:56:00 +03:00
|
|
|
<< "includes target \"" << depender->GetName()
|
2012-09-15 23:55:24 +04:00
|
|
|
<< "\" which requires target \"" << dependee->GetName() << "\" ";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (occurrences == 0) {
|
2012-09-15 23:55:24 +04:00
|
|
|
e << "that is not in the export set.";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2012-09-15 23:55:24 +04:00
|
|
|
e << "that is not in this export set, but " << occurrences
|
2016-05-16 17:34:04 +03:00
|
|
|
<< " times in others.";
|
|
|
|
}
|
2008-01-31 01:25:52 +03:00
|
|
|
cmSystemTools::Error(e.str().c_str());
|
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 cmExportInstallFileGenerator::InstallNameDir(
|
2016-08-17 02:49:57 +03:00
|
|
|
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->GetInstallNameDirForInstallTree();
|
|
|
|
}
|
2013-05-21 02:57:58 +04:00
|
|
|
|
|
|
|
return install_name_dir;
|
|
|
|
}
|