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.
This commit is contained in:
Brad King
2018-03-26 07:29:48 -04:00
parent 6b9172d759
commit 70c50aa23c
5 changed files with 18 additions and 7 deletions

View File

@@ -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);

View File

@@ -0,0 +1 @@
# Created manually

View File

@@ -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()

View File

@@ -0,0 +1,3 @@
set(BUILD_TESTING OFF CACHE BOOL "Build the testing tree.")
include(CTest)
configure_file(CTestTestfile.cmake.in CTestTestfile.cmake)

View File

@@ -3,3 +3,5 @@ include(RunCMake)
set(RunCMake_TEST_OPTIONS -DNoProject=1)
run_cmake(BeforeProject)
unset(RunCMake_TEST_OPTIONS)
run_cmake(NotOn)