summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2006-03-22 19:40:36 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2006-03-22 19:40:36 (GMT)
commitee1975570e60e472e467733a840c30c583fb95cc (patch)
tree1f066070f5314a7f4cc9d1e7977d1b464ad4b999 /Source/cmMakefile.cxx
parent10efe3b079caf5237e01d31b09f7947c77c7458f (diff)
downloadCMake-ee1975570e60e472e467733a840c30c583fb95cc.zip
CMake-ee1975570e60e472e467733a840c30c583fb95cc.tar.gz
CMake-ee1975570e60e472e467733a840c30c583fb95cc.tar.bz2
ENH: Allow blocking of writing into the source tree
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx32
1 files changed, 32 insertions, 0 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 08223cb..cb8c948 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1320,6 +1320,33 @@ bool cmMakefile::IsSet(const char* name) const
return true;
}
+bool cmMakefile::CanIWriteThisFile(const char* fileName)
+{
+ if ( !this->IsOn("CMAKE_DISABLE_SOURCE_CHANGES") )
+ {
+ return 0;
+ }
+ // If we are doing an in-source build, than the test will always fail
+ if ( cmSystemTools::SameFile(this->GetHomeDirectory(), this->GetHomeOutputDirectory()) )
+ {
+ if ( this->IsOn("CMAKE_DISABLE_IN_SOURCE_BUILD") )
+ {
+ return false;
+ }
+ return true;
+ }
+
+ // Check if this is subdirectory of the source tree but not a subdirectory of a build tree
+ if ( cmSystemTools::IsSubDirectory(fileName,
+ this->GetHomeDirectory()) &&
+ !cmSystemTools::IsSubDirectory(fileName,
+ this->GetHomeOutputDirectory()) )
+ {
+ return false;
+ }
+ return true;
+}
+
const char* cmMakefile::GetRequiredDefinition(const char* name) const
{
const char* ret = this->GetDefinition(name);
@@ -2328,6 +2355,11 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
bool copyonly, bool atOnly, bool escapeQuotes)
{
int res = 1;
+ if ( !this->CanIWriteThisFile(outfile) )
+ {
+ cmSystemTools::Error("Attempt to write file: ", outfile, " into a source directory.");
+ return 0;
+ }
if ( !cmSystemTools::FileExists(infile) )
{
cmSystemTools::Error("File ", infile, " does not exist.");