2007-06-08 19:57:16 +04: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 "cmExportCommand.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmake.h"
|
|
|
|
|
|
|
|
#include <cmsys/auto_ptr.hxx>
|
|
|
|
|
2007-07-02 23:43:21 +04:00
|
|
|
cmExportCommand::cmExportCommand()
|
|
|
|
:cmCommand()
|
|
|
|
,ArgumentGroup()
|
2007-07-03 00:46:18 +04:00
|
|
|
,Targets(&Helper, "TARGETS")
|
|
|
|
,Append(&Helper, "APPEND", &ArgumentGroup)
|
|
|
|
,Prefix(&Helper, "PREFIX", &ArgumentGroup)
|
|
|
|
,Filename(&Helper, "FILE", &ArgumentGroup)
|
2007-07-02 23:43:21 +04:00
|
|
|
{
|
|
|
|
// at first TARGETS
|
|
|
|
this->Targets.Follows(0);
|
|
|
|
// and after that the other options in any order
|
|
|
|
this->ArgumentGroup.Follows(&this->Targets);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-08 19:57:16 +04:00
|
|
|
// cmExportCommand
|
|
|
|
bool cmExportCommand
|
|
|
|
::InitialPass(std::vector<std::string> const& args)
|
|
|
|
{
|
|
|
|
if(args.size() < 2 )
|
|
|
|
{
|
|
|
|
this->SetError("called with too few arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-07-02 23:43:21 +04:00
|
|
|
std::vector<std::string> unknownArgs;
|
|
|
|
this->Helper.Parse(&args, &unknownArgs);
|
|
|
|
|
|
|
|
if (!unknownArgs.empty())
|
|
|
|
{
|
|
|
|
this->SetError("Unknown arguments.");
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->Targets.WasFound() == false)
|
2007-06-08 19:57:16 +04:00
|
|
|
{
|
2007-07-02 23:43:21 +04:00
|
|
|
this->SetError("TARGETS option missing.");
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
2007-06-08 19:57:16 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-07-02 23:43:21 +04:00
|
|
|
|
|
|
|
if ( !this->Makefile->CanIWriteThisFile(this->Filename.GetString().c_str()) )
|
2007-06-08 19:57:16 +04:00
|
|
|
{
|
2007-07-02 23:43:21 +04:00
|
|
|
std::string e = "attempted to write a file: " + this->Filename.GetString()
|
2007-06-08 19:57:16 +04:00
|
|
|
+ " into a source directory.";
|
|
|
|
this->SetError(e.c_str());
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-07-02 23:43:21 +04:00
|
|
|
if((this->Targets.GetVector().empty())||(this->Filename.GetString().empty()))
|
2007-06-08 19:57:16 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use copy-if-different if not appending.
|
|
|
|
cmsys::auto_ptr<std::ofstream> foutPtr;
|
2007-07-02 23:43:21 +04:00
|
|
|
if(this->Append.IsEnabled())
|
2007-06-08 19:57:16 +04:00
|
|
|
{
|
|
|
|
cmsys::auto_ptr<std::ofstream> ap(
|
2007-07-02 23:43:21 +04:00
|
|
|
new std::ofstream(this->Filename.GetString().c_str(), std::ios::app));
|
2007-06-08 19:57:16 +04:00
|
|
|
foutPtr = ap;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmsys::auto_ptr<cmGeneratedFileStream> ap(
|
2007-07-02 23:43:21 +04:00
|
|
|
new cmGeneratedFileStream(this->Filename.GetString().c_str(), true));
|
2007-06-08 19:57:16 +04:00
|
|
|
ap->SetCopyIfDifferent(true);
|
|
|
|
foutPtr = ap;
|
|
|
|
}
|
|
|
|
std::ostream& fout = *foutPtr.get();
|
|
|
|
|
|
|
|
if (!fout)
|
|
|
|
{
|
2007-07-02 23:43:21 +04:00
|
|
|
cmSystemTools::Error("Error Writing ", this->Filename.GetString().c_str());
|
2007-06-08 19:57:16 +04:00
|
|
|
cmSystemTools::ReportLastSystemError("");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the following code may move into an "export generator"
|
|
|
|
// Compute the set of configurations.
|
|
|
|
std::vector<std::string> configurationTypes;
|
|
|
|
if(const char* types =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
|
|
|
|
{
|
|
|
|
cmSystemTools::ExpandListArgument(types, configurationTypes);
|
|
|
|
}
|
|
|
|
if(configurationTypes.empty())
|
|
|
|
{
|
|
|
|
const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
|
|
|
|
if (config!=0)
|
|
|
|
{
|
|
|
|
configurationTypes.push_back(config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-02 23:43:21 +04:00
|
|
|
for(std::vector<std::string>::const_iterator
|
|
|
|
currentTarget = this->Targets.GetVector().begin();
|
|
|
|
currentTarget != this->Targets.GetVector().end();
|
2007-06-09 00:19:13 +04:00
|
|
|
++currentTarget)
|
|
|
|
{
|
|
|
|
cmTarget* target = this->Makefile->GetLocalGenerator()->
|
|
|
|
GetGlobalGenerator()->FindTarget(0, currentTarget->c_str(), true);
|
|
|
|
if (target == 0)
|
|
|
|
{
|
|
|
|
std::string e = "detected unknown target: " + *currentTarget;
|
|
|
|
this->SetError(e.c_str());
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-02 23:43:21 +04:00
|
|
|
for(std::vector<std::string>::const_iterator
|
|
|
|
currentTarget = this->Targets.GetVector().begin();
|
|
|
|
currentTarget != this->Targets.GetVector().end();
|
2007-06-08 19:57:16 +04:00
|
|
|
++currentTarget)
|
|
|
|
{
|
|
|
|
// Look for a CMake target with the given name, which is an executable
|
|
|
|
// and which can be run
|
2007-06-09 00:19:13 +04:00
|
|
|
cmTarget* target = this->Makefile->GetLocalGenerator()->
|
|
|
|
GetGlobalGenerator()->FindTarget(0, currentTarget->c_str(), true);
|
2007-06-08 19:57:16 +04:00
|
|
|
if ((target != 0)
|
|
|
|
&& ((target->GetType() == cmTarget::EXECUTABLE)
|
|
|
|
|| (target->GetType() == cmTarget::STATIC_LIBRARY)
|
|
|
|
|| (target->GetType() == cmTarget::SHARED_LIBRARY)
|
|
|
|
|| (target->GetType() == cmTarget::MODULE_LIBRARY)))
|
|
|
|
{
|
|
|
|
switch (target->GetType())
|
|
|
|
{
|
|
|
|
case cmTarget::EXECUTABLE:
|
2007-07-02 23:43:21 +04:00
|
|
|
fout << "ADD_EXECUTABLE("
|
|
|
|
<< this->Prefix.GetString().c_str() << currentTarget->c_str()
|
|
|
|
<< " IMPORT )\n";
|
2007-06-08 19:57:16 +04:00
|
|
|
break;
|
|
|
|
case cmTarget::STATIC_LIBRARY:
|
2007-07-02 23:43:21 +04:00
|
|
|
fout << "ADD_LIBRARY("
|
|
|
|
<< this->Prefix.GetString().c_str() << currentTarget->c_str()
|
|
|
|
<< " STATIC IMPORT )\n";
|
2007-06-08 19:57:16 +04:00
|
|
|
break;
|
|
|
|
case cmTarget::SHARED_LIBRARY:
|
2007-07-02 23:43:21 +04:00
|
|
|
fout << "ADD_LIBRARY("
|
|
|
|
<< this->Prefix.GetString().c_str() << currentTarget->c_str()
|
|
|
|
<< " SHARED IMPORT )\n";
|
2007-06-08 19:57:16 +04:00
|
|
|
break;
|
|
|
|
case cmTarget::MODULE_LIBRARY:
|
2007-07-02 23:43:21 +04:00
|
|
|
fout << "ADD_LIBRARY("
|
|
|
|
<< this->Prefix.GetString().c_str() << currentTarget->c_str()
|
|
|
|
<< " MODULE IMPORT )\n";
|
2007-06-08 19:57:16 +04:00
|
|
|
break;
|
|
|
|
default: // should never happen
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-07-02 23:43:21 +04:00
|
|
|
fout << "SET_TARGET_PROPERTIES(" << this->Prefix.GetString().c_str()
|
2007-06-09 00:19:13 +04:00
|
|
|
<< currentTarget->c_str() << " PROPERTIES \n"
|
|
|
|
<< " LOCATION " << target->GetLocation(0) << "\n";
|
|
|
|
for(std::vector<std::string>::const_iterator
|
|
|
|
currentConfig = configurationTypes.begin();
|
2007-06-08 19:57:16 +04:00
|
|
|
currentConfig != configurationTypes.end();
|
|
|
|
++currentConfig)
|
|
|
|
{
|
|
|
|
if (!currentConfig->empty())
|
|
|
|
{
|
|
|
|
const char* loc = target->GetLocation(currentConfig->c_str());
|
|
|
|
if (loc && *loc)
|
|
|
|
{
|
2007-06-09 00:19:13 +04:00
|
|
|
fout << " " << currentConfig->c_str()
|
|
|
|
<< "_LOCATION " << loc << "\n";
|
2007-06-08 19:57:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fout << " )\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|