mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-21 14:40:26 -06:00
Merge topic 'cmake-option-parsing'
27eb7c5bdbcmake: Ensure source and binary dirs are seta1adbc7243cmake: Stop processing if -P option lacks file name Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !2799
This commit is contained in:
@@ -610,16 +610,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;
|
||||
@@ -640,7 +637,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;
|
||||
@@ -802,16 +798,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)
|
||||
|
||||
@@ -277,8 +277,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;
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -4,17 +4,17 @@ include(RunCMake)
|
||||
|
||||
run_cmake_command(NoArgs ${CMAKE_COMMAND})
|
||||
run_cmake_command(Wizard ${CMAKE_COMMAND} -i)
|
||||
run_cmake_command(C-no-arg ${CMAKE_COMMAND} -C)
|
||||
run_cmake_command(C-no-file ${CMAKE_COMMAND} -C nosuchcachefile.txt)
|
||||
run_cmake_command(Cno-file ${CMAKE_COMMAND} -Cnosuchcachefile.txt)
|
||||
run_cmake_command(C-no-arg ${CMAKE_COMMAND} -B DummyBuildDir -C)
|
||||
run_cmake_command(C-no-file ${CMAKE_COMMAND} -B DummyBuildDir -C nosuchcachefile.txt)
|
||||
run_cmake_command(Cno-file ${CMAKE_COMMAND} -B DummyBuildDir -Cnosuchcachefile.txt)
|
||||
run_cmake_command(cache-no-file ${CMAKE_COMMAND} nosuchsubdir/CMakeCache.txt)
|
||||
run_cmake_command(lists-no-file ${CMAKE_COMMAND} nosuchsubdir/CMakeLists.txt)
|
||||
run_cmake_command(D-no-arg ${CMAKE_COMMAND} -D)
|
||||
run_cmake_command(D-no-src ${CMAKE_COMMAND} -D VAR=VALUE)
|
||||
run_cmake_command(Dno-src ${CMAKE_COMMAND} -DVAR=VALUE)
|
||||
run_cmake_command(U-no-arg ${CMAKE_COMMAND} -U)
|
||||
run_cmake_command(U-no-src ${CMAKE_COMMAND} -U VAR)
|
||||
run_cmake_command(Uno-src ${CMAKE_COMMAND} -UVAR)
|
||||
run_cmake_command(D-no-arg ${CMAKE_COMMAND} -B DummyBuildDir -D)
|
||||
run_cmake_command(D-no-src ${CMAKE_COMMAND} -B DummyBuildDir -D VAR=VALUE)
|
||||
run_cmake_command(Dno-src ${CMAKE_COMMAND} -B DummyBuildDir -DVAR=VALUE)
|
||||
run_cmake_command(U-no-arg ${CMAKE_COMMAND} -B DummyBuildDir -U)
|
||||
run_cmake_command(U-no-src ${CMAKE_COMMAND} -B DummyBuildDir -U VAR)
|
||||
run_cmake_command(Uno-src ${CMAKE_COMMAND} -B DummyBuildDir -UVAR)
|
||||
run_cmake_command(E-no-arg ${CMAKE_COMMAND} -E)
|
||||
run_cmake_command(E_capabilities ${CMAKE_COMMAND} -E capabilities)
|
||||
run_cmake_command(E_capabilities-arg ${CMAKE_COMMAND} -E capabilities --extra-arg)
|
||||
@@ -34,8 +34,8 @@ run_cmake_command(E___run_co_compile-bad-iwyu ${CMAKE_COMMAND} -E __run_co_compi
|
||||
run_cmake_command(E___run_co_compile-no--- ${CMAKE_COMMAND} -E __run_co_compile --iwyu=iwyu-does-not-exist command-does-not-exist)
|
||||
run_cmake_command(E___run_co_compile-no-cc ${CMAKE_COMMAND} -E __run_co_compile --iwyu=iwyu-does-not-exist --)
|
||||
|
||||
run_cmake_command(G_no-arg ${CMAKE_COMMAND} -G)
|
||||
run_cmake_command(G_bad-arg ${CMAKE_COMMAND} -G NoSuchGenerator)
|
||||
run_cmake_command(G_no-arg ${CMAKE_COMMAND} -B DummyBuildDir -G)
|
||||
run_cmake_command(G_bad-arg ${CMAKE_COMMAND} -B DummyBuildDir -G NoSuchGenerator)
|
||||
run_cmake_command(P_no-arg ${CMAKE_COMMAND} -P)
|
||||
run_cmake_command(P_no-file ${CMAKE_COMMAND} -P nosuchscriptfile.cmake)
|
||||
|
||||
@@ -61,6 +61,7 @@ function(run_ExplicitDirs)
|
||||
|
||||
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 )
|
||||
@@ -330,9 +331,9 @@ set(RunCMake_TEST_OPTIONS -Wdev -Wno-dev)
|
||||
run_cmake(Wno-dev)
|
||||
unset(RunCMake_TEST_OPTIONS)
|
||||
|
||||
run_cmake_command(W_bad-arg1 ${CMAKE_COMMAND} -W)
|
||||
run_cmake_command(W_bad-arg2 ${CMAKE_COMMAND} -Wno-)
|
||||
run_cmake_command(W_bad-arg3 ${CMAKE_COMMAND} -Werror=)
|
||||
run_cmake_command(W_bad-arg1 ${CMAKE_COMMAND} -B DummyBuildDir -W)
|
||||
run_cmake_command(W_bad-arg2 ${CMAKE_COMMAND} -B DummyBuildDir -Wno-)
|
||||
run_cmake_command(W_bad-arg3 ${CMAKE_COMMAND} -B DummyBuildDir -Werror=)
|
||||
|
||||
set(RunCMake_TEST_OPTIONS --debug-output)
|
||||
run_cmake(debug-output)
|
||||
|
||||
1
Tests/RunCMake/CommandLine/no-S-B-result.txt
Normal file
1
Tests/RunCMake/CommandLine/no-S-B-result.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
1
Tests/RunCMake/CommandLine/no-S-B-stderr.txt
Normal file
1
Tests/RunCMake/CommandLine/no-S-B-stderr.txt
Normal file
@@ -0,0 +1 @@
|
||||
CMake Error: No source or binary directory provided
|
||||
Reference in New Issue
Block a user