summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-01-14 12:24:36 (GMT)
committerBrad King <brad.king@kitware.com>2019-01-14 12:24:36 (GMT)
commitc63a19e9201474750fea6adc11d75a9bb5a21e5b (patch)
tree3b8ddaef1b1122dce3fe9028f1140c87df7e12a7 /Source
parentddb5b097cd29e2e7fcddcb79c4e3ae8c64b0a5b3 (diff)
parent27eb7c5bdb5bb8deefe1772675dc4819592bf036 (diff)
downloadCMake-c63a19e9201474750fea6adc11d75a9bb5a21e5b.zip
CMake-c63a19e9201474750fea6adc11d75a9bb5a21e5b.tar.gz
CMake-c63a19e9201474750fea6adc11d75a9bb5a21e5b.tar.bz2
Merge branch 'cmake-option-parsing' into release-3.13
Merge-request: !2799
Diffstat (limited to 'Source')
-rw-r--r--Source/cmake.cxx25
-rw-r--r--Source/cmake.h3
-rw-r--r--Source/cmakemain.cxx10
3 files changed, 22 insertions, 16 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)
diff --git a/Source/cmake.h b/Source/cmake.h
index d3d0e80..5bca306 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -275,8 +275,7 @@ public:
int GetSystemInformation(std::vector<std::string>&);
///! Parse command line arguments
- void SetArgs(const std::vector<std::string>&,
- bool directoriesSetBefore = false);
+ void SetArgs(const std::vector<std::string>& args);
///! Is this cmake running as a result of a TRY_COMPILE command
bool GetIsInTryCompile() const;
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index 75dabde..e52f2b3 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -285,12 +285,12 @@ int do_cmake(int ac, char const* const* av)
} else if (cmHasLiteralPrefix(av[i], "-P")) {
if (i == ac - 1) {
cmSystemTools::Error("No script specified for argument -P");
- } else {
- workingMode = cmake::SCRIPT_MODE;
- args.push_back(av[i]);
- i++;
- args.push_back(av[i]);
+ return 1;
}
+ workingMode = cmake::SCRIPT_MODE;
+ args.push_back(av[i]);
+ i++;
+ args.push_back(av[i]);
} else if (cmHasLiteralPrefix(av[i], "--find-package")) {
workingMode = cmake::FIND_PACKAGE_MODE;
args.push_back(av[i]);