From 70c50aa23cc993a502cd3c87be8afb79d973b50e Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 26 Mar 2018 07:29:48 -0400 Subject: Revert "Remove CTestTestfile.cmake when BUILD_TESTING is OFF" Revert commit v3.8.0-rc1~305^2 (Remove CTestTestfile.cmake when BUILD_TESTING is OFF, 2016-11-14) again. We reverted it once in commit v3.8.0-rc3~22^2 (Revert "Remove CTestTestfile.cmake when BUILD_TESTING is OFF", 2017-03-06) but it was accidentally restored by commit v3.11.0-rc1~387^2 (server: add "ctestInfo" request to get test info, 2017-10-25), perhaps due to conflict resolution during rebase. We cannot remove `CTestTestfile.cmake` when testing is off because it breaks projects that never enable testing but create their own `CTestTestfile.cmake` manually instead. Revert the change again and add a test case. --- Source/cmLocalGenerator.cxx | 11 ++++------- Tests/RunCMake/CTest/CTestTestfile.cmake.in | 1 + Tests/RunCMake/CTest/NotOn-check.cmake | 8 ++++++++ Tests/RunCMake/CTest/NotOn.cmake | 3 +++ Tests/RunCMake/CTest/RunCMakeTest.cmake | 2 ++ 5 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 Tests/RunCMake/CTest/CTestTestfile.cmake.in create mode 100644 Tests/RunCMake/CTest/NotOn-check.cmake create mode 100644 Tests/RunCMake/CTest/NotOn.cmake diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index cee540b..e942ff4 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -224,14 +224,7 @@ void cmLocalGenerator::TraceDependencies() void cmLocalGenerator::GenerateTestFiles() { - std::string file = this->StateSnapshot.GetDirectory().GetCurrentBinary(); - file += "/"; - file += "CTestTestfile.cmake"; - if (!this->Makefile->IsOn("CMAKE_TESTING_ENABLED")) { - if (cmSystemTools::FileExists(file)) { - cmSystemTools::RemoveFile(file); - } return; } @@ -240,6 +233,10 @@ void cmLocalGenerator::GenerateTestFiles() const std::string& config = this->Makefile->GetConfigurations(configurationTypes, false); + std::string file = this->StateSnapshot.GetDirectory().GetCurrentBinary(); + file += "/"; + file += "CTestTestfile.cmake"; + cmGeneratedFileStream fout(file.c_str()); fout.SetCopyIfDifferent(true); diff --git a/Tests/RunCMake/CTest/CTestTestfile.cmake.in b/Tests/RunCMake/CTest/CTestTestfile.cmake.in new file mode 100644 index 0000000..0763244 --- /dev/null +++ b/Tests/RunCMake/CTest/CTestTestfile.cmake.in @@ -0,0 +1 @@ +# Created manually diff --git a/Tests/RunCMake/CTest/NotOn-check.cmake b/Tests/RunCMake/CTest/NotOn-check.cmake new file mode 100644 index 0000000..b68218a --- /dev/null +++ b/Tests/RunCMake/CTest/NotOn-check.cmake @@ -0,0 +1,8 @@ +set(f "${RunCMake_TEST_BINARY_DIR}/CTestTestfile.cmake") +if(NOT EXISTS "${f}") + set(RunCMake_TEST_FAILED "File does not exist:\n ${f}") +endif() +file(READ ${f} content) +if(NOT "${content}" MATCHES "^# Created manually") + set(RunCMake_TEST_FAILED "File:\n ${f}\nhas unexpected content:\n ${content}") +endif() diff --git a/Tests/RunCMake/CTest/NotOn.cmake b/Tests/RunCMake/CTest/NotOn.cmake new file mode 100644 index 0000000..7fba019 --- /dev/null +++ b/Tests/RunCMake/CTest/NotOn.cmake @@ -0,0 +1,3 @@ +set(BUILD_TESTING OFF CACHE BOOL "Build the testing tree.") +include(CTest) +configure_file(CTestTestfile.cmake.in CTestTestfile.cmake) diff --git a/Tests/RunCMake/CTest/RunCMakeTest.cmake b/Tests/RunCMake/CTest/RunCMakeTest.cmake index a6f6842..1392240 100644 --- a/Tests/RunCMake/CTest/RunCMakeTest.cmake +++ b/Tests/RunCMake/CTest/RunCMakeTest.cmake @@ -3,3 +3,5 @@ include(RunCMake) set(RunCMake_TEST_OPTIONS -DNoProject=1) run_cmake(BeforeProject) unset(RunCMake_TEST_OPTIONS) + +run_cmake(NotOn) -- cgit v0.12