mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-04 05:10:10 -05:00
cmake: simplify to a single source of truth of working mode
This commit is contained in:
committed by
Brad King
parent
64b22cd459
commit
314135cdf1
+7
-17
@@ -405,9 +405,6 @@ void cmake::PrintPresetEnvironment()
|
|||||||
// Parse the args
|
// Parse the args
|
||||||
bool cmake::SetCacheArgs(const std::vector<std::string>& args)
|
bool cmake::SetCacheArgs(const std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
auto findPackageMode = false;
|
|
||||||
auto seenScriptOption = false;
|
|
||||||
|
|
||||||
auto DefineLambda = [](std::string const& entry, cmake* state) -> bool {
|
auto DefineLambda = [](std::string const& entry, cmake* state) -> bool {
|
||||||
std::string var;
|
std::string var;
|
||||||
std::string value;
|
std::string value;
|
||||||
@@ -498,10 +495,10 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
|
|||||||
GetProjectCommandsInScriptMode(state->GetState());
|
GetProjectCommandsInScriptMode(state->GetState());
|
||||||
// Documented behavior of CMAKE{,_CURRENT}_{SOURCE,BINARY}_DIR is to be
|
// Documented behavior of CMAKE{,_CURRENT}_{SOURCE,BINARY}_DIR is to be
|
||||||
// set to $PWD for -P mode.
|
// set to $PWD for -P mode.
|
||||||
|
state->SetWorkingMode(SCRIPT_MODE);
|
||||||
state->SetHomeDirectory(cmSystemTools::GetCurrentWorkingDirectory());
|
state->SetHomeDirectory(cmSystemTools::GetCurrentWorkingDirectory());
|
||||||
state->SetHomeOutputDirectory(cmSystemTools::GetCurrentWorkingDirectory());
|
state->SetHomeOutputDirectory(cmSystemTools::GetCurrentWorkingDirectory());
|
||||||
state->ReadListFile(args, path);
|
state->ReadListFile(args, path);
|
||||||
seenScriptOption = true;
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -565,15 +562,12 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
|
|||||||
"No install directory specified for --install-prefix",
|
"No install directory specified for --install-prefix",
|
||||||
CommandArgument::Values::One, PrefixLambda },
|
CommandArgument::Values::One, PrefixLambda },
|
||||||
CommandArgument{ "--find-package", CommandArgument::Values::Zero,
|
CommandArgument{ "--find-package", CommandArgument::Values::Zero,
|
||||||
[&](std::string const&, cmake*) -> bool {
|
IgnoreAndTrueLambda },
|
||||||
findPackageMode = true;
|
|
||||||
return true;
|
|
||||||
} },
|
|
||||||
};
|
};
|
||||||
for (decltype(args.size()) i = 1; i < args.size(); ++i) {
|
for (decltype(args.size()) i = 1; i < args.size(); ++i) {
|
||||||
std::string const& arg = args[i];
|
std::string const& arg = args[i];
|
||||||
|
|
||||||
if (arg == "--" && seenScriptOption) {
|
if (arg == "--" && this->GetWorkingMode() == SCRIPT_MODE) {
|
||||||
// Stop processing CMake args and avoid possible errors
|
// Stop processing CMake args and avoid possible errors
|
||||||
// when arbitrary args are given to CMake script.
|
// when arbitrary args are given to CMake script.
|
||||||
break;
|
break;
|
||||||
@@ -588,7 +582,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (findPackageMode) {
|
if (this->GetWorkingMode() == FIND_PACKAGE_MODE) {
|
||||||
return this->FindPackage(args);
|
return this->FindPackage(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -793,7 +787,6 @@ void cmake::SetArgs(const std::vector<std::string>& args)
|
|||||||
bool haveToolset = false;
|
bool haveToolset = false;
|
||||||
bool havePlatform = false;
|
bool havePlatform = false;
|
||||||
bool haveBArg = false;
|
bool haveBArg = false;
|
||||||
bool scriptMode = false;
|
|
||||||
std::string possibleUnknownArg;
|
std::string possibleUnknownArg;
|
||||||
std::string extraProvidedPath;
|
std::string extraProvidedPath;
|
||||||
#if !defined(CMAKE_BOOTSTRAP)
|
#if !defined(CMAKE_BOOTSTRAP)
|
||||||
@@ -871,10 +864,7 @@ void cmake::SetArgs(const std::vector<std::string>& args)
|
|||||||
CommandArgument{ "-P", "-P must be followed by a file name.",
|
CommandArgument{ "-P", "-P must be followed by a file name.",
|
||||||
CommandArgument::Values::One,
|
CommandArgument::Values::One,
|
||||||
CommandArgument::RequiresSeparator::No,
|
CommandArgument::RequiresSeparator::No,
|
||||||
[&](std::string const&, cmake*) -> bool {
|
IgnoreAndTrueLambda },
|
||||||
scriptMode = true;
|
|
||||||
return true;
|
|
||||||
} },
|
|
||||||
CommandArgument{ "-D", "-D must be followed with VAR=VALUE.",
|
CommandArgument{ "-D", "-D must be followed with VAR=VALUE.",
|
||||||
CommandArgument::Values::One,
|
CommandArgument::Values::One,
|
||||||
CommandArgument::RequiresSeparator::No,
|
CommandArgument::RequiresSeparator::No,
|
||||||
@@ -1198,12 +1188,12 @@ void cmake::SetArgs(const std::vector<std::string>& args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!extraProvidedPath.empty() && !scriptMode) {
|
if (!extraProvidedPath.empty() && this->GetWorkingMode() == NORMAL_MODE) {
|
||||||
this->IssueMessage(MessageType::WARNING,
|
this->IssueMessage(MessageType::WARNING,
|
||||||
cmStrCat("Ignoring extra path from command line:\n \"",
|
cmStrCat("Ignoring extra path from command line:\n \"",
|
||||||
extraProvidedPath, "\""));
|
extraProvidedPath, "\""));
|
||||||
}
|
}
|
||||||
if (!possibleUnknownArg.empty() && !scriptMode) {
|
if (!possibleUnknownArg.empty() && this->GetWorkingMode() != SCRIPT_MODE) {
|
||||||
cmSystemTools::Error(cmStrCat("Unknown argument ", possibleUnknownArg));
|
cmSystemTools::Error(cmStrCat("Unknown argument ", possibleUnknownArg));
|
||||||
cmSystemTools::Error("Run 'cmake --help' for all supported options.");
|
cmSystemTools::Error("Run 'cmake --help' for all supported options.");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user