2003-01-21 00:59:02 +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 "cmExportLibraryDependencies.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
2004-03-15 18:44:53 +03:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2003-01-21 00:59:02 +03:00
|
|
|
#include "cmake.h"
|
|
|
|
|
2006-03-17 00:04:30 +03:00
|
|
|
#include <cmsys/auto_ptr.hxx>
|
2004-03-16 20:54:39 +03:00
|
|
|
|
2006-05-10 23:08:38 +04:00
|
|
|
bool cmExportLibraryDependenciesCommand
|
2008-01-23 18:28:26 +03:00
|
|
|
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
|
2003-01-21 00:59:02 +03:00
|
|
|
{
|
|
|
|
if(args.size() < 1 )
|
|
|
|
{
|
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// store the arguments for the final pass
|
2007-06-15 18:10:24 +04:00
|
|
|
this->Filename = args[0];
|
|
|
|
this->Append = false;
|
|
|
|
if(args.size() > 1)
|
|
|
|
{
|
|
|
|
if(args[1] == "APPEND")
|
|
|
|
{
|
|
|
|
this->Append = true;
|
|
|
|
}
|
|
|
|
}
|
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.
|
2006-03-17 00:04:30 +03:00
|
|
|
cmsys::auto_ptr<std::ofstream> foutPtr;
|
2007-06-15 18:10:24 +04:00
|
|
|
if(this->Append)
|
2003-01-21 00:59:02 +03:00
|
|
|
{
|
2006-03-17 00:04:30 +03:00
|
|
|
cmsys::auto_ptr<std::ofstream> ap(
|
2007-06-15 18:10:24 +04:00
|
|
|
new std::ofstream(this->Filename.c_str(), std::ios::app));
|
2006-03-16 23:50:21 +03:00
|
|
|
foutPtr = ap;
|
2003-01-21 00:59:02 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-17 00:04:30 +03:00
|
|
|
cmsys::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;
|
2003-01-21 00:59:02 +03:00
|
|
|
}
|
2006-03-16 22:14:15 +03:00
|
|
|
std::ostream& fout = *foutPtr.get();
|
2004-03-15 18:44:53 +03:00
|
|
|
|
2003-01-21 00:59:02 +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;
|
|
|
|
}
|
2007-06-15 18:10:24 +04:00
|
|
|
const cmake* cm = this->Makefile->GetCMakeInstance();
|
|
|
|
const cmGlobalGenerator* global = cm->GetGlobalGenerator();
|
|
|
|
const std::vector<cmLocalGenerator *>& locals = global->GetLocalGenerators();
|
2003-01-21 00:59:02 +03:00
|
|
|
std::string libDepName;
|
2007-06-15 18:10:24 +04:00
|
|
|
for(std::vector<cmLocalGenerator *>::const_iterator i = locals.begin();
|
2003-01-21 00:59:02 +03:00
|
|
|
i != locals.end(); ++i)
|
|
|
|
{
|
2007-06-15 18:10:24 +04:00
|
|
|
const cmLocalGenerator* gen = *i;
|
|
|
|
const cmTargets &tgts = gen->GetMakefile()->GetTargets();
|
2003-08-01 17:11:04 +04:00
|
|
|
std::vector<std::string> depends;
|
|
|
|
const char *defType;
|
2007-06-15 18:10:24 +04:00
|
|
|
for(cmTargets::const_iterator l = tgts.begin();
|
2003-01-21 00:59:02 +03:00
|
|
|
l != tgts.end(); ++l)
|
|
|
|
{
|
2007-05-23 23:40:12 +04:00
|
|
|
libDepName = l->first;
|
|
|
|
libDepName += "_LIB_DEPENDS";
|
|
|
|
const char* def = this->Makefile->GetDefinition(libDepName.c_str());
|
|
|
|
if(def)
|
2003-01-21 00:59:02 +03:00
|
|
|
{
|
2007-05-23 23:40:12 +04:00
|
|
|
fout << "SET(" << libDepName << " \"" << def << "\")\n";
|
|
|
|
// now for each dependency, check for link type
|
|
|
|
cmSystemTools::ExpandListArgument(def, depends);
|
|
|
|
for(std::vector<std::string>::const_iterator d = depends.begin();
|
|
|
|
d != depends.end(); ++d)
|
2003-01-21 00:59:02 +03:00
|
|
|
{
|
2007-05-23 23:40:12 +04:00
|
|
|
libDepName = *d;
|
|
|
|
libDepName += "_LINK_TYPE";
|
|
|
|
defType = this->Makefile->GetDefinition(libDepName.c_str());
|
|
|
|
libDepName = cmSystemTools::EscapeSpaces(libDepName.c_str());
|
|
|
|
if(defType)
|
2003-08-01 17:11:04 +04:00
|
|
|
{
|
2007-05-23 23:40:12 +04:00
|
|
|
fout << "SET(" << libDepName << " \"" << defType << "\")\n";
|
2003-08-01 17:11:04 +04:00
|
|
|
}
|
2003-01-21 00:59:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|