From 44e2923f332653f6b1aad610b314a9edbdf6bf24 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 3 Jun 2014 11:36:25 -0400 Subject: [PATCH] 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. --- Source/cmake.cxx | 8 +++++++- Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 7 +++++++ Tests/RunCMake/CommandLine/build-bad-generator-result.txt | 1 + Tests/RunCMake/CommandLine/build-bad-generator-stderr.txt | 1 + Tests/RunCMake/CommandLine/build-no-cache-result.txt | 1 + Tests/RunCMake/CommandLine/build-no-cache-stderr.txt | 1 + Tests/RunCMake/CommandLine/build-no-generator-result.txt | 1 + Tests/RunCMake/CommandLine/build-no-generator-stderr.txt | 1 + .../CommandLine/cache-bad-generator/CMakeCache.txt | 1 + .../CommandLine/cache-no-generator/CMakeCache.txt | 0 10 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/CommandLine/build-bad-generator-result.txt create mode 100644 Tests/RunCMake/CommandLine/build-bad-generator-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/build-no-cache-result.txt create mode 100644 Tests/RunCMake/CommandLine/build-no-cache-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/build-no-generator-result.txt create mode 100644 Tests/RunCMake/CommandLine/build-no-generator-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/cache-bad-generator/CMakeCache.txt create mode 100644 Tests/RunCMake/CommandLine/cache-no-generator/CMakeCache.txt diff --git a/Source/cmake.cxx b/Source/cmake.cxx index abbabe762..729717304 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2664,11 +2664,17 @@ int cmake::Build(const std::string& dir, } 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; } cmsys::auto_ptr gen( this->CreateGlobalGenerator(it.GetValue())); + if(!gen.get()) + { + std::cerr << "Error: could create CMAKE_GENERATOR \"" + << it.GetValue() << "\"\n"; + return 1; + } std::string output; std::string projName; if(!it.Find("CMAKE_PROJECT_NAME")) diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index ada4cab63..3aaeac047 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -1,5 +1,12 @@ 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) run_cmake_command(E_create_symlink-missing-dir ${CMAKE_COMMAND} -E create_symlink T missing-dir/L diff --git a/Tests/RunCMake/CommandLine/build-bad-generator-result.txt b/Tests/RunCMake/CommandLine/build-bad-generator-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-bad-generator-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/build-bad-generator-stderr.txt b/Tests/RunCMake/CommandLine/build-bad-generator-stderr.txt new file mode 100644 index 000000000..110340749 --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-bad-generator-stderr.txt @@ -0,0 +1 @@ +^Error: could create CMAKE_GENERATOR "Bad Generator"$ diff --git a/Tests/RunCMake/CommandLine/build-no-cache-result.txt b/Tests/RunCMake/CommandLine/build-no-cache-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-no-cache-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/build-no-cache-stderr.txt b/Tests/RunCMake/CommandLine/build-no-cache-stderr.txt new file mode 100644 index 000000000..40dd3c097 --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-no-cache-stderr.txt @@ -0,0 +1 @@ +^Error: could not load cache$ diff --git a/Tests/RunCMake/CommandLine/build-no-generator-result.txt b/Tests/RunCMake/CommandLine/build-no-generator-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-no-generator-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/build-no-generator-stderr.txt b/Tests/RunCMake/CommandLine/build-no-generator-stderr.txt new file mode 100644 index 000000000..40ad030be --- /dev/null +++ b/Tests/RunCMake/CommandLine/build-no-generator-stderr.txt @@ -0,0 +1 @@ +^Error: could not find CMAKE_GENERATOR in Cache$ diff --git a/Tests/RunCMake/CommandLine/cache-bad-generator/CMakeCache.txt b/Tests/RunCMake/CommandLine/cache-bad-generator/CMakeCache.txt new file mode 100644 index 000000000..e34af4432 --- /dev/null +++ b/Tests/RunCMake/CommandLine/cache-bad-generator/CMakeCache.txt @@ -0,0 +1 @@ +CMAKE_GENERATOR:INTERNAL=Bad Generator diff --git a/Tests/RunCMake/CommandLine/cache-no-generator/CMakeCache.txt b/Tests/RunCMake/CommandLine/cache-no-generator/CMakeCache.txt new file mode 100644 index 000000000..e69de29bb