From 2e99949ccb216c59ff1932bc3773654e9ae54419 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 10 Jul 2012 10:55:02 -0400 Subject: [PATCH] include: Ignore empty string as file name (#13388) Previously CMake silently accepted the empty string and added a bogus dependency on the current directory. Instead warn about the empty file name and ignore it. We cannot make this an error because there may be existing projects that accidentally depend on the old behavior. Add a RunCMake.include test to cover this case. --- Source/cmIncludeCommand.cxx | 7 +++++++ Tests/RunCMake/CMakeLists.txt | 1 + Tests/RunCMake/include/CMakeLists.txt | 3 +++ Tests/RunCMake/include/EmptyString-stderr.txt | 5 +++++ Tests/RunCMake/include/EmptyString.cmake | 1 + Tests/RunCMake/include/EmptyStringOptional-stderr.txt | 5 +++++ Tests/RunCMake/include/EmptyStringOptional.cmake | 1 + Tests/RunCMake/include/RunCMakeTest.cmake | 4 ++++ 8 files changed, 27 insertions(+) create mode 100644 Tests/RunCMake/include/CMakeLists.txt create mode 100644 Tests/RunCMake/include/EmptyString-stderr.txt create mode 100644 Tests/RunCMake/include/EmptyString.cmake create mode 100644 Tests/RunCMake/include/EmptyStringOptional-stderr.txt create mode 100644 Tests/RunCMake/include/EmptyStringOptional.cmake create mode 100644 Tests/RunCMake/include/RunCMakeTest.cmake diff --git a/Source/cmIncludeCommand.cxx b/Source/cmIncludeCommand.cxx index 0ac6df46a..0d5f67b78 100644 --- a/Source/cmIncludeCommand.cxx +++ b/Source/cmIncludeCommand.cxx @@ -70,6 +70,13 @@ bool cmIncludeCommand } } + if(fname.empty()) + { + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, + "include() given empty file name (ignored)."); + return true; + } + if(!cmSystemTools::FileIsFullPath(fname.c_str())) { // Not a path. Maybe module. diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 23fc086d8..eca96f907 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -50,6 +50,7 @@ add_RunCMake_test(ObjectLibrary) add_RunCMake_test(build_command) add_RunCMake_test(find_package) +add_RunCMake_test(include) add_RunCMake_test(list) if("${CMAKE_TEST_GENERATOR}" MATCHES "Visual Studio [^6]") diff --git a/Tests/RunCMake/include/CMakeLists.txt b/Tests/RunCMake/include/CMakeLists.txt new file mode 100644 index 000000000..e8db6b05b --- /dev/null +++ b/Tests/RunCMake/include/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/include/EmptyString-stderr.txt b/Tests/RunCMake/include/EmptyString-stderr.txt new file mode 100644 index 000000000..006c647c6 --- /dev/null +++ b/Tests/RunCMake/include/EmptyString-stderr.txt @@ -0,0 +1,5 @@ +CMake Warning \(dev\) at EmptyString.cmake:1 \(include\): + include\(\) given empty file name \(ignored\). +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/include/EmptyString.cmake b/Tests/RunCMake/include/EmptyString.cmake new file mode 100644 index 000000000..4285cb3d5 --- /dev/null +++ b/Tests/RunCMake/include/EmptyString.cmake @@ -0,0 +1 @@ +include("") diff --git a/Tests/RunCMake/include/EmptyStringOptional-stderr.txt b/Tests/RunCMake/include/EmptyStringOptional-stderr.txt new file mode 100644 index 000000000..b61c67912 --- /dev/null +++ b/Tests/RunCMake/include/EmptyStringOptional-stderr.txt @@ -0,0 +1,5 @@ +CMake Warning \(dev\) at EmptyStringOptional.cmake:1 \(include\): + include\(\) given empty file name \(ignored\). +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/include/EmptyStringOptional.cmake b/Tests/RunCMake/include/EmptyStringOptional.cmake new file mode 100644 index 000000000..549d46b3d --- /dev/null +++ b/Tests/RunCMake/include/EmptyStringOptional.cmake @@ -0,0 +1 @@ +include("" OPTIONAL) diff --git a/Tests/RunCMake/include/RunCMakeTest.cmake b/Tests/RunCMake/include/RunCMakeTest.cmake new file mode 100644 index 000000000..59b87ca75 --- /dev/null +++ b/Tests/RunCMake/include/RunCMakeTest.cmake @@ -0,0 +1,4 @@ +include(RunCMake) + +run_cmake(EmptyString) +run_cmake(EmptyStringOptional)