summaryrefslogtreecommitdiffstats
path: root/Source/cmake.cxx
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2019-01-13 12:44:18 (GMT)
committerCraig Scott <craig.scott@crascit.com>2019-01-13 20:13:28 (GMT)
commit27eb7c5bdb5bb8deefe1772675dc4819592bf036 (patch)
treecb132c54cdfb0201a6d2de1976870eadaca2f750 /Source/cmake.cxx
parenta1adbc724336b0a4185e34b63e18de03a8b119cf (diff)
downloadCMake-27eb7c5bdb5bb8deefe1772675dc4819592bf036.zip
CMake-27eb7c5bdb5bb8deefe1772675dc4819592bf036.tar.gz
CMake-27eb7c5bdb5bb8deefe1772675dc4819592bf036.tar.bz2
cmake: Ensure source and binary dirs are set
If only the source dir is provided, the binary dir is assumed to be the working directory. If only the binary dir is provided and it doesn't yet have a CMakeCache.txt to provide the source dir, then the source dir is assumed to be the working directory. This logic was not previously being handled correctly when -S and/or -B options were involved. Furthermore, when both were missing, no suitable error message was provided and an empty string was used for the build directory. Fixes: #18707
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r--Source/cmake.cxx25
1 files changed, 16 insertions, 9 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 1aff5eb..74542df 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -609,16 +609,13 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
}
// Parse the args
-void cmake::SetArgs(const std::vector<std::string>& args,
- bool directoriesSetBefore)
+void cmake::SetArgs(const std::vector<std::string>& args)
{
- bool directoriesSet = directoriesSetBefore;
bool haveToolset = false;
bool havePlatform = false;
for (unsigned int i = 1; i < args.size(); ++i) {
std::string const& arg = args[i];
if (arg.find("-H", 0) == 0 || arg.find("-S", 0) == 0) {
- directoriesSet = true;
std::string path = arg.substr(2);
if (path.empty()) {
++i;
@@ -639,7 +636,6 @@ void cmake::SetArgs(const std::vector<std::string>& args,
} else if (arg.find("-O", 0) == 0) {
// There is no local generate anymore. Ignore -O option.
} else if (arg.find("-B", 0) == 0) {
- directoriesSet = true;
std::string path = arg.substr(2);
if (path.empty()) {
++i;
@@ -801,16 +797,27 @@ void cmake::SetArgs(const std::vector<std::string>& args,
this->SetGlobalGenerator(gen);
}
}
- // no option assume it is the path to the source
+ // no option assume it is the path to the source or an existing build
else {
- directoriesSet = true;
this->SetDirectoriesFromFile(arg.c_str());
}
}
- if (!directoriesSet) {
- this->SetHomeOutputDirectory(cmSystemTools::GetCurrentWorkingDirectory());
+
+ const bool haveSourceDir = !this->GetHomeDirectory().empty();
+ const bool haveBinaryDir = !this->GetHomeOutputDirectory().empty();
+
+ if (this->CurrentWorkingMode == cmake::NORMAL_MODE && !haveSourceDir &&
+ !haveBinaryDir) {
+ cmSystemTools::Error("No source or binary directory provided");
+ return;
+ }
+
+ if (!haveSourceDir) {
this->SetHomeDirectory(cmSystemTools::GetCurrentWorkingDirectory());
}
+ if (!haveBinaryDir) {
+ this->SetHomeOutputDirectory(cmSystemTools::GetCurrentWorkingDirectory());
+ }
}
void cmake::SetDirectoriesFromFile(const char* arg)