summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/CTest/cmCTestTestHandler.cxx2
-rw-r--r--Source/cmIncludeCommand.cxx21
-rw-r--r--Source/cmProjectCommand.cxx13
-rw-r--r--Tests/RunCMake/include/ExportExportInclude-stderr.txt2
-rw-r--r--Tests/RunCMake/include/IncludeIsDirectory-result.txt1
-rw-r--r--Tests/RunCMake/include/IncludeIsDirectory-stderr.txt6
-rw-r--r--Tests/RunCMake/include/IncludeIsDirectory.cmake1
-rw-r--r--Tests/RunCMake/include/IncludeMalformed-result.txt1
-rw-r--r--Tests/RunCMake/include/IncludeMalformed-stderr.txt13
-rw-r--r--Tests/RunCMake/include/IncludeMalformed.cmake1
-rw-r--r--Tests/RunCMake/include/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/include/malformedInclude.cmake1
12 files changed, 56 insertions, 8 deletions
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index 4d1a589..84bb791 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -122,7 +122,7 @@ bool cmCTestSubdirCommand(std::vector<std::string> const& args,
readit = status.GetMakefile().ReadDependentFile(fname);
}
if (!readit) {
- status.SetError(cmStrCat("Could not find include file: ", fname));
+ status.SetError(cmStrCat("Could not load include file: ", fname));
return false;
}
}
diff --git a/Source/cmIncludeCommand.cxx b/Source/cmIncludeCommand.cxx
index ae801bb..5e3aec5 100644
--- a/Source/cmIncludeCommand.cxx
+++ b/Source/cmIncludeCommand.cxx
@@ -146,11 +146,24 @@ bool cmIncludeCommand(std::vector<std::string> const& args,
std::string listFile = cmSystemTools::CollapseFullPath(
fname, status.GetMakefile().GetCurrentSourceDirectory());
- if (optional && !cmSystemTools::FileExists(listFile)) {
+
+ const bool fileDoesnotExist = !cmSystemTools::FileExists(listFile);
+ const bool fileIsDirectory = cmSystemTools::FileIsDirectory(listFile);
+ if (fileDoesnotExist || fileIsDirectory) {
if (!resultVarName.empty()) {
status.GetMakefile().AddDefinition(resultVarName, "NOTFOUND");
}
- return true;
+ if (optional) {
+ return true;
+ }
+ if (fileDoesnotExist) {
+ status.SetError(cmStrCat("could not find requested file:\n ", fname));
+ return false;
+ }
+ if (fileIsDirectory) {
+ status.SetError(cmStrCat("requested file is a directory:\n ", fname));
+ return false;
+ }
}
bool readit =
@@ -163,9 +176,7 @@ bool cmIncludeCommand(std::vector<std::string> const& args,
}
if (!optional && !readit && !cmSystemTools::GetFatalErrorOccured()) {
- std::string m = cmStrCat("could not find load file:\n"
- " ",
- fname);
+ std::string m = cmStrCat("could not load requested file:\n ", fname);
status.SetError(m);
return false;
}
diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx
index 0cfba63..ed32de9 100644
--- a/Source/cmProjectCommand.cxx
+++ b/Source/cmProjectCommand.cxx
@@ -358,6 +358,17 @@ static bool IncludeByVariable(cmExecutionStatus& status,
return true;
}
+ std::string includeFile =
+ cmSystemTools::CollapseFullPath(*include, mf.GetCurrentSourceDirectory());
+ if (!cmSystemTools::FileExists(includeFile)) {
+ status.SetError(cmStrCat("could not find requested file:\n ", *include));
+ return false;
+ }
+ if (cmSystemTools::FileIsDirectory(includeFile)) {
+ status.SetError(cmStrCat("requested file is a directory:\n ", *include));
+ return false;
+ }
+
const bool readit = mf.ReadDependentFile(*include);
if (readit) {
return true;
@@ -367,7 +378,7 @@ static bool IncludeByVariable(cmExecutionStatus& status,
return true;
}
- status.SetError(cmStrCat("could not find file:\n ", *include));
+ status.SetError(cmStrCat("could not load requested file:\n ", *include));
return false;
}
diff --git a/Tests/RunCMake/include/ExportExportInclude-stderr.txt b/Tests/RunCMake/include/ExportExportInclude-stderr.txt
index 70d013c..6d5c02f 100644
--- a/Tests/RunCMake/include/ExportExportInclude-stderr.txt
+++ b/Tests/RunCMake/include/ExportExportInclude-stderr.txt
@@ -1,5 +1,5 @@
CMake Error at ExportExportInclude.cmake:6 \(include\):
- include could not find load file:
+ include could not find requested file:
.*/Tests/RunCMake/include/ExportExportInclude-build/theTargets.cmake
Call Stack \(most recent call first\):
diff --git a/Tests/RunCMake/include/IncludeIsDirectory-result.txt b/Tests/RunCMake/include/IncludeIsDirectory-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/include/IncludeIsDirectory-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include/IncludeIsDirectory-stderr.txt b/Tests/RunCMake/include/IncludeIsDirectory-stderr.txt
new file mode 100644
index 0000000..5735c29
--- /dev/null
+++ b/Tests/RunCMake/include/IncludeIsDirectory-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at IncludeIsDirectory.cmake:1 \(include\):
+ include requested file is a directory:
+
+ .*/Tests/RunCMake/include/IncludeIsDirectory-build
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/include/IncludeIsDirectory.cmake b/Tests/RunCMake/include/IncludeIsDirectory.cmake
new file mode 100644
index 0000000..74189e3
--- /dev/null
+++ b/Tests/RunCMake/include/IncludeIsDirectory.cmake
@@ -0,0 +1 @@
+include("${CMAKE_CURRENT_BINARY_DIR}")
diff --git a/Tests/RunCMake/include/IncludeMalformed-result.txt b/Tests/RunCMake/include/IncludeMalformed-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/include/IncludeMalformed-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/include/IncludeMalformed-stderr.txt b/Tests/RunCMake/include/IncludeMalformed-stderr.txt
new file mode 100644
index 0000000..fc75549
--- /dev/null
+++ b/Tests/RunCMake/include/IncludeMalformed-stderr.txt
@@ -0,0 +1,13 @@
+CMake Error at malformedInclude.cmake:1:
+ Parse error. Function missing ending "\)". End of file reached.
+Call Stack \(most recent call first\):
+ IncludeMalformed.cmake:1 \(include\)
+ CMakeLists.txt:3 \(include\)
+
+
+CMake Error at IncludeMalformed.cmake:1 \(include\):
+ include could not load requested file:
+
+ malformedInclude.cmake
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/include/IncludeMalformed.cmake b/Tests/RunCMake/include/IncludeMalformed.cmake
new file mode 100644
index 0000000..9560142
--- /dev/null
+++ b/Tests/RunCMake/include/IncludeMalformed.cmake
@@ -0,0 +1 @@
+include("malformedInclude.cmake")
diff --git a/Tests/RunCMake/include/RunCMakeTest.cmake b/Tests/RunCMake/include/RunCMakeTest.cmake
index bea7d5c..8fb7201 100644
--- a/Tests/RunCMake/include/RunCMakeTest.cmake
+++ b/Tests/RunCMake/include/RunCMakeTest.cmake
@@ -5,3 +5,5 @@ run_cmake(EmptyStringOptional)
run_cmake(CMP0024-WARN)
run_cmake(CMP0024-NEW)
run_cmake(ExportExportInclude)
+run_cmake(IncludeIsDirectory)
+run_cmake(IncludeMalformed)
diff --git a/Tests/RunCMake/include/malformedInclude.cmake b/Tests/RunCMake/include/malformedInclude.cmake
new file mode 100644
index 0000000..3cec3ad
--- /dev/null
+++ b/Tests/RunCMake/include/malformedInclude.cmake
@@ -0,0 +1 @@
+if(