2006-02-19 23:25:27 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
#include "cmInstallTargetGenerator.h"
|
|
|
|
|
2006-02-20 03:29:30 +03:00
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
2006-02-19 23:25:27 +03:00
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmTarget.h"
|
2006-06-14 20:28:32 +04:00
|
|
|
#include "cmake.h"
|
2006-02-19 23:25:27 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmInstallTargetGenerator
|
2006-03-04 03:29:35 +03:00
|
|
|
::cmInstallTargetGenerator(cmTarget& t, const char* dest, bool implib,
|
2006-08-17 22:48:54 +04:00
|
|
|
const char* file_permissions,
|
2006-05-05 22:57:19 +04:00
|
|
|
std::vector<std::string> const& configurations,
|
2006-10-05 19:31:57 +04:00
|
|
|
const char* component, bool optional):
|
2006-03-04 03:29:35 +03:00
|
|
|
Target(&t), Destination(dest), ImportLibrary(implib),
|
2006-08-17 22:48:54 +04:00
|
|
|
FilePermissions(file_permissions), Configurations(configurations),
|
2006-10-05 19:31:57 +04:00
|
|
|
Component(component), Optional(optional)
|
2006-02-19 23:25:27 +03:00
|
|
|
{
|
2006-02-20 01:27:47 +03:00
|
|
|
this->Target->SetHaveInstallRule(true);
|
2006-02-19 23:25:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmInstallTargetGenerator
|
|
|
|
::~cmInstallTargetGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
|
|
|
|
{
|
|
|
|
// Compute the build tree directory from which to copy the target.
|
|
|
|
std::string fromDir;
|
|
|
|
if(this->Target->NeedRelinkBeforeInstall())
|
|
|
|
{
|
|
|
|
fromDir = this->Target->GetMakefile()->GetStartOutputDirectory();
|
2006-06-14 20:28:32 +04:00
|
|
|
fromDir += cmake::GetCMakeFilesDirectory();
|
|
|
|
fromDir += "/CMakeRelink.dir/";
|
2006-02-19 23:25:27 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-09 17:30:16 +03:00
|
|
|
fromDir = this->Target->GetDirectory(0, this->ImportLibrary);
|
2006-02-19 23:25:27 +03:00
|
|
|
fromDir += "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write variable settings to do per-configuration references.
|
2006-02-24 21:13:14 +03:00
|
|
|
this->PrepareScriptReference(os, this->Target, "BUILD", true, false);
|
2006-02-19 23:25:27 +03:00
|
|
|
|
|
|
|
// Create the per-configuration reference.
|
2006-02-24 21:13:14 +03:00
|
|
|
std::string fromName = this->GetScriptReference(this->Target, "BUILD",
|
|
|
|
false);
|
2006-02-19 23:25:27 +03:00
|
|
|
std::string fromFile = fromDir;
|
|
|
|
fromFile += fromName;
|
|
|
|
|
2006-03-03 20:58:48 +03:00
|
|
|
// Choose the final destination. This may be modified for certain
|
|
|
|
// target types.
|
|
|
|
std::string destination = this->Destination;
|
|
|
|
|
2006-02-19 23:25:27 +03:00
|
|
|
// Setup special properties for some target types.
|
2006-08-22 00:55:03 +04:00
|
|
|
std::string literal_args;
|
2006-02-19 23:25:27 +03:00
|
|
|
std::string props;
|
|
|
|
const char* properties = 0;
|
|
|
|
cmTarget::TargetType type = this->Target->GetType();
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case cmTarget::SHARED_LIBRARY:
|
|
|
|
{
|
|
|
|
// Add shared library installation properties if this platform
|
|
|
|
// supports them.
|
2006-08-01 23:36:49 +04:00
|
|
|
const char* lib_version = 0;
|
|
|
|
const char* lib_soversion = 0;
|
|
|
|
|
|
|
|
// Versioning is supported only for shared libraries and modules,
|
|
|
|
// and then only when the platform supports an soname flag.
|
|
|
|
cmGlobalGenerator* gg =
|
2006-08-03 05:30:58 +04:00
|
|
|
(this->Target->GetMakefile()
|
|
|
|
->GetLocalGenerator()->GetGlobalGenerator());
|
2006-08-01 23:36:49 +04:00
|
|
|
if(const char* linkLanguage = this->Target->GetLinkerLanguage(gg))
|
2006-02-19 23:25:27 +03:00
|
|
|
{
|
2006-08-01 23:36:49 +04:00
|
|
|
std::string sonameFlagVar = "CMAKE_SHARED_LIBRARY_SONAME_";
|
|
|
|
sonameFlagVar += linkLanguage;
|
|
|
|
sonameFlagVar += "_FLAG";
|
|
|
|
if(this->Target->GetMakefile()->GetDefinition(sonameFlagVar.c_str()))
|
|
|
|
{
|
|
|
|
lib_version = this->Target->GetProperty("VERSION");
|
|
|
|
lib_soversion = this->Target->GetProperty("SOVERSION");
|
|
|
|
}
|
2006-02-19 23:25:27 +03:00
|
|
|
}
|
2006-08-01 23:36:49 +04:00
|
|
|
|
2006-02-19 23:25:27 +03:00
|
|
|
if(lib_version)
|
|
|
|
{
|
|
|
|
props += " VERSION ";
|
|
|
|
props += lib_version;
|
|
|
|
}
|
|
|
|
if(lib_soversion)
|
|
|
|
{
|
|
|
|
props += " SOVERSION ";
|
|
|
|
props += lib_soversion;
|
|
|
|
}
|
|
|
|
properties = props.c_str();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case cmTarget::EXECUTABLE:
|
|
|
|
{
|
|
|
|
// Add executable installation properties if this platform
|
|
|
|
// supports them.
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
const char* exe_version = 0;
|
|
|
|
#else
|
|
|
|
const char* exe_version = this->Target->GetProperty("VERSION");
|
|
|
|
#endif
|
|
|
|
if(exe_version)
|
|
|
|
{
|
|
|
|
props += " VERSION ";
|
|
|
|
props += exe_version;
|
|
|
|
properties = props.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle OSX Bundles.
|
2006-03-28 19:58:14 +04:00
|
|
|
if(this->Target->GetMakefile()->IsOn("APPLE") &&
|
|
|
|
this->Target->GetPropertyAsBool("MACOSX_BUNDLE"))
|
2006-02-19 23:25:27 +03:00
|
|
|
{
|
|
|
|
// Compute the source locations of the bundle executable and
|
|
|
|
// Info.plist file.
|
2006-03-03 20:58:48 +03:00
|
|
|
this->PrepareScriptReference(os, this->Target, "INSTALL",
|
|
|
|
false, false);
|
2006-03-28 22:16:15 +04:00
|
|
|
fromFile += ".app";
|
|
|
|
type = cmTarget::INSTALL_DIRECTORY;
|
2006-08-22 00:55:03 +04:00
|
|
|
literal_args += " USE_SOURCE_PERMISSIONS";
|
2006-02-19 23:25:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case cmTarget::STATIC_LIBRARY:
|
|
|
|
case cmTarget::MODULE_LIBRARY:
|
|
|
|
// Nothing special for modules or static libraries.
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-02-20 00:10:23 +03:00
|
|
|
// An import library looks like a static library.
|
|
|
|
if(this->ImportLibrary)
|
|
|
|
{
|
|
|
|
type = cmTarget::STATIC_LIBRARY;
|
|
|
|
}
|
|
|
|
|
2006-02-19 23:25:27 +03:00
|
|
|
// Write code to install the target file.
|
2006-08-17 22:48:54 +04:00
|
|
|
const char* no_dir_permissions = 0;
|
2006-08-22 00:55:03 +04:00
|
|
|
const char* no_rename = 0;
|
2006-10-05 19:31:57 +04:00
|
|
|
bool optional = this->Optional | this->ImportLibrary;
|
2006-03-03 20:58:48 +03:00
|
|
|
this->AddInstallRule(os, destination.c_str(), type, fromFile.c_str(),
|
2006-10-05 19:31:57 +04:00
|
|
|
optional, properties,
|
2006-08-17 22:48:54 +04:00
|
|
|
this->FilePermissions.c_str(), no_dir_permissions,
|
2006-05-05 22:57:19 +04:00
|
|
|
this->Configurations,
|
2006-08-22 00:55:03 +04:00
|
|
|
this->Component.c_str(),
|
|
|
|
no_rename, literal_args.c_str());
|
2006-02-24 21:13:14 +03:00
|
|
|
|
|
|
|
// Fix the install_name settings in installed binaries.
|
|
|
|
if(type == cmTarget::SHARED_LIBRARY ||
|
|
|
|
type == cmTarget::MODULE_LIBRARY ||
|
|
|
|
type == cmTarget::EXECUTABLE)
|
|
|
|
{
|
2006-03-03 20:58:48 +03:00
|
|
|
this->AddInstallNamePatchRule(os, destination.c_str());
|
2006-02-24 21:13:14 +03:00
|
|
|
}
|
2006-02-19 23:25:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmInstallTargetGenerator
|
2006-02-24 21:13:14 +03:00
|
|
|
::PrepareScriptReference(std::ostream& os, cmTarget* target,
|
|
|
|
const char* place, bool useConfigDir,
|
|
|
|
bool useSOName)
|
2006-02-19 23:25:27 +03:00
|
|
|
{
|
|
|
|
// If the target name may vary with the configuration type then
|
|
|
|
// store all possible names ahead of time in variables.
|
|
|
|
std::string fname;
|
|
|
|
for(std::vector<std::string>::const_iterator i =
|
|
|
|
this->ConfigurationTypes->begin();
|
|
|
|
i != this->ConfigurationTypes->end(); ++i)
|
|
|
|
{
|
2006-02-24 21:13:14 +03:00
|
|
|
// Initialize the name.
|
2006-02-20 03:29:30 +03:00
|
|
|
fname = "";
|
2006-02-24 21:13:14 +03:00
|
|
|
|
|
|
|
if(useConfigDir)
|
|
|
|
{
|
|
|
|
// Start with the configuration's subdirectory.
|
|
|
|
target->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
|
2006-03-03 20:58:48 +03:00
|
|
|
AppendDirectoryForConfig("", i->c_str(), "/", fname);
|
2006-02-24 21:13:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the name of the library.
|
|
|
|
std::string targetName;
|
|
|
|
std::string targetNameSO;
|
|
|
|
std::string targetNameReal;
|
|
|
|
std::string targetNameImport;
|
2007-02-01 17:57:24 +03:00
|
|
|
std::string targetNamePDB;
|
2006-02-24 21:13:14 +03:00
|
|
|
target->GetLibraryNames(targetName, targetNameSO, targetNameReal,
|
2007-02-01 17:57:24 +03:00
|
|
|
targetNameImport, targetNamePDB, i->c_str());
|
2006-02-24 21:13:14 +03:00
|
|
|
if(this->ImportLibrary)
|
|
|
|
{
|
|
|
|
// Use the import library name.
|
|
|
|
fname += targetNameImport;
|
|
|
|
}
|
|
|
|
else if(useSOName)
|
|
|
|
{
|
|
|
|
// Use the soname.
|
|
|
|
fname += targetNameSO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Use the canonical name.
|
|
|
|
fname += targetName;
|
|
|
|
}
|
2006-02-20 03:29:30 +03:00
|
|
|
|
2006-02-19 23:25:27 +03:00
|
|
|
// Set a variable with the target name for this configuration.
|
2006-02-24 21:13:14 +03:00
|
|
|
os << "SET(" << target->GetName() << "_" << place
|
2006-02-19 23:25:27 +03:00
|
|
|
<< (this->ImportLibrary? "_IMPNAME_" : "_NAME_") << *i
|
|
|
|
<< " \"" << fname << "\")\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2006-02-24 21:13:14 +03:00
|
|
|
std::string cmInstallTargetGenerator::GetScriptReference(cmTarget* target,
|
|
|
|
const char* place,
|
|
|
|
bool useSOName)
|
2006-02-19 23:25:27 +03:00
|
|
|
{
|
|
|
|
if(this->ConfigurationTypes->empty())
|
|
|
|
{
|
2006-02-20 00:10:23 +03:00
|
|
|
// Reference the target by its one configuration name.
|
2006-02-24 21:13:14 +03:00
|
|
|
std::string targetName;
|
|
|
|
std::string targetNameSO;
|
|
|
|
std::string targetNameReal;
|
|
|
|
std::string targetNameImport;
|
2007-02-01 17:57:24 +03:00
|
|
|
std::string targetNamePDB;
|
2006-02-24 21:13:14 +03:00
|
|
|
target->GetLibraryNames(targetName, targetNameSO, targetNameReal,
|
2007-02-01 17:57:24 +03:00
|
|
|
targetNameImport, targetNamePDB,
|
|
|
|
this->ConfigurationName);
|
2006-02-24 21:13:14 +03:00
|
|
|
if(this->ImportLibrary)
|
|
|
|
{
|
|
|
|
// Use the import library name.
|
|
|
|
return targetNameImport;
|
|
|
|
}
|
|
|
|
else if(useSOName)
|
|
|
|
{
|
|
|
|
// Use the soname.
|
|
|
|
return targetNameSO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Use the canonical name.
|
|
|
|
return targetName;
|
|
|
|
}
|
2006-02-19 23:25:27 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-20 00:10:23 +03:00
|
|
|
// Reference the target using the per-configuration variable.
|
2006-02-19 23:25:27 +03:00
|
|
|
std::string ref = "${";
|
2006-02-24 21:13:14 +03:00
|
|
|
ref += target->GetName();
|
2006-02-19 23:25:27 +03:00
|
|
|
if(this->ImportLibrary)
|
|
|
|
{
|
2006-02-24 21:13:14 +03:00
|
|
|
ref += "_";
|
|
|
|
ref += place;
|
2006-02-19 23:25:27 +03:00
|
|
|
ref += "_IMPNAME_";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-24 21:13:14 +03:00
|
|
|
ref += "_";
|
|
|
|
ref += place;
|
2006-02-19 23:25:27 +03:00
|
|
|
ref += "_NAME_";
|
|
|
|
}
|
|
|
|
ref += "${CMAKE_INSTALL_CONFIG_NAME}}";
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
}
|
2006-02-24 21:13:14 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2006-05-11 23:50:11 +04:00
|
|
|
void cmInstallTargetGenerator
|
|
|
|
::AddInstallNamePatchRule(std::ostream& os,
|
|
|
|
const char* destination)
|
2006-02-24 21:13:14 +03:00
|
|
|
{
|
|
|
|
// Build a map of build-tree install_name to install-tree install_name for
|
|
|
|
// shared libraries linked to this target.
|
|
|
|
std::map<cmStdString, cmStdString> install_name_remap;
|
|
|
|
cmTarget::LinkLibraryType linkType = cmTarget::OPTIMIZED;
|
|
|
|
const char* config = this->ConfigurationName;
|
|
|
|
if(config && cmSystemTools::UpperCase(config) == "DEBUG")
|
|
|
|
{
|
|
|
|
linkType = cmTarget::DEBUG;
|
|
|
|
}
|
|
|
|
// TODO: Merge with ComputeLinkInformation.
|
2006-03-15 19:02:08 +03:00
|
|
|
const cmTarget::LinkLibraryVectorType& inLibs =
|
|
|
|
this->Target->GetLinkLibraries();
|
|
|
|
for(cmTarget::LinkLibraryVectorType::const_iterator j = inLibs.begin();
|
2006-02-24 21:13:14 +03:00
|
|
|
j != inLibs.end(); ++j)
|
|
|
|
{
|
|
|
|
std::string lib = j->first;
|
|
|
|
if((this->Target->GetType() == cmTarget::EXECUTABLE ||
|
|
|
|
lib != this->Target->GetName()) &&
|
|
|
|
(j->second == cmTarget::GENERAL || j->second == linkType))
|
|
|
|
{
|
2006-05-11 23:50:11 +04:00
|
|
|
if(cmTarget* tgt = this->Target->GetMakefile()->
|
|
|
|
GetLocalGenerator()->GetGlobalGenerator()->
|
|
|
|
FindTarget(0, lib.c_str()))
|
2006-02-24 21:13:14 +03:00
|
|
|
{
|
|
|
|
if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
|
|
|
|
{
|
2006-05-11 23:50:11 +04:00
|
|
|
// If the build tree and install tree use different path
|
|
|
|
// components of the install_name field then we need to create a
|
|
|
|
// mapping to be applied after installation.
|
2006-02-24 21:13:14 +03:00
|
|
|
std::string for_build = tgt->GetInstallNameDirForBuildTree(config);
|
2006-03-15 19:02:08 +03:00
|
|
|
std::string for_install =
|
|
|
|
tgt->GetInstallNameDirForInstallTree(config);
|
2006-02-24 21:13:14 +03:00
|
|
|
if(for_build != for_install)
|
|
|
|
{
|
|
|
|
// Map from the build-tree install_name.
|
|
|
|
this->PrepareScriptReference(os, tgt, "REMAP_FROM",
|
|
|
|
!for_build.empty(), true);
|
|
|
|
for_build += this->GetScriptReference(tgt, "REMAP_FROM", true);
|
|
|
|
|
|
|
|
// Map to the install-tree install_name.
|
|
|
|
this->PrepareScriptReference(os, tgt, "REMAP_TO",
|
|
|
|
false, true);
|
|
|
|
for_install += this->GetScriptReference(tgt, "REMAP_TO", true);
|
|
|
|
|
|
|
|
// Store the mapping entry.
|
|
|
|
install_name_remap[for_build] = for_install;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Edit the install_name of the target itself if necessary.
|
|
|
|
this->PrepareScriptReference(os, this->Target, "REMAPPED", false, true);
|
|
|
|
std::string new_id;
|
|
|
|
if(this->Target->GetType() == cmTarget::SHARED_LIBRARY)
|
|
|
|
{
|
2006-05-11 23:50:11 +04:00
|
|
|
std::string for_build =
|
|
|
|
this->Target->GetInstallNameDirForBuildTree(config);
|
|
|
|
std::string for_install =
|
|
|
|
this->Target->GetInstallNameDirForInstallTree(config);
|
2006-02-24 21:13:14 +03:00
|
|
|
if(for_build != for_install)
|
|
|
|
{
|
|
|
|
// Prepare to refer to the install-tree install_name.
|
|
|
|
new_id = for_install;
|
|
|
|
new_id += this->GetScriptReference(this->Target, "REMAPPED", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write a rule to run install_name_tool to set the install-tree
|
|
|
|
// install_name value and references.
|
|
|
|
if(!new_id.empty() || !install_name_remap.empty())
|
|
|
|
{
|
2006-05-11 23:50:11 +04:00
|
|
|
std::string component_test = "NOT CMAKE_INSTALL_COMPONENT OR "
|
|
|
|
"\"${CMAKE_INSTALL_COMPONENT}\" MATCHES \"^(";
|
2006-03-30 22:33:48 +04:00
|
|
|
component_test += this->Component;
|
|
|
|
component_test += ")$\"";
|
|
|
|
os << "IF(" << component_test << ")\n";
|
|
|
|
os << " EXECUTE_PROCESS(COMMAND install_name_tool";
|
2006-02-24 21:13:14 +03:00
|
|
|
if(!new_id.empty())
|
|
|
|
{
|
2006-03-30 22:33:48 +04:00
|
|
|
os << "\n -id \"" << new_id << "\"";
|
2006-02-24 21:13:14 +03:00
|
|
|
}
|
|
|
|
for(std::map<cmStdString, cmStdString>::const_iterator
|
|
|
|
i = install_name_remap.begin();
|
|
|
|
i != install_name_remap.end(); ++i)
|
|
|
|
{
|
2006-03-30 22:33:48 +04:00
|
|
|
os << "\n -change \"" << i->first << "\" \"" << i->second << "\"";
|
2006-02-24 21:13:14 +03:00
|
|
|
}
|
2006-06-01 23:08:36 +04:00
|
|
|
os << "\n \"$ENV{DESTDIR}" << destination << "/"
|
2006-02-24 21:13:14 +03:00
|
|
|
<< this->GetScriptReference(this->Target, "REMAPPED", true) << "\")\n";
|
2006-03-30 22:33:48 +04:00
|
|
|
os << "ENDIF(" << component_test << ")\n";
|
2006-02-24 21:13:14 +03:00
|
|
|
}
|
|
|
|
}
|