From 2395b1b244743aaf28426a72f37d1aac96e3db9e Mon Sep 17 00:00:00 2001
From: Craig Scott <craig.scott@crascit.com>
Date: Tue, 22 Jan 2019 21:33:54 +1100
Subject: [PATCH] cmake: Convert no source/build dir error to warning

Temporarily restore previous behavior that allowed specifying
no source or build directory to work, even though it was
neither documented nor supported. This commit is expected
to eventually be reverted to restore the fatal error for such
cases.

Relates: #18817
---
 Source/cmake.cxx                              |  7 +++++--
 Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 12 +++++++++++-
 Tests/RunCMake/CommandLine/no-S-B-result.txt  |  1 -
 Tests/RunCMake/CommandLine/no-S-B-stderr.txt  |  5 ++++-
 4 files changed, 20 insertions(+), 5 deletions(-)
 delete mode 100644 Tests/RunCMake/CommandLine/no-S-B-result.txt

diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 74542df968..d0863b0cd4 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -808,8 +808,11 @@ void cmake::SetArgs(const std::vector<std::string>& args)
 
   if (this->CurrentWorkingMode == cmake::NORMAL_MODE && !haveSourceDir &&
       !haveBinaryDir) {
-    cmSystemTools::Error("No source or binary directory provided");
-    return;
+    this->IssueMessage(
+      cmake::WARNING,
+      "No source or binary directory provided. Both will be assumed to be "
+      "the same as the current working directory, but note that this "
+      "warning will become a fatal error in future CMake releases.");
   }
 
   if (!haveSourceDir) {
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index 32e20aca1a..3e56c25548 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -54,12 +54,22 @@ run_cmake_command(cache-empty-entry
   ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-empty-entry/)
 
 function(run_ExplicitDirs)
+  set(source_dir ${RunCMake_BINARY_DIR}/ExplicitDirsMissing)
+
+  file(REMOVE_RECURSE "${source_dir}")
+  file(MAKE_DIRECTORY "${source_dir}")
+  file(WRITE ${source_dir}/CMakeLists.txt [=[
+cmake_minimum_required(VERSION 3.13)
+project(ExplicitDirsMissing LANGUAGES NONE)
+]=])
+  run_cmake_command(no-S-B ${CMAKE_COMMAND} -E chdir ${source_dir}
+    ${CMAKE_COMMAND} -DFOO=BAR)
+
   set(source_dir ${RunCMake_SOURCE_DIR}/ExplicitDirs)
   set(binary_dir ${RunCMake_BINARY_DIR}/ExplicitDirs-build)
 
   file(REMOVE_RECURSE "${binary_dir}")
   file(MAKE_DIRECTORY "${binary_dir}")
-  run_cmake_command(no-S-B ${CMAKE_COMMAND} -DFOO=BAR)
   run_cmake_command(S-arg ${CMAKE_COMMAND} -S ${source_dir} ${binary_dir})
   run_cmake_command(S-arg-reverse-order ${CMAKE_COMMAND} ${binary_dir} -S${source_dir} )
   run_cmake_command(S-no-arg ${CMAKE_COMMAND} -S )
diff --git a/Tests/RunCMake/CommandLine/no-S-B-result.txt b/Tests/RunCMake/CommandLine/no-S-B-result.txt
deleted file mode 100644
index d00491fd7e..0000000000
--- a/Tests/RunCMake/CommandLine/no-S-B-result.txt
+++ /dev/null
@@ -1 +0,0 @@
-1
diff --git a/Tests/RunCMake/CommandLine/no-S-B-stderr.txt b/Tests/RunCMake/CommandLine/no-S-B-stderr.txt
index 7a943077b5..c166dcf561 100644
--- a/Tests/RunCMake/CommandLine/no-S-B-stderr.txt
+++ b/Tests/RunCMake/CommandLine/no-S-B-stderr.txt
@@ -1 +1,4 @@
-CMake Error: No source or binary directory provided
+CMake Warning:
+  No source or binary directory provided.  Both will be assumed to be the
+  same as the current working directory, but note that this warning will
+  become a fatal error in future CMake releases.
-- 
GitLab