| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- /*=========================================================================
- Program: Insight Segmentation & Registration Toolkit
- Module: $RCSfile$
- Language: C++
- Date: $Date$
- Version: $Revision$
- Copyright (c) 2000 National Library of Medicine
- All rights reserved.
- See COPYRIGHT.txt for copyright details.
- =========================================================================*/
- #include "cmAddCustomCommandCommand.h"
- // cmAddCustomCommandCommand
- bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args)
- {
- /* Let's complain at the end of this function about the lack of a particular
- arg. For the moment, let's say that SOURCE, COMMAND, TARGET are always
- required.
- */
- if (args.size() < 6)
- {
- this->SetError("called with wrong number of arguments.");
- return false;
- }
- std::string source, command, target;
- std::vector<std::string> command_args, depends, outputs;
- std::string outDir = m_Makefile->GetCurrentOutputDirectory();
- enum tdoing {
- doing_source,
- doing_command,
- doing_target,
- doing_args,
- doing_depends,
- doing_outputs,
- doing_nothing
- };
- tdoing doing = doing_nothing;
- for (unsigned int j = 0; j < args.size(); ++j)
- {
- std::string copy = args[j];
- m_Makefile->ExpandVariablesInString(copy);
- if(copy == "SOURCE")
- {
- doing = doing_source;
- }
- else if(copy == "COMMAND")
- {
- doing = doing_command;
- }
- else if(copy == "TARGET")
- {
- doing = doing_target;
- }
- else if(copy == "ARGS")
- {
- doing = doing_args;
- }
- else if (copy == "DEPENDS")
- {
- doing = doing_depends;
- }
- else if (copy == "OUTPUTS")
- {
- doing = doing_outputs;
- }
- else
- {
- switch (doing)
- {
- case doing_source:
- source = copy;
- break;
- case doing_command:
- command = copy;
- break;
- case doing_target:
- target = copy;
- break;
- case doing_args:
- command_args.push_back(copy);
- break;
- case doing_depends:
- depends.push_back(copy);
- break;
- case doing_outputs:
- outputs.push_back(copy);
- break;
- default:
- this->SetError("Wrong syntax. Unknow type of argument.");
- return false;
- }
- }
- }
- /* At this point we could complain about the lack of arguments.
- For the moment, let's say that SOURCE, COMMAND, TARGET are always
- required.
- */
-
- if(source.empty())
- {
- this->SetError("Wrong syntax. Empty SOURCE.");
- return false;
- }
- if(command.empty())
- {
- this->SetError("Wrong syntax. Empty COMMAND.");
- return false;
- }
- if(target.empty())
- {
- this->SetError("Wrong syntax. Empty TARGET.");
- return false;
- }
- m_Makefile->AddCustomCommand(source.c_str(),
- command.c_str(),
- command_args,
- depends,
- outputs,
- target.c_str());
- // All this is a hack for now
- int cc = outputs.size()-1;
- while( cc >= 0 )
- {
- std::string fileName = outputs[cc];
- std::string directory = cmSystemTools::GetFilenamePath(fileName);
- if ( directory == std::string() )
- {
- directory = outDir;
- }
- fileName = cmSystemTools::GetFilenameName(fileName);
- std::string::size_type pos = fileName.rfind(".");
- fileName = fileName.substr(0, pos);
- // Add the generated source to the package target's source list.
- cmSourceFile file;
- file.SetName(fileName.c_str(), directory.c_str(), "c", false);
- m_Makefile->AddSource(file, target.c_str());
- cc--;
- }
- if ( outputs.size() > 0 )
- {
- std::cout << "Target: " << target << std::endl;
- m_Makefile->GetTargets()[target.c_str()].GetSourceLists().push_back(target);
- }
-
- return true;
- }
|