2001-03-02 00:47:05 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: Insight Segmentation & Registration Toolkit
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
2001-04-27 16:01:17 +04:00
|
|
|
Copyright (c) 2001 Insight Consortium
|
|
|
|
All rights reserved.
|
2001-03-02 00:47:05 +03:00
|
|
|
|
2001-04-27 16:01:17 +04:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2001-03-02 00:47:05 +03:00
|
|
|
|
2001-04-27 16:01:17 +04:00
|
|
|
* Redistributions of source code must retain the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
* The name of the Insight Consortium, nor the names of any consortium members,
|
|
|
|
nor of any contributors, may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
* Modified source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2001-03-02 00:47:05 +03:00
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
#include "cmCablePackageCommand.h"
|
|
|
|
#include "cmCacheManager.h"
|
2001-04-16 18:01:13 +04:00
|
|
|
#include "cmTarget.h"
|
2001-03-02 00:47:05 +03:00
|
|
|
|
2001-03-15 18:42:43 +03:00
|
|
|
|
|
|
|
cmCablePackageCommand::~cmCablePackageCommand()
|
|
|
|
{
|
|
|
|
// If we are the owner of the cmCableData, we must delete it here.
|
|
|
|
// For most cmCableCommands, the cmCableCommand destructor will take
|
|
|
|
// care of this. If this package happens to be the last one, and is
|
|
|
|
// the owner, then the destructor of cmCableData will call back to a method
|
|
|
|
// in this class after the package part of it has been freed!
|
|
|
|
if(m_CableData && m_CableData->OwnerIs(this))
|
|
|
|
{
|
|
|
|
delete m_CableData;
|
|
|
|
// Make sure our superclass's destructor doesn't try to delete the
|
|
|
|
// cmCableData too.
|
|
|
|
m_CableData = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-02 00:47:05 +03:00
|
|
|
// cmCablePackageCommand
|
2001-06-06 21:19:15 +04:00
|
|
|
bool cmCablePackageCommand::InitialPass(std::vector<std::string>& args)
|
2001-03-02 00:47:05 +03:00
|
|
|
{
|
2001-04-11 22:59:02 +04:00
|
|
|
if(args.size() != 2)
|
2001-03-02 00:47:05 +03:00
|
|
|
{
|
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
2001-04-11 22:59:02 +04:00
|
|
|
|
|
|
|
// setup this once. Really this should probably be moved somewhere else
|
|
|
|
// at some point.
|
|
|
|
{
|
|
|
|
// We must add a custom rule to cause the cable_config.xml to be re-built
|
|
|
|
// when it is removed. Rebuilding it means re-running CMake.
|
2001-04-30 19:51:17 +04:00
|
|
|
std::string cMakeLists = m_Makefile->GetStartDirectory();
|
2001-04-11 22:59:02 +04:00
|
|
|
cMakeLists += "/";
|
2001-04-30 19:51:17 +04:00
|
|
|
cMakeLists += "CMakeLists.txt";
|
2001-05-04 18:44:26 +04:00
|
|
|
cMakeLists = cmSystemTools::EscapeSpaces(cMakeLists.c_str());
|
2001-04-11 22:59:02 +04:00
|
|
|
|
2001-06-07 22:52:29 +04:00
|
|
|
std::string command = "${CMAKE_COMMAND}";
|
|
|
|
std::string commandArgs = cMakeLists;
|
2001-04-11 22:59:02 +04:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2001-06-07 22:52:29 +04:00
|
|
|
commandArgs += " -DSP";
|
2001-04-11 22:59:02 +04:00
|
|
|
#endif
|
2001-06-07 22:52:29 +04:00
|
|
|
commandArgs += " -H\"";
|
|
|
|
commandArgs += m_Makefile->GetHomeDirectory();
|
|
|
|
commandArgs += "\" -S\"";
|
|
|
|
commandArgs += m_Makefile->GetStartDirectory();
|
|
|
|
commandArgs += "\" -O\"";
|
|
|
|
commandArgs += m_Makefile->GetStartOutputDirectory();
|
|
|
|
commandArgs += "\" -B\"";
|
|
|
|
commandArgs += m_Makefile->GetHomeOutputDirectory();
|
|
|
|
commandArgs += "\"";
|
|
|
|
m_Makefile->ExpandVariablesInString(commandArgs);
|
2001-05-04 18:44:26 +04:00
|
|
|
m_Makefile->ExpandVariablesInString(command);
|
2001-04-11 22:59:02 +04:00
|
|
|
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
m_Makefile->AddCustomCommand(cMakeLists.c_str(),
|
|
|
|
command.c_str(),
|
2001-06-07 22:52:29 +04:00
|
|
|
commandArgs.c_str(),
|
2001-04-11 22:59:02 +04:00
|
|
|
depends,
|
|
|
|
"cable_config.xml", args[1].c_str());
|
|
|
|
}
|
|
|
|
|
2001-03-02 00:47:05 +03:00
|
|
|
// This command needs to access the Cable data.
|
|
|
|
this->SetupCableData();
|
|
|
|
|
|
|
|
// The argument is the package name.
|
|
|
|
m_PackageName = args[0];
|
2001-04-11 22:59:02 +04:00
|
|
|
m_TargetName = args[1];
|
2001-03-15 18:42:43 +03:00
|
|
|
|
2001-03-02 00:47:05 +03:00
|
|
|
// Ask the cable data to begin the package. This may call another
|
2001-03-09 00:13:27 +03:00
|
|
|
// cmCablePackageCommand's WritePackageFooter(). This will call
|
|
|
|
// this cmCablePackageCommand's WritePackageHeader().
|
2001-03-02 00:47:05 +03:00
|
|
|
m_CableData->BeginPackage(this);
|
2001-03-09 18:52:03 +03:00
|
|
|
|
2001-03-09 00:13:27 +03:00
|
|
|
// Add custom rules to the makefile to generate this package's source
|
|
|
|
// files.
|
2001-04-26 23:27:38 +04:00
|
|
|
{
|
2001-03-09 00:13:27 +03:00
|
|
|
std::string command = "${CABLE}";
|
2001-03-09 18:52:03 +03:00
|
|
|
m_Makefile->ExpandVariablesInString(command);
|
2001-03-20 21:20:59 +03:00
|
|
|
std::vector<std::string> depends;
|
2001-03-09 00:13:27 +03:00
|
|
|
depends.push_back(command);
|
2001-06-07 22:52:29 +04:00
|
|
|
std::string commandArgs = " cable_config.xml";
|
2001-03-09 00:13:27 +03:00
|
|
|
|
2001-03-20 21:20:59 +03:00
|
|
|
std::vector<std::string> outputs;
|
|
|
|
outputs.push_back("Cxx/"+m_PackageName+"_cxx.cxx");
|
|
|
|
outputs.push_back("Cxx/"+m_PackageName+"_cxx.h");
|
2001-03-09 00:13:27 +03:00
|
|
|
|
2001-03-20 21:20:59 +03:00
|
|
|
// A rule for the package's source files.
|
2001-03-09 01:30:53 +03:00
|
|
|
m_Makefile->AddCustomCommand("cable_config.xml",
|
2001-03-09 00:13:27 +03:00
|
|
|
command.c_str(),
|
2001-06-07 22:52:29 +04:00
|
|
|
commandArgs.c_str(),
|
2001-03-20 21:20:59 +03:00
|
|
|
depends,
|
2001-04-11 22:59:02 +04:00
|
|
|
outputs, m_TargetName.c_str());
|
2001-04-26 23:27:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add custom rules to the makefile to generate this package's xml files.
|
|
|
|
{
|
|
|
|
std::string command = "${GCCXML}";
|
|
|
|
m_Makefile->ExpandVariablesInString(command);
|
2001-04-27 22:52:16 +04:00
|
|
|
// Only add the rule if GCC-XML is available.
|
|
|
|
if((command != "") && (command != "${GCCXML}"))
|
|
|
|
{
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
depends.push_back(command);
|
|
|
|
std::string input = m_Makefile->GetStartOutputDirectory();
|
|
|
|
input = input + "/Cxx/"+m_PackageName+"_cxx.cxx";
|
|
|
|
std::string output = "Cxx/"+m_PackageName+"_cxx.xml";
|
|
|
|
command = "\""+command+"\" ${CXX_FLAGS} -fsyntax-only -fxml=" + output + " -c " + input;
|
|
|
|
|
|
|
|
std::vector<std::string> outputs;
|
|
|
|
outputs.push_back("Cxx/"+m_PackageName+"_cxx.xml");
|
|
|
|
|
|
|
|
// A rule for the package's source files.
|
|
|
|
m_Makefile->AddCustomCommand(input.c_str(),
|
|
|
|
command.c_str(),
|
2001-06-07 22:52:29 +04:00
|
|
|
"",
|
2001-04-27 22:52:16 +04:00
|
|
|
depends,
|
|
|
|
outputs, m_TargetName.c_str());
|
|
|
|
}
|
2001-04-26 23:27:38 +04:00
|
|
|
}
|
2001-03-02 00:47:05 +03:00
|
|
|
|
2001-04-16 18:01:13 +04:00
|
|
|
// add the source list to the target
|
2001-04-19 21:28:46 +04:00
|
|
|
m_Makefile->GetTargets()[m_TargetName.c_str()].GetSourceLists().push_back(m_PackageName);
|
2001-04-16 18:01:13 +04:00
|
|
|
|
2001-03-02 00:47:05 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-09 00:13:27 +03:00
|
|
|
void cmCablePackageCommand::FinalPass()
|
|
|
|
{
|
|
|
|
// Add a rule to build the generated package.
|
|
|
|
std::string fileName = "Cxx/"+m_PackageName+"_cxx";
|
|
|
|
std::string filePath = m_Makefile->GetStartOutputDirectory();
|
2001-04-25 00:49:12 +04:00
|
|
|
cmSourceFile file;
|
|
|
|
file.SetIsAnAbstractClass(false);
|
|
|
|
file.SetIsAHeaderFileOnly(false);
|
2001-03-09 00:13:27 +03:00
|
|
|
file.SetName(fileName.c_str(), filePath.c_str(), "cxx", false);
|
2001-04-25 00:49:12 +04:00
|
|
|
m_Makefile->AddSource(file, m_PackageName.c_str());
|
2001-03-09 00:13:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-02 00:47:05 +03:00
|
|
|
/**
|
|
|
|
* Write a CABLE package header.
|
|
|
|
*/
|
|
|
|
void cmCablePackageCommand::WritePackageHeader() const
|
|
|
|
{
|
|
|
|
std::ostream& os = m_CableData->GetOutputStream();
|
|
|
|
cmCableData::Indentation indent = m_CableData->GetIndentation();
|
|
|
|
os << indent << "<Package name=\"" << m_PackageName.c_str() << "\">"
|
|
|
|
<< std::endl;
|
|
|
|
m_CableData->Indent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a CABLE package footer.
|
|
|
|
*/
|
|
|
|
void cmCablePackageCommand::WritePackageFooter() const
|
|
|
|
{
|
|
|
|
m_CableData->Unindent();
|
|
|
|
std::ostream& os = m_CableData->GetOutputStream();
|
|
|
|
cmCableData::Indentation indent = m_CableData->GetIndentation();
|
|
|
|
os << indent << "</Package> <!-- \"" << m_PackageName.c_str() << "\" -->"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
|