2001-01-11 22:55:47 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
=========================================================================*/
|
2000-08-29 23:26:29 +04:00
|
|
|
#include "cmDSWMakefile.h"
|
2001-01-05 19:41:20 +03:00
|
|
|
#include "cmStandardIncludes.h"
|
2000-08-29 23:26:29 +04:00
|
|
|
#include "cmSystemTools.h"
|
2000-09-12 13:30:35 +04:00
|
|
|
#include "cmDSPMakefile.h"
|
2001-01-05 19:41:20 +03:00
|
|
|
#include "cmMSProjectGenerator.h"
|
2000-08-29 23:26:29 +04:00
|
|
|
#include <windows.h>
|
|
|
|
|
2000-09-12 13:30:35 +04:00
|
|
|
// microsoft nonsense
|
|
|
|
#undef GetCurrentDirectory
|
|
|
|
#undef SetCurrentDirectory
|
2000-08-29 23:26:29 +04:00
|
|
|
|
2001-01-05 19:41:20 +03:00
|
|
|
cmDSWMakefile::cmDSWMakefile(cmMakefile* m)
|
|
|
|
{
|
|
|
|
m_Makefile = m;
|
|
|
|
}
|
|
|
|
|
2000-09-21 21:45:08 +04:00
|
|
|
// output the DSW file
|
2000-08-29 23:26:29 +04:00
|
|
|
void cmDSWMakefile::OutputDSWFile()
|
|
|
|
{
|
2001-02-15 21:30:13 +03:00
|
|
|
if(m_Makefile->GetStartOutputDirectory() == "")
|
2000-08-29 23:26:29 +04:00
|
|
|
{
|
|
|
|
// default to build in place
|
2001-02-15 21:30:13 +03:00
|
|
|
m_Makefile->SetStartOutputDirectory(m_Makefile->GetHomeDirectory());
|
2000-08-29 23:26:29 +04:00
|
|
|
}
|
|
|
|
// If the output directory is not the m_cmHomeDirectory
|
|
|
|
// then create it.
|
2001-02-15 21:30:13 +03:00
|
|
|
if(strcmp(m_Makefile->GetStartOutputDirectory(),
|
2001-01-05 19:41:20 +03:00
|
|
|
m_Makefile->GetHomeDirectory()) != 0)
|
2000-08-29 23:26:29 +04:00
|
|
|
{
|
2001-02-15 21:30:13 +03:00
|
|
|
if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
|
2000-08-29 23:26:29 +04:00
|
|
|
{
|
|
|
|
MessageBox(0, "Error creating directory ", 0, MB_OK);
|
2001-02-15 21:30:13 +03:00
|
|
|
MessageBox(0, m_Makefile->GetStartOutputDirectory(), 0, MB_OK);
|
2000-08-29 23:26:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
std::string fname;
|
2001-02-15 21:30:13 +03:00
|
|
|
fname = m_Makefile->GetStartOutputDirectory();
|
2000-08-29 23:26:29 +04:00
|
|
|
fname += "/";
|
2001-01-05 19:41:20 +03:00
|
|
|
fname += m_Makefile->GetProjectName();
|
2000-08-29 23:26:29 +04:00
|
|
|
fname += ".dsw";
|
|
|
|
std::ofstream fout(fname.c_str());
|
|
|
|
if(!fout)
|
|
|
|
{
|
2001-01-05 19:41:20 +03:00
|
|
|
cmSystemTools::Error("Error can not open for write: " , fname.c_str());
|
2000-08-29 23:26:29 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->WriteDSWFile(fout);
|
|
|
|
}
|
|
|
|
|
2000-09-12 13:30:35 +04:00
|
|
|
// ------------------------------------------------
|
|
|
|
// Recursive function to find all the CMakeLists.txt files
|
|
|
|
// in a project. As each file is read in, any directories in
|
|
|
|
// the SUBDIR variable are also passed back to this function.
|
|
|
|
// The result is a vector of cmDSPMakefile objects, one for
|
|
|
|
// each directory with a CMakeLists.txt file
|
|
|
|
//
|
2001-01-05 19:41:20 +03:00
|
|
|
void
|
|
|
|
cmDSWMakefile
|
|
|
|
::FindAllCMakeListsFiles(const char* subdir,
|
|
|
|
std::vector<cmMSProjectGenerator*>& makefiles)
|
2000-09-12 13:30:35 +04:00
|
|
|
{
|
2001-01-05 19:41:20 +03:00
|
|
|
std::string currentDir = m_Makefile->GetCurrentDirectory();
|
2000-09-12 13:30:35 +04:00
|
|
|
currentDir += "/";
|
|
|
|
currentDir += subdir;
|
|
|
|
currentDir += "/";
|
|
|
|
currentDir += "CMakeLists.txt";
|
|
|
|
// CMakeLists.txt exits in the subdirectory
|
|
|
|
// then create a cmDSPMakefile for it
|
|
|
|
if(cmSystemTools::FileExists(currentDir.c_str()))
|
|
|
|
{
|
|
|
|
// Create a new cmDSPMakefile to read the currentDir CMakeLists.txt file
|
2001-01-05 19:41:20 +03:00
|
|
|
cmMSProjectGenerator* pg = new cmMSProjectGenerator;
|
2001-02-12 22:26:25 +03:00
|
|
|
pg->BuildDSWOff();
|
2001-01-05 19:41:20 +03:00
|
|
|
cmMakefile* mf = new cmMakefile;
|
|
|
|
mf->SetMakefileGenerator(pg);
|
2000-09-12 13:30:35 +04:00
|
|
|
// add it to the vector
|
2001-01-05 19:41:20 +03:00
|
|
|
makefiles.push_back(pg);
|
2000-09-12 13:30:35 +04:00
|
|
|
// Set up the file with the current context
|
2001-02-15 21:30:13 +03:00
|
|
|
mf->SetHomeOutputDirectory(m_Makefile->GetStartOutputDirectory());
|
2001-01-05 19:41:20 +03:00
|
|
|
mf->SetHomeDirectory(m_Makefile->GetHomeDirectory());
|
2001-02-15 21:30:13 +03:00
|
|
|
// Set the output directory which may be different than the source
|
|
|
|
std::string outdir = m_Makefile->GetStartOutputDirectory();
|
|
|
|
outdir += "/";
|
|
|
|
outdir += subdir;
|
|
|
|
mf->SetStartOutputDirectory(outdir.c_str());
|
2000-09-12 13:30:35 +04:00
|
|
|
// set the current directory in the Source as a full
|
|
|
|
// path
|
2001-02-15 21:30:13 +03:00
|
|
|
std::string currentDir = m_Makefile->GetStartDirectory();
|
2000-09-12 13:30:35 +04:00
|
|
|
currentDir += "/";
|
|
|
|
currentDir += subdir;
|
2001-02-15 21:30:13 +03:00
|
|
|
mf->SetStartDirectory(currentDir.c_str());
|
2000-09-12 13:30:35 +04:00
|
|
|
// Parse the CMakeLists.txt file
|
|
|
|
currentDir += "/CMakeLists.txt";
|
2001-02-15 21:30:13 +03:00
|
|
|
mf->MakeStartDirectoriesCurrent();
|
|
|
|
mf->ReadListFile(currentDir.c_str());
|
2000-09-12 13:30:35 +04:00
|
|
|
// Create the DSP file
|
2001-01-05 19:41:20 +03:00
|
|
|
mf->GenerateMakefile();
|
2000-09-12 13:30:35 +04:00
|
|
|
// Look at any sub directories parsed (SUBDIRS) and
|
|
|
|
// recurse into them
|
2001-01-05 19:41:20 +03:00
|
|
|
const std::vector<std::string>& subdirs = mf->GetSubDirectories();
|
2000-09-12 13:30:35 +04:00
|
|
|
for(std::vector<std::string>::const_iterator i = subdirs.begin();
|
|
|
|
i != subdirs.end(); ++i)
|
|
|
|
{
|
|
|
|
// append the subdirectory to the current directoy subdir
|
|
|
|
std::string nextDir = subdir;
|
|
|
|
nextDir += "/";
|
|
|
|
nextDir += i->c_str();
|
|
|
|
// recurse into nextDir
|
|
|
|
this->FindAllCMakeListsFiles(nextDir.c_str(),
|
|
|
|
makefiles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-01-05 19:41:20 +03:00
|
|
|
cmSystemTools::Error("Can not find CMakeLists.txt in ",
|
|
|
|
currentDir.c_str());
|
2000-09-12 13:30:35 +04:00
|
|
|
}
|
|
|
|
}
|
2000-08-29 23:26:29 +04:00
|
|
|
|
2000-09-12 13:30:35 +04:00
|
|
|
|
|
|
|
// Write a DSW file to the stream
|
2000-08-29 23:26:29 +04:00
|
|
|
void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
|
|
|
|
{
|
2000-09-12 13:30:35 +04:00
|
|
|
// Write out the header for a DSW file
|
2000-08-29 23:26:29 +04:00
|
|
|
this->WriteDSWHeader(fout);
|
2000-09-12 13:30:35 +04:00
|
|
|
// Create an array of dsp files for the project
|
2001-01-05 19:41:20 +03:00
|
|
|
std::vector<cmMSProjectGenerator*> dspfiles;
|
2000-09-12 13:30:35 +04:00
|
|
|
// loop over all the subdirectories for the DSW file,
|
|
|
|
// and find all sub directory projects
|
2001-01-05 19:41:20 +03:00
|
|
|
const std::vector<std::string>& dirs = m_Makefile->GetSubDirectories();
|
|
|
|
for(std::vector<std::string>::const_iterator j = dirs.begin();
|
|
|
|
j != dirs.end(); ++j)
|
2000-08-29 23:26:29 +04:00
|
|
|
{
|
2000-09-12 13:30:35 +04:00
|
|
|
this->FindAllCMakeListsFiles(j->c_str(), dspfiles);
|
|
|
|
}
|
|
|
|
// For each DSP file created insert them into the DSW file
|
2001-01-05 19:41:20 +03:00
|
|
|
for(std::vector<cmMSProjectGenerator*>::iterator k = dspfiles.begin();
|
2000-09-12 13:30:35 +04:00
|
|
|
k != dspfiles.end(); ++k)
|
|
|
|
{
|
|
|
|
// Get the directory for the dsp file, it comes
|
|
|
|
// from the source, so it has the source path which needs
|
|
|
|
// to be removed as this may be built in a different directory
|
|
|
|
// than the source
|
2001-01-05 19:41:20 +03:00
|
|
|
std::string dir = (*k)->GetDSPMakefile()->
|
|
|
|
GetMakefile()->GetCurrentDirectory();
|
2000-09-12 13:30:35 +04:00
|
|
|
// Get the home directory with the trailing slash
|
2001-01-05 19:41:20 +03:00
|
|
|
std::string homedir = m_Makefile->GetHomeDirectory();
|
2000-09-12 13:30:35 +04:00
|
|
|
homedir += "/";
|
|
|
|
// make the directory relative by removing the home directory part
|
|
|
|
cmSystemTools::ReplaceString(dir, homedir.c_str(), "");
|
|
|
|
// Get the list of create dsp files from the cmDSPMakefile, more
|
|
|
|
// than one dsp could have been created per input CMakeLists.txt file
|
2001-01-05 19:41:20 +03:00
|
|
|
std::vector<std::string> dspnames = (*k)->GetDSPMakefile()->GetCreatedProjectNames();
|
2000-08-29 23:26:29 +04:00
|
|
|
for(std::vector<std::string>::iterator si = dspnames.begin();
|
|
|
|
si != dspnames.end(); ++si)
|
|
|
|
{
|
2000-09-12 13:30:35 +04:00
|
|
|
// Write the project into the DSW file
|
2001-01-05 19:41:20 +03:00
|
|
|
this->WriteProject(fout, si->c_str(), dir.c_str(),
|
|
|
|
(*k)->GetDSPMakefile());
|
2000-08-29 23:26:29 +04:00
|
|
|
}
|
2000-09-12 13:30:35 +04:00
|
|
|
// delete the cmDSPMakefile object once done with it to avoid
|
|
|
|
// leaks
|
2001-01-05 19:41:20 +03:00
|
|
|
delete (*k)->GetDSPMakefile()->GetMakefile();
|
2000-08-29 23:26:29 +04:00
|
|
|
}
|
2000-09-12 13:30:35 +04:00
|
|
|
// Write the footer for the DSW file
|
2000-08-29 23:26:29 +04:00
|
|
|
this->WriteDSWFooter(fout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cmDSWMakefile::WriteProject(std::ostream& fout,
|
2000-09-12 13:30:35 +04:00
|
|
|
const char* dspname,
|
2000-09-27 23:01:19 +04:00
|
|
|
const char* dir,
|
2001-01-05 19:41:20 +03:00
|
|
|
cmDSPMakefile* project)
|
2000-08-29 23:26:29 +04:00
|
|
|
{
|
|
|
|
fout << "###############################################################################\n\n";
|
|
|
|
fout << "Project: \"" << dspname << "\"="
|
|
|
|
<< dir << "\\" << dspname << ".dsp - Package Owner=<4>\n\n";
|
|
|
|
fout << "Package=<5>\n{{{\n}}}\n\n";
|
|
|
|
fout << "Package=<4>\n";
|
|
|
|
fout << "{{{\n";
|
2001-01-05 19:41:20 +03:00
|
|
|
if(project->GetMakefile()->HasExecutables())
|
2000-09-27 23:01:19 +04:00
|
|
|
{
|
|
|
|
// insert Begin Project Dependency Project_Dep_Name project stuff here
|
|
|
|
std::vector<std::string>::iterator i, end;
|
2001-01-05 19:41:20 +03:00
|
|
|
i = project->GetMakefile()->GetLinkLibraries().begin();
|
|
|
|
end = project->GetMakefile()->GetLinkLibraries().end();
|
2000-09-27 23:01:19 +04:00
|
|
|
for(;i!= end; ++i)
|
|
|
|
{
|
|
|
|
fout << "Begin Project Dependency\n";
|
|
|
|
fout << "Project_Dep_Name " << *i << "\n";
|
|
|
|
fout << "End Project Dependency\n";
|
|
|
|
}
|
|
|
|
}
|
2000-08-29 23:26:29 +04:00
|
|
|
fout << "}}}\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmDSWMakefile::WriteDSWFooter(std::ostream& fout)
|
|
|
|
{
|
|
|
|
fout << "###############################################################################\n\n";
|
|
|
|
fout << "Global:\n\n";
|
|
|
|
fout << "Package=<5>\n{{{\n}}}\n\n";
|
|
|
|
fout << "Package=<3>\n{{{\n}}}\n\n";
|
|
|
|
fout << "###############################################################################\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cmDSWMakefile::WriteDSWHeader(std::ostream& fout)
|
|
|
|
{
|
|
|
|
fout << "Microsoft Developer Studio Workspace File, Format Version 6.00\n";
|
|
|
|
fout << "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\n\n";
|
|
|
|
}
|