summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2006-03-09 14:30:35 -0500
committerBill Hoffman <bill.hoffman@kitware.com>2006-03-09 14:30:35 -0500
commit4c5ba06fa13a2bc07f7e0a26bf455dc0b09d5e9c (patch)
tree36dd3cbb29d7773e102a0c58dee4ef3a5063c7c9
parentd253baab99663f531d91d406faf6fe2b822f5cb8 (diff)
downloadcmake-4c5ba06fa13a2bc07f7e0a26bf455dc0b09d5e9c.tar.gz
ENH: use a cmake script to do the clean step, this allows for large numbers of files to be removed without making the command line too long
-rw-r--r--Source/cmFileCommand.cxx32
-rw-r--r--Source/cmFileCommand.h3
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx28
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.h3
-rw-r--r--Source/cmMakefileExecutableTargetGenerator.cxx11
-rw-r--r--Source/cmMakefileLibraryTargetGenerator.cxx19
-rw-r--r--Source/cmMakefileTargetGenerator.cxx5
7 files changed, 82 insertions, 19 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 56f93ebd75..6c4ad5c0cb 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -20,6 +20,7 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <cmsys/Directory.hxx>
// cmLibraryCommand
bool cmFileCommand::InitialPass(std::vector<std::string> const& args)
@@ -54,6 +55,14 @@ bool cmFileCommand::InitialPass(std::vector<std::string> const& args)
{
return this->HandleMakeDirectoryCommand(args);
}
+ else if ( subCommand == "REMOVE" )
+ {
+ return this->HandleRemove(args, false);
+ }
+ else if ( subCommand == "REMOVE_RECURSE" )
+ {
+ return this->HandleRemove(args, true);
+ }
else if ( subCommand == "INSTALL" )
{
return this->HandleInstallCommand(args);
@@ -857,3 +866,26 @@ bool cmFileCommand::HandleRelativePathCommand(
}
+//----------------------------------------------------------------------------
+bool cmFileCommand::HandleRemove(std::vector<std::string> const& args,
+ bool recurse)
+{
+
+ std::string message;
+ std::vector<std::string>::const_iterator i = args.begin();
+
+ i++; // Get rid of subcommand
+ for(;i != args.end(); ++i)
+ {
+ if(cmSystemTools::FileIsDirectory(i->c_str()) && recurse)
+ {
+ cmSystemTools::RemoveADirectory(i->c_str());
+ }
+ else
+ {
+ cmSystemTools::RemoveFile(i->c_str());
+ }
+ }
+ return true;
+}
+
diff --git a/Source/cmFileCommand.h b/Source/cmFileCommand.h
index 2dcbe2e2f5..fd61694db4 100644
--- a/Source/cmFileCommand.h
+++ b/Source/cmFileCommand.h
@@ -69,6 +69,8 @@ public:
" FILE(READ filename variable)\n"
" FILE(GLOB variable [globbing expressions]...)\n"
" FILE(GLOB_RECURSE variable [globbing expressions]...)\n"
+ " FILE(REMOVE [directory]...)\n"
+ " FILE(REMOVE_RECURSE [directory]...)\n"
" FILE(MAKE_DIRECTORY [directory]...)\n"
" FILE(RELATIVE_PATH variable directory file)\n"
"WRITE will write a message into a file called 'filename'. It "
@@ -101,6 +103,7 @@ public:
cmTypeMacro(cmFileCommand, cmCommand);
protected:
+ bool HandleRemove(std::vector<std::string> const& args, bool recurse);
bool HandleWriteCommand(std::vector<std::string> const& args, bool append);
bool HandleReadCommand(std::vector<std::string> const& args);
bool HandleGlobCommand(std::vector<std::string> const& args, bool recurse);
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index 5045d520e9..94e14da0ce 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -813,17 +813,37 @@ cmLocalUnixMakefileGenerator3
void
cmLocalUnixMakefileGenerator3
::AppendCleanCommand(std::vector<std::string>& commands,
- const std::vector<std::string>& files)
+ const std::vector<std::string>& files,
+ cmTarget& target, const char* filename)
{
if(!files.empty())
{
- std::string remove = "$(CMAKE_COMMAND) -E remove -f";
+ std::string cleanfile = m_Makefile->GetCurrentOutputDirectory();
+ cleanfile += "/";
+ cleanfile += this->GetTargetDirectory(target);
+ cleanfile += "/cmake_clean";
+ if(filename)
+ {
+ cleanfile += "_";
+ cleanfile += filename;
+ }
+ cleanfile += ".cmake";
+ std::string cleanfilePath = this->Convert(cleanfile.c_str(), FULL);
+ std::ofstream fout(cleanfilePath.c_str());
+ if(!fout)
+ {
+ cmSystemTools::Error("Could not create ", cleanfilePath.c_str());
+ }
+ fout << "FILE(REMOVE\n";
+ std::string remove = "$(CMAKE_COMMAND) -P ";
+ remove += this->Convert(cleanfile.c_str(), START_OUTPUT, SHELL);
for(std::vector<std::string>::const_iterator f = files.begin();
f != files.end(); ++f)
{
- remove += " ";
- remove += this->Convert(f->c_str(),START_OUTPUT,SHELL);
+ fout << "\"" << this->Convert(f->c_str(),START_OUTPUT,UNCHANGED)
+ << "\"\n";
}
+ fout << ")\n";
commands.push_back(remove);
}
}
diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h
index 54d3ddc504..4864ffb6eb 100644
--- a/Source/cmLocalUnixMakefileGenerator3.h
+++ b/Source/cmLocalUnixMakefileGenerator3.h
@@ -272,7 +272,8 @@ protected:
void AppendCustomCommand(std::vector<std::string>& commands,
const cmCustomCommand& cc);
void AppendCleanCommand(std::vector<std::string>& commands,
- const std::vector<std::string>& files);
+ const std::vector<std::string>& files,
+ cmTarget& target, const char* filename =0);
private:
friend class cmMakefileTargetGenerator;
diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx
index 73b1e590cd..1bdf7095db 100644
--- a/Source/cmMakefileExecutableTargetGenerator.cxx
+++ b/Source/cmMakefileExecutableTargetGenerator.cxx
@@ -225,18 +225,19 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
std::string cleanFullRealName = outpath + cleanRealName;
exeCleanFiles.push_back(this->Convert(cleanFullName.c_str(),
cmLocalGenerator::START_OUTPUT,
- cmLocalGenerator::MAKEFILE));
+ cmLocalGenerator::UNCHANGED));
if(cleanRealName != cleanName)
{
exeCleanFiles.push_back(this->Convert(cleanFullRealName.c_str(),
cmLocalGenerator::START_OUTPUT,
- cmLocalGenerator::MAKEFILE));
+ cmLocalGenerator::UNCHANGED));
}
}
// Add a command to remove any existing files for this executable.
std::vector<std::string> commands1;
- this->LocalGenerator->AppendCleanCommand(commands1, exeCleanFiles);
+ this->LocalGenerator->AppendCleanCommand(commands1, exeCleanFiles,
+ *this->Target, "target");
this->LocalGenerator->CreateCDCommand(commands1,
this->Makefile->GetStartOutputDirectory(),
this->Makefile->GetHomeOutputDirectory());
@@ -352,6 +353,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
this->CleanFiles.insert(this->CleanFiles.end(),
exeCleanFiles.begin(),
exeCleanFiles.end());
- this->CleanFiles.push_back(cleanObjs);
+ this->CleanFiles.insert(this->CleanFiles.end(),
+ this->Objects.begin(),
+ this->Objects.end());
}
diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx
index ade1696b39..60303eaef5 100644
--- a/Source/cmMakefileLibraryTargetGenerator.cxx
+++ b/Source/cmMakefileLibraryTargetGenerator.cxx
@@ -283,19 +283,19 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
std::string cleanFullImportName = outpath + cleanImportName;
libCleanFiles.push_back
(this->Convert(cleanFullStaticName.c_str(),cmLocalGenerator::START_OUTPUT,
- cmLocalGenerator::MAKEFILE));
+ cmLocalGenerator::UNCHANGED));
if(cleanSharedRealName != cleanStaticName)
{
libCleanFiles.push_back(this->Convert(cleanFullSharedRealName.c_str(),
cmLocalGenerator::START_OUTPUT,
- cmLocalGenerator::MAKEFILE));
+ cmLocalGenerator::UNCHANGED));
}
if(cleanSharedSOName != cleanStaticName &&
cleanSharedSOName != cleanSharedRealName)
{
libCleanFiles.push_back(this->Convert(cleanFullSharedSOName.c_str(),
cmLocalGenerator::START_OUTPUT,
- cmLocalGenerator::MAKEFILE));
+ cmLocalGenerator::UNCHANGED));
}
if(cleanSharedName != cleanStaticName &&
cleanSharedName != cleanSharedSOName &&
@@ -303,7 +303,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
{
libCleanFiles.push_back(this->Convert(cleanFullSharedName.c_str(),
cmLocalGenerator::START_OUTPUT,
- cmLocalGenerator::MAKEFILE));
+ cmLocalGenerator::UNCHANGED));
}
if(!cleanImportName.empty() &&
cleanImportName != cleanStaticName &&
@@ -313,12 +313,13 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
{
libCleanFiles.push_back(this->Convert(cleanFullImportName.c_str(),
cmLocalGenerator::START_OUTPUT,
- cmLocalGenerator::MAKEFILE));
+ cmLocalGenerator::UNCHANGED));
}
}
// Add a command to remove any existing files for this library.
std::vector<std::string> commands1;
- this->LocalGenerator->AppendCleanCommand(commands1, libCleanFiles);
+ this->LocalGenerator->AppendCleanCommand(commands1, libCleanFiles,
+ *this->Target, "target");
this->LocalGenerator->CreateCDCommand(commands1,
this->Makefile->GetStartOutputDirectory(),
this->Makefile->GetHomeOutputDirectory());
@@ -487,7 +488,9 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
// Clean all the possible library names and symlinks and object files.
this->CleanFiles.insert(this->CleanFiles.end(),
- libCleanFiles.begin(),libCleanFiles.end());
- this->CleanFiles.push_back(cleanObjs);
+ libCleanFiles.begin(),libCleanFiles.end());
+ this->CleanFiles.insert(this->CleanFiles.end(),
+ this->Objects.begin(),
+ this->Objects.end());
}
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index e400163479..3ec828be20 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -485,7 +485,8 @@ void cmMakefileTargetGenerator::WriteTargetCleanRules()
cleanTarget += "/clean";
// Construct the clean command.
- this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles);
+ this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles,
+ *this->Target);
this->LocalGenerator->CreateCDCommand(commands,
this->Makefile->GetStartOutputDirectory(),
this->Makefile->GetHomeOutputDirectory());
@@ -605,7 +606,7 @@ void cmMakefileTargetGenerator::WriteCustomCommands()
this->CleanFiles.push_back
(this->Convert(cc->GetOutput(),
cmLocalGenerator::START_OUTPUT,
- cmLocalGenerator::SHELL));
+ cmLocalGenerator::UNCHANGED));
}
}
}