cmake: Fix --build crash on bad CMAKE_GENERATOR in cache
If we fail to create the generator named by CMAKE_GENERATOR, exit with an error message instead of crashing. While at it, fix the wording of the error message when CMAKE_GENERATOR is not set. Extend the RunCMake.CommandLine test with cases covering the "cmake --build" option when the named directory does not provide a CMakeCache.txt with a valid CMAKE_GENERATOR.
This commit is contained in:
parent
cbc9a9514d
commit
44e2923f33
@ -2664,11 +2664,17 @@ int cmake::Build(const std::string& dir,
|
|||||||
}
|
}
|
||||||
if(!it.Find("CMAKE_GENERATOR"))
|
if(!it.Find("CMAKE_GENERATOR"))
|
||||||
{
|
{
|
||||||
std::cerr << "Error: could find generator in Cache\n";
|
std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
cmsys::auto_ptr<cmGlobalGenerator> gen(
|
cmsys::auto_ptr<cmGlobalGenerator> gen(
|
||||||
this->CreateGlobalGenerator(it.GetValue()));
|
this->CreateGlobalGenerator(it.GetValue()));
|
||||||
|
if(!gen.get())
|
||||||
|
{
|
||||||
|
std::cerr << "Error: could create CMAKE_GENERATOR \""
|
||||||
|
<< it.GetValue() << "\"\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
std::string output;
|
std::string output;
|
||||||
std::string projName;
|
std::string projName;
|
||||||
if(!it.Find("CMAKE_PROJECT_NAME"))
|
if(!it.Find("CMAKE_PROJECT_NAME"))
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
include(RunCMake)
|
include(RunCMake)
|
||||||
|
|
||||||
|
run_cmake_command(build-no-cache
|
||||||
|
${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR})
|
||||||
|
run_cmake_command(build-no-generator
|
||||||
|
${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-no-generator)
|
||||||
|
run_cmake_command(build-bad-generator
|
||||||
|
${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-bad-generator)
|
||||||
|
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
run_cmake_command(E_create_symlink-missing-dir
|
run_cmake_command(E_create_symlink-missing-dir
|
||||||
${CMAKE_COMMAND} -E create_symlink T missing-dir/L
|
${CMAKE_COMMAND} -E create_symlink T missing-dir/L
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
1
|
@ -0,0 +1 @@
|
|||||||
|
^Error: could create CMAKE_GENERATOR "Bad Generator"$
|
1
Tests/RunCMake/CommandLine/build-no-cache-result.txt
Normal file
1
Tests/RunCMake/CommandLine/build-no-cache-result.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
1
|
1
Tests/RunCMake/CommandLine/build-no-cache-stderr.txt
Normal file
1
Tests/RunCMake/CommandLine/build-no-cache-stderr.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
^Error: could not load cache$
|
1
Tests/RunCMake/CommandLine/build-no-generator-result.txt
Normal file
1
Tests/RunCMake/CommandLine/build-no-generator-result.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
1
|
1
Tests/RunCMake/CommandLine/build-no-generator-stderr.txt
Normal file
1
Tests/RunCMake/CommandLine/build-no-generator-stderr.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
^Error: could not find CMAKE_GENERATOR in Cache$
|
@ -0,0 +1 @@
|
|||||||
|
CMAKE_GENERATOR:INTERNAL=Bad Generator
|
Loading…
x
Reference in New Issue
Block a user