2002-05-08 21:11:53 +04:00
|
|
|
/*=========================================================================
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
2002-05-08 21:11:53 +04:00
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
2002-05-08 21:11:53 +04:00
|
|
|
|
|
|
|
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 "cmITKWrapTclCommand.h"
|
|
|
|
#include "cmMakeDepend.h"
|
|
|
|
|
|
|
|
cmITKWrapTclCommand::cmITKWrapTclCommand():
|
|
|
|
m_MakeDepend(new cmMakeDepend)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cmITKWrapTclCommand::~cmITKWrapTclCommand()
|
|
|
|
{
|
|
|
|
delete m_MakeDepend;
|
|
|
|
}
|
|
|
|
|
2002-12-10 23:55:43 +03:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
cmITKWrapTclCommand::AddDependencies(cmDependInformation const *info,
|
|
|
|
std::vector<std::string>& depends,
|
|
|
|
std::set<cmDependInformation const*>& visited)
|
|
|
|
{
|
|
|
|
if(!info)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// add info to the visited set
|
|
|
|
visited.insert(info);
|
|
|
|
|
|
|
|
// add this dependency and the recurse
|
|
|
|
// now recurse with info's dependencies
|
|
|
|
for(cmDependInformation::DependencySet::const_iterator d =
|
|
|
|
info->m_DependencySet.begin();
|
|
|
|
d != info->m_DependencySet.end(); ++d)
|
|
|
|
{
|
|
|
|
if (visited.find(*d) == visited.end())
|
|
|
|
{
|
|
|
|
if((*d)->m_FullPath != "")
|
|
|
|
{
|
|
|
|
depends.push_back((*d)->m_FullPath);
|
|
|
|
}
|
|
|
|
this->AddDependencies(*d,depends,visited);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-08 21:11:53 +04:00
|
|
|
// cmITKWrapTclCommand
|
2002-12-12 02:13:33 +03:00
|
|
|
bool cmITKWrapTclCommand::InitialPass(std::vector<std::string> const& args)
|
2002-05-08 21:11:53 +04:00
|
|
|
{
|
2002-12-12 02:13:33 +03:00
|
|
|
if(args.size() < 2 )
|
2002-05-08 21:11:53 +04:00
|
|
|
{
|
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// keep the target name
|
|
|
|
m_TargetName = args[0];
|
2002-07-26 18:15:04 +04:00
|
|
|
m_Target = &m_Makefile->GetTargets()[m_TargetName.c_str()];
|
2002-05-08 21:11:53 +04:00
|
|
|
|
|
|
|
// Prepare the dependency generator.
|
|
|
|
m_MakeDepend->SetMakefile(m_Makefile);
|
|
|
|
|
|
|
|
for(std::vector<std::string>::const_iterator i = (args.begin() + 1);
|
|
|
|
i != args.end(); ++i)
|
|
|
|
{
|
|
|
|
if(!this->CreateCableRule((*i).c_str())) { return false; }
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmITKWrapTclCommand::CreateCableRule(const char* configFile)
|
|
|
|
{
|
|
|
|
std::string tclFile =
|
2002-06-27 23:57:09 +04:00
|
|
|
cmSystemTools::GetFilenameWithoutExtension(configFile);
|
2002-05-08 21:11:53 +04:00
|
|
|
tclFile += "_tcl";
|
|
|
|
|
|
|
|
std::string inFile = m_Makefile->GetCurrentDirectory();
|
|
|
|
inFile += "/";
|
|
|
|
inFile += configFile;
|
|
|
|
|
|
|
|
std::string outDir = m_Makefile->GetCurrentOutputDirectory();
|
|
|
|
|
|
|
|
// Generate the rule to run cable to generate wrappers.
|
|
|
|
std::string command = this->GetCableFromCache();
|
|
|
|
std::vector<std::string> depends;
|
2002-05-09 01:45:31 +04:00
|
|
|
|
|
|
|
// Special case for CMake's wrapping test. Don't add dependency if
|
|
|
|
// it is a dummy executable.
|
|
|
|
if(command != "echo")
|
|
|
|
{
|
|
|
|
depends.push_back(command);
|
|
|
|
}
|
2005-02-22 18:32:44 +03:00
|
|
|
|
|
|
|
cmCustomCommandLine commandLine;
|
|
|
|
commandLine.push_back(command);
|
|
|
|
commandLine.push_back(inFile);
|
|
|
|
commandLine.push_back("-tcl");
|
2002-05-08 21:11:53 +04:00
|
|
|
std::string tmp = tclFile+".cxx";
|
2005-02-22 18:32:44 +03:00
|
|
|
commandLine.push_back(tmp);
|
2002-05-08 21:11:53 +04:00
|
|
|
#if !defined(_WIN32) || defined(__CYGWIN__)
|
2002-05-09 01:37:03 +04:00
|
|
|
tmp = "${CMAKE_CXX_COMPILER}";
|
2002-05-08 21:11:53 +04:00
|
|
|
m_Makefile->ExpandVariablesInString(tmp);
|
2002-05-09 01:37:03 +04:00
|
|
|
if(tmp.length() > 0)
|
|
|
|
{
|
2005-02-22 18:32:44 +03:00
|
|
|
commandLine.push_back("--gccxml-compiler");
|
|
|
|
commandLine.push_back(tmp);
|
2002-10-28 18:29:28 +03:00
|
|
|
tmp = "${CMAKE_CXX_FLAGS}";
|
|
|
|
m_Makefile->ExpandVariablesInString(tmp);
|
2005-02-22 18:32:44 +03:00
|
|
|
commandLine.push_back("--gccxml-cxxflags");
|
|
|
|
commandLine.push_back(tmp);
|
2002-05-09 01:37:03 +04:00
|
|
|
}
|
2002-11-05 03:45:19 +03:00
|
|
|
#else
|
|
|
|
const char* genName = m_Makefile->GetDefinition("CMAKE_GENERATOR");
|
|
|
|
if (genName)
|
|
|
|
{
|
|
|
|
std::string gen = genName;
|
|
|
|
if(gen == "Visual Studio 6")
|
|
|
|
{
|
2005-02-22 18:32:44 +03:00
|
|
|
commandLine.push_back("--gccxml-compiler");
|
|
|
|
commandLine.push_back("msvc6");
|
2002-11-05 03:45:19 +03:00
|
|
|
tmp = "${CMAKE_CXX_FLAGS}";
|
|
|
|
m_Makefile->ExpandVariablesInString(tmp);
|
2005-02-22 18:32:44 +03:00
|
|
|
commandLine.push_back("--gccxml-cxxflags");
|
|
|
|
commandLine.push_back(tmp);
|
2002-11-05 03:45:19 +03:00
|
|
|
}
|
|
|
|
else if(gen == "Visual Studio 7")
|
|
|
|
{
|
2005-02-22 18:32:44 +03:00
|
|
|
commandLine.push_back("--gccxml-compiler");
|
|
|
|
commandLine.push_back("msvc7");
|
2002-11-05 03:45:19 +03:00
|
|
|
tmp = "${CMAKE_CXX_FLAGS}";
|
|
|
|
m_Makefile->ExpandVariablesInString(tmp);
|
2005-02-22 18:32:44 +03:00
|
|
|
commandLine.push_back("--gccxml-cxxflags");
|
|
|
|
commandLine.push_back(tmp);
|
2002-11-05 03:45:19 +03:00
|
|
|
}
|
|
|
|
else if(gen == "NMake Makefiles")
|
|
|
|
{
|
|
|
|
tmp = "${CMAKE_CXX_COMPILER}";
|
|
|
|
m_Makefile->ExpandVariablesInString(tmp);
|
2005-02-22 18:32:44 +03:00
|
|
|
commandLine.push_back("--gccxml-compiler");
|
|
|
|
commandLine.push_back(tmp);
|
2002-11-05 03:45:19 +03:00
|
|
|
tmp = "${CMAKE_CXX_FLAGS}";
|
|
|
|
m_Makefile->ExpandVariablesInString(tmp);
|
2005-02-22 18:32:44 +03:00
|
|
|
commandLine.push_back("--gccxml-cxxflags");
|
|
|
|
commandLine.push_back(tmp);
|
2002-11-05 03:45:19 +03:00
|
|
|
}
|
|
|
|
}
|
2002-05-08 21:11:53 +04:00
|
|
|
#endif
|
2002-10-02 02:37:08 +04:00
|
|
|
const char* gccxml = m_Makefile->GetDefinition("ITK_GCCXML_EXECUTABLE");
|
|
|
|
if(gccxml)
|
|
|
|
{
|
2005-02-22 18:32:44 +03:00
|
|
|
commandLine.push_back("--gccxml");
|
|
|
|
commandLine.push_back(gccxml);
|
2002-10-02 02:37:08 +04:00
|
|
|
}
|
2002-05-08 21:11:53 +04:00
|
|
|
tmp = "-I";
|
|
|
|
tmp += m_Makefile->GetStartDirectory();
|
2005-02-22 18:32:44 +03:00
|
|
|
commandLine.push_back(tmp);
|
2002-05-08 21:11:53 +04:00
|
|
|
const std::vector<std::string>& includes =
|
|
|
|
m_Makefile->GetIncludeDirectories();
|
|
|
|
for(std::vector<std::string>::const_iterator i = includes.begin();
|
|
|
|
i != includes.end(); ++i)
|
|
|
|
{
|
|
|
|
tmp = "-I";
|
|
|
|
tmp += i->c_str();
|
|
|
|
m_Makefile->ExpandVariablesInString(tmp);
|
2005-02-22 18:32:44 +03:00
|
|
|
commandLine.push_back(tmp);
|
2002-05-08 21:11:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the dependencies.
|
|
|
|
const cmDependInformation* info =
|
|
|
|
m_MakeDepend->FindDependencies(inFile.c_str());
|
|
|
|
if (info)
|
|
|
|
{
|
2002-12-10 23:55:43 +03:00
|
|
|
std::set<cmDependInformation const*> visited;
|
|
|
|
this->AddDependencies(info, depends, visited);
|
2002-05-08 21:11:53 +04:00
|
|
|
}
|
|
|
|
|
2003-06-05 22:37:35 +04:00
|
|
|
std::string output;
|
|
|
|
output = outDir+"/"+tclFile+".cxx";
|
2002-05-08 21:11:53 +04:00
|
|
|
|
2002-07-26 18:15:04 +04:00
|
|
|
// Add the source to the makefile.
|
2002-05-08 21:11:53 +04:00
|
|
|
cmSourceFile file;
|
|
|
|
file.SetName(tclFile.c_str(), outDir.c_str(), "cxx", false);
|
|
|
|
// Set dependency hints.
|
|
|
|
file.GetDepends().push_back(inFile.c_str());
|
|
|
|
file.GetDepends().push_back("CableTclFacility/ctCalls.h");
|
2002-06-27 23:57:09 +04:00
|
|
|
m_Makefile->AddSource(file);
|
2003-06-05 22:37:35 +04:00
|
|
|
|
2005-02-22 18:32:44 +03:00
|
|
|
const char* no_comment = 0;
|
|
|
|
cmCustomCommandLines commandLines;
|
|
|
|
commandLines.push_back(commandLine);
|
|
|
|
m_Makefile->AddCustomCommandToOutput(output.c_str(), depends,
|
|
|
|
inFile.c_str(), commandLines,
|
|
|
|
no_comment);
|
2002-07-26 18:15:04 +04:00
|
|
|
|
|
|
|
// Add the generated source to the package's source list.
|
2003-06-05 22:37:35 +04:00
|
|
|
m_Target->GetSourceLists().push_back(output);
|
2002-07-26 18:15:04 +04:00
|
|
|
|
2002-05-08 21:11:53 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the "CABLE" cache entry value. If there is no cache entry for CABLE,
|
|
|
|
* one will be created and initialized to NOTFOUND.
|
|
|
|
*/
|
|
|
|
std::string cmITKWrapTclCommand::GetCableFromCache() const
|
|
|
|
{
|
|
|
|
const char* cable =
|
|
|
|
m_Makefile->GetDefinition("CABLE");
|
|
|
|
if(cable)
|
|
|
|
{ return cable; }
|
|
|
|
|
|
|
|
m_Makefile->AddCacheDefinition("CABLE",
|
2003-01-31 21:50:42 +03:00
|
|
|
"CABLE-NOTFOUND",
|
2002-05-08 21:11:53 +04:00
|
|
|
"Path to CABLE executable.",
|
|
|
|
cmCacheManager::FILEPATH);
|
2003-01-31 21:50:42 +03:00
|
|
|
return "CABLE-NOTFOUND";
|
2002-05-08 21:11:53 +04:00
|
|
|
}
|