2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2003-01-21 00:59:02 +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.
|
2003-01-21 00:59:02 +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.
|
|
|
|
============================================================================*/
|
2014-02-10 00:55:17 +04:00
|
|
|
#include "cmExportLibraryDependenciesCommand.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2004-03-15 18:44:53 +03:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmGlobalGenerator.h"
|
2008-04-27 15:01:05 +04:00
|
|
|
#include "cmVersion.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmake.h"
|
2003-01-21 00:59:02 +03:00
|
|
|
|
2016-06-28 17:17:52 +03:00
|
|
|
#include <cm_auto_ptr.hxx>
|
2004-03-16 20:54:39 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmExportLibraryDependenciesCommand::InitialPass(
|
|
|
|
std::vector<std::string> const& args, cmExecutionStatus&)
|
2003-01-21 00:59:02 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Disallowed(
|
|
|
|
cmPolicies::CMP0033,
|
|
|
|
"The export_library_dependencies command should not be called; "
|
|
|
|
"see CMP0033.")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (args.size() < 1) {
|
2003-01-21 00:59:02 +03:00
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2003-01-21 00:59:02 +03:00
|
|
|
// store the arguments for the final pass
|
2007-06-15 18:10:24 +04:00
|
|
|
this->Filename = args[0];
|
|
|
|
this->Append = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() > 1) {
|
|
|
|
if (args[1] == "APPEND") {
|
2007-06-15 18:10:24 +04:00
|
|
|
this->Append = true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2003-01-21 00:59:02 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmExportLibraryDependenciesCommand::FinalPass()
|
|
|
|
{
|
2007-06-15 18:10:24 +04:00
|
|
|
// export_library_dependencies() shouldn't modify anything
|
|
|
|
// ensure this by calling a const method
|
|
|
|
this->ConstFinalPass();
|
|
|
|
}
|
2004-03-15 18:44:53 +03:00
|
|
|
|
2007-06-15 18:10:24 +04:00
|
|
|
void cmExportLibraryDependenciesCommand::ConstFinalPass() const
|
|
|
|
{
|
2004-03-15 18:44:53 +03:00
|
|
|
// Use copy-if-different if not appending.
|
2016-06-28 17:17:52 +03:00
|
|
|
CM_AUTO_PTR<cmsys::ofstream> foutPtr;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Append) {
|
2016-06-28 17:17:52 +03:00
|
|
|
CM_AUTO_PTR<cmsys::ofstream> ap(
|
2014-01-04 09:47:13 +04:00
|
|
|
new cmsys::ofstream(this->Filename.c_str(), std::ios::app));
|
2006-03-16 23:50:21 +03:00
|
|
|
foutPtr = ap;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2016-06-28 17:17:52 +03:00
|
|
|
CM_AUTO_PTR<cmGeneratedFileStream> ap(
|
2007-06-15 18:10:24 +04:00
|
|
|
new cmGeneratedFileStream(this->Filename.c_str(), true));
|
2004-11-03 15:51:51 +03:00
|
|
|
ap->SetCopyIfDifferent(true);
|
2006-03-16 23:50:21 +03:00
|
|
|
foutPtr = ap;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-16 22:14:15 +03:00
|
|
|
std::ostream& fout = *foutPtr.get();
|
2004-03-15 18:44:53 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!fout) {
|
2007-06-15 18:10:24 +04:00
|
|
|
cmSystemTools::Error("Error Writing ", this->Filename.c_str());
|
2004-09-08 00:55:25 +04:00
|
|
|
cmSystemTools::ReportLastSystemError("");
|
2003-01-21 00:59:02 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-02-11 18:31:44 +03:00
|
|
|
|
|
|
|
// Collect dependency information about all library targets built in
|
|
|
|
// the project.
|
2008-02-20 21:36:38 +03:00
|
|
|
cmake* cm = this->Makefile->GetCMakeInstance();
|
|
|
|
cmGlobalGenerator* global = cm->GetGlobalGenerator();
|
2015-08-02 14:18:30 +03:00
|
|
|
const std::vector<cmMakefile*>& locals = global->GetMakefiles();
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, std::string> libDepsOld;
|
|
|
|
std::map<std::string, std::string> libDepsNew;
|
|
|
|
std::map<std::string, std::string> libTypes;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmMakefile*>::const_iterator i = locals.begin();
|
|
|
|
i != locals.end(); ++i) {
|
|
|
|
const cmTargets& tgts = (*i)->GetTargets();
|
|
|
|
for (cmTargets::const_iterator l = tgts.begin(); l != tgts.end(); ++l) {
|
2008-02-11 18:31:44 +03:00
|
|
|
// Get the current target.
|
|
|
|
cmTarget const& target = l->second;
|
|
|
|
|
|
|
|
// Skip non-library targets.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target.GetType() < cmState::STATIC_LIBRARY ||
|
|
|
|
target.GetType() > cmState::MODULE_LIBRARY) {
|
2008-02-11 18:31:44 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-02-11 18:31:44 +03:00
|
|
|
|
|
|
|
// Construct the dependency variable name.
|
|
|
|
std::string targetEntry = target.GetName();
|
|
|
|
targetEntry += "_LIB_DEPENDS";
|
|
|
|
|
2014-07-14 22:19:32 +04:00
|
|
|
// Construct the dependency variable value with the direct link
|
|
|
|
// dependencies.
|
2008-02-11 18:31:44 +03:00
|
|
|
std::string valueOld;
|
|
|
|
std::string valueNew;
|
2014-07-14 22:19:32 +04:00
|
|
|
cmTarget::LinkLibraryVectorType const& libs =
|
|
|
|
target.GetOriginalLinkLibraries();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cmTarget::LinkLibraryVectorType::const_iterator li = libs.begin();
|
|
|
|
li != libs.end(); ++li) {
|
2008-02-11 18:31:44 +03:00
|
|
|
std::string ltVar = li->first;
|
|
|
|
ltVar += "_LINK_TYPE";
|
|
|
|
std::string ltValue;
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (li->second) {
|
2015-10-10 14:56:36 +03:00
|
|
|
case GENERAL_LibraryType:
|
2008-02-11 18:31:44 +03:00
|
|
|
valueNew += "general;";
|
|
|
|
ltValue = "general";
|
|
|
|
break;
|
2015-10-10 14:56:36 +03:00
|
|
|
case DEBUG_LibraryType:
|
2008-02-11 18:31:44 +03:00
|
|
|
valueNew += "debug;";
|
|
|
|
ltValue = "debug";
|
|
|
|
break;
|
2015-10-10 14:56:36 +03:00
|
|
|
case OPTIMIZED_LibraryType:
|
2008-02-11 18:31:44 +03:00
|
|
|
valueNew += "optimized;";
|
|
|
|
ltValue = "optimized";
|
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-02-20 21:36:38 +03:00
|
|
|
std::string lib = li->first;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmTarget* libtgt = global->FindTarget(lib)) {
|
2008-02-20 21:36:38 +03:00
|
|
|
// Handle simple output name changes. This command is
|
|
|
|
// deprecated so we do not support full target name
|
|
|
|
// translation (which requires per-configuration info).
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* outname = libtgt->GetProperty("OUTPUT_NAME")) {
|
2008-02-20 21:36:38 +03:00
|
|
|
lib = outname;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-02-20 21:36:38 +03:00
|
|
|
valueOld += lib;
|
2008-02-11 18:31:44 +03:00
|
|
|
valueOld += ";";
|
2008-02-20 21:36:38 +03:00
|
|
|
valueNew += lib;
|
2008-02-11 18:31:44 +03:00
|
|
|
valueNew += ";";
|
|
|
|
|
|
|
|
std::string& ltEntry = libTypes[ltVar];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (ltEntry.empty()) {
|
2008-02-11 18:31:44 +03:00
|
|
|
ltEntry = ltValue;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (ltEntry != ltValue) {
|
2008-02-11 18:31:44 +03:00
|
|
|
ltEntry = "general";
|
2003-01-21 00:59:02 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-02-11 18:31:44 +03:00
|
|
|
libDepsNew[targetEntry] = valueNew;
|
|
|
|
libDepsOld[targetEntry] = valueOld;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-02-11 18:31:44 +03:00
|
|
|
|
|
|
|
// Generate dependency information for both old and new style CMake
|
|
|
|
// versions.
|
|
|
|
const char* vertest =
|
|
|
|
"\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" GREATER 2.4";
|
2016-07-10 16:35:24 +03:00
|
|
|
fout << "# Generated by CMake\n\n";
|
2013-08-22 13:30:19 +04:00
|
|
|
fout << "if(" << vertest << ")\n";
|
2008-02-11 18:31:44 +03:00
|
|
|
fout << " # Information for CMake 2.6 and above.\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<std::string, std::string>::const_iterator i =
|
|
|
|
libDepsNew.begin();
|
|
|
|
i != libDepsNew.end(); ++i) {
|
|
|
|
if (!i->second.empty()) {
|
2013-08-22 13:30:19 +04:00
|
|
|
fout << " set(\"" << i->first << "\" \"" << i->second << "\")\n";
|
2008-02-11 18:31:44 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-08-22 13:30:19 +04:00
|
|
|
fout << "else()\n";
|
2008-02-11 18:31:44 +03:00
|
|
|
fout << " # Information for CMake 2.4 and lower.\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<std::string, std::string>::const_iterator i =
|
|
|
|
libDepsOld.begin();
|
|
|
|
i != libDepsOld.end(); ++i) {
|
|
|
|
if (!i->second.empty()) {
|
2013-08-22 13:30:19 +04:00
|
|
|
fout << " set(\"" << i->first << "\" \"" << i->second << "\")\n";
|
2008-02-11 18:31:44 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
for (std::map<std::string, std::string>::const_iterator i = libTypes.begin();
|
|
|
|
i != libTypes.end(); ++i) {
|
|
|
|
if (i->second != "general") {
|
2013-08-22 13:30:19 +04:00
|
|
|
fout << " set(\"" << i->first << "\" \"" << i->second << "\")\n";
|
2003-01-21 00:59:02 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-08-22 13:30:19 +04:00
|
|
|
fout << "endif()\n";
|
2003-01-21 00:59:02 +03:00
|
|
|
return;
|
|
|
|
}
|