From 6449089436d16406f35f1ee9aef33c07ca89785e Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 25 Aug 2006 16:31:07 -0400 Subject: [PATCH] ENH: Patch from Alex for adding IF(FILE_IS_NEWER). I also added a test. --- Source/cmIfCommand.cxx | 23 ++++++++++++++++++++++- Source/cmIfCommand.h | 4 ++++ Tests/StringFileTest/CMakeLists.txt | 5 +++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index e745735d3..c9a6c08cb 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -226,7 +226,7 @@ bool cmIfCommand::IsTrue(const std::vector &args, IncrementArguments(newArgs,argP1,argP2); reducible = 1; } - // does a file exist + // does a directory with this name exist if (*arg == "IS_DIRECTORY" && argP1 != newArgs.end()) { if(cmSystemTools::FileIsDirectory((argP1)->c_str())) @@ -242,6 +242,27 @@ bool cmIfCommand::IsTrue(const std::vector &args, IncrementArguments(newArgs,argP1,argP2); reducible = 1; } + // is file A newer than file B + if (*arg == "FILE_IS_NEWER" && argP1 != newArgs.end() && argP2 != newArgs.end()) + { + int fileIsNewer=0; + bool success=cmSystemTools::FileTimeCompare((argP1)->c_str(), (argP2)->c_str(), + &fileIsNewer); + if(success==false || fileIsNewer==1 || fileIsNewer==0) + { + *arg = "1"; + } + else + { + *arg = "0"; + } + + newArgs.erase(argP2); + newArgs.erase(argP1); + argP1 = arg; + IncrementArguments(newArgs,argP1,argP2); + reducible = 1; + } // does a command exist if (*arg == "COMMAND" && argP1 != newArgs.end()) { diff --git a/Source/cmIfCommand.h b/Source/cmIfCommand.h index e49c21fbc..90cf1a0a1 100644 --- a/Source/cmIfCommand.h +++ b/Source/cmIfCommand.h @@ -128,6 +128,10 @@ public: " IF(EXISTS directory-name)\n" "True if the named file or directory exists. " "Behavior is well-defined only for full paths.\n" + " IF(FILE_IS_NEWER file1 file2)\n" + "True if file1 is newer than file2 or if one of the two files " + "doesn't exist. " + "Behavior is well-defined only for full paths.\n" " IF(IS_DIRECTORY directory-name)\n" "True if the given name is a directory. " "Behavior is well-defined only for full paths.\n" diff --git a/Tests/StringFileTest/CMakeLists.txt b/Tests/StringFileTest/CMakeLists.txt index 044f2716a..c43bd07f6 100644 --- a/Tests/StringFileTest/CMakeLists.txt +++ b/Tests/StringFileTest/CMakeLists.txt @@ -75,6 +75,11 @@ FOREACH(var FILE(APPEND "${file}" "#define ${var} \"${${var}}\"\n") ENDFOREACH(var) +# Verify that the file was created recently. +IF(NOT FILE_IS_NEWER "${file}" "${CMAKE_CURRENT_SOURCE_DIR}/InputFile.h.in") + MESSAGE(FATAL_ERROR "IF(FILE_IS_NEWER) does not seem to work.") +ENDIF(NOT FILE_IS_NEWER "${file}" "${CMAKE_CURRENT_SOURCE_DIR}/InputFile.h.in") + # Test configuration of the string SET(TEST_DEFINED 123) SET(TEST_NOT_DEFINED)