2007-06-08 15:57:16 +00: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"
|
|
|
|
|
2008-01-28 13:38:36 +00:00
|
|
|
#include "cmExportBuildFileGenerator.h"
|
2007-06-08 15:57:16 +00:00
|
|
|
|
2007-07-02 19:43:21 +00:00
|
|
|
cmExportCommand::cmExportCommand()
|
|
|
|
:cmCommand()
|
|
|
|
,ArgumentGroup()
|
2007-07-02 20:46:18 +00:00
|
|
|
,Targets(&Helper, "TARGETS")
|
2008-01-28 18:21:42 +00:00
|
|
|
,Append(&Helper, "APPEND", &ArgumentGroup)
|
2008-01-28 13:38:36 +00:00
|
|
|
,Namespace(&Helper, "NAMESPACE", &ArgumentGroup)
|
2007-07-02 20:46:18 +00:00
|
|
|
,Filename(&Helper, "FILE", &ArgumentGroup)
|
2007-07-02 19:43:21 +00: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 15:57:16 +00:00
|
|
|
// cmExportCommand
|
|
|
|
bool cmExportCommand
|
2008-01-23 15:28:26 +00:00
|
|
|
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
|
2007-06-08 15:57:16 +00:00
|
|
|
{
|
|
|
|
if(args.size() < 2 )
|
|
|
|
{
|
|
|
|
this->SetError("called with too few arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-07-02 19:43:21 +00:00
|
|
|
std::vector<std::string> unknownArgs;
|
|
|
|
this->Helper.Parse(&args, &unknownArgs);
|
|
|
|
|
|
|
|
if (!unknownArgs.empty())
|
|
|
|
{
|
|
|
|
this->SetError("Unknown arguments.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->Targets.WasFound() == false)
|
2007-06-08 15:57:16 +00:00
|
|
|
{
|
2007-07-02 19:43:21 +00:00
|
|
|
this->SetError("TARGETS option missing.");
|
2007-06-08 15:57:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-01-28 13:38:36 +00:00
|
|
|
if(!this->Filename.WasFound())
|
2007-06-08 15:57:16 +00:00
|
|
|
{
|
2008-01-28 13:38:36 +00:00
|
|
|
this->SetError("FILE <filename> option missing.");
|
2007-06-08 15:57:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-01-28 13:38:36 +00:00
|
|
|
// Make sure the file has a .cmake extension.
|
|
|
|
if(cmSystemTools::GetFilenameLastExtension(this->Filename.GetCString())
|
|
|
|
!= ".cmake")
|
2007-06-08 15:57:16 +00:00
|
|
|
{
|
2008-01-28 13:38:36 +00:00
|
|
|
cmOStringStream e;
|
|
|
|
e << "FILE option given filename \"" << this->Filename.GetString()
|
|
|
|
<< "\" which does not have an extension of \".cmake\".\n";
|
|
|
|
this->SetError(e.str().c_str());
|
|
|
|
return false;
|
2007-06-08 15:57:16 +00:00
|
|
|
}
|
|
|
|
|
2008-01-28 13:38:36 +00:00
|
|
|
// Get the file to write.
|
|
|
|
std::string fname = this->Filename.GetString();
|
|
|
|
if(cmSystemTools::FileIsFullPath(fname.c_str()))
|
2007-06-08 15:57:16 +00:00
|
|
|
{
|
2008-01-28 13:38:36 +00:00
|
|
|
if(!this->Makefile->CanIWriteThisFile(fname.c_str()))
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "FILE option given filename \"" << fname
|
|
|
|
<< "\" which is in the source tree.\n";
|
|
|
|
this->SetError(e.str().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2007-06-08 15:57:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-01-28 13:38:36 +00:00
|
|
|
// Interpret relative paths with respect to the current build dir.
|
|
|
|
fname = this->Makefile->GetCurrentOutputDirectory();
|
|
|
|
fname += "/";
|
|
|
|
fname += this->Filename.GetString();
|
2007-06-08 15:57:16 +00:00
|
|
|
}
|
|
|
|
|
2008-01-28 13:38:36 +00:00
|
|
|
// Collect the targets to be exported.
|
|
|
|
std::vector<cmTarget*> targets;
|
|
|
|
for(std::vector<std::string>::const_iterator
|
2007-07-02 19:43:21 +00:00
|
|
|
currentTarget = this->Targets.GetVector().begin();
|
|
|
|
currentTarget != this->Targets.GetVector().end();
|
2007-06-08 20:19:13 +00:00
|
|
|
++currentTarget)
|
|
|
|
{
|
2008-01-28 13:38:36 +00:00
|
|
|
if(cmTarget* target =
|
|
|
|
this->Makefile->GetLocalGenerator()->
|
|
|
|
GetGlobalGenerator()->FindTarget(0, currentTarget->c_str()))
|
|
|
|
{
|
|
|
|
if((target->GetType() == cmTarget::EXECUTABLE) ||
|
|
|
|
(target->GetType() == cmTarget::STATIC_LIBRARY) ||
|
|
|
|
(target->GetType() == cmTarget::SHARED_LIBRARY) ||
|
|
|
|
(target->GetType() == cmTarget::MODULE_LIBRARY))
|
|
|
|
{
|
|
|
|
targets.push_back(target);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "given target \"" << *currentTarget
|
|
|
|
<< "\" which is not an executable or library.";
|
|
|
|
this->SetError(e.str().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2007-06-08 20:19:13 +00:00
|
|
|
{
|
2008-01-28 13:38:36 +00:00
|
|
|
cmOStringStream e;
|
|
|
|
e << "given target \"" << *currentTarget
|
|
|
|
<< "\" which is not built by this project.";
|
|
|
|
this->SetError(e.str().c_str());
|
2007-06-08 20:19:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-28 13:38:36 +00:00
|
|
|
// Setup export file generation.
|
|
|
|
cmExportBuildFileGenerator ebfg;
|
|
|
|
ebfg.SetExportFile(fname.c_str());
|
|
|
|
ebfg.SetNamespace(this->Namespace.GetCString());
|
2008-01-28 18:21:42 +00:00
|
|
|
ebfg.SetAppendMode(this->Append.IsEnabled());
|
2008-01-28 13:38:36 +00:00
|
|
|
ebfg.SetExports(&targets);
|
2008-01-30 22:25:52 +00:00
|
|
|
ebfg.SetCommand(this);
|
2008-01-28 13:38:36 +00:00
|
|
|
|
|
|
|
// Compute the set of configurations exported.
|
|
|
|
if(const char* types =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
|
2007-06-08 15:57:16 +00:00
|
|
|
{
|
2008-01-28 13:38:36 +00:00
|
|
|
std::vector<std::string> configurationTypes;
|
|
|
|
cmSystemTools::ExpandListArgument(types, configurationTypes);
|
|
|
|
for(std::vector<std::string>::const_iterator
|
|
|
|
ci = configurationTypes.begin();
|
|
|
|
ci != configurationTypes.end(); ++ci)
|
2007-06-08 15:57:16 +00:00
|
|
|
{
|
2008-01-28 13:38:36 +00:00
|
|
|
ebfg.AddConfiguration(ci->c_str());
|
2007-06-08 15:57:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-28 13:38:36 +00:00
|
|
|
else if(const char* config =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
|
|
|
|
{
|
|
|
|
ebfg.AddConfiguration(config);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ebfg.AddConfiguration("");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the import file.
|
2008-02-06 19:20:36 +00:00
|
|
|
if(!ebfg.GenerateImportFile() && this->ErrorMessage.empty())
|
2008-01-28 13:38:36 +00:00
|
|
|
{
|
|
|
|
this->SetError("could not write export file.");
|
|
|
|
return false;
|
|
|
|
}
|
2007-06-08 15:57:16 +00:00
|
|
|
|
2008-01-30 22:25:52 +00:00
|
|
|
// Report generated error message if any.
|
|
|
|
if(!this->ErrorMessage.empty())
|
|
|
|
{
|
|
|
|
this->SetError(this->ErrorMessage.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-08 15:57:16 +00:00
|
|
|
return true;
|
|
|
|
}
|