ExternalProject: PATCH_COMMAND runs on every build
I tried two cmake versions: 3.14.7 and 3.18.1.
I created a simple cmake file where I include a git repository and patch it:
cmake_minimum_required(VERSION 3.5)
project(tinyxml2)
include(ExternalProject)
set(tinyxml2_prefix ${CMAKE_CURRENT_BINARY_DIR}/tinyxml2)
set(tinyxml2_INSTALL_DIR ${tinyxml2_prefix}/install)
set(patch_command ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/patches/tinyxml2.cpp.patch <SOURCE_DIR> && git checkout <SOURCE_DIR>/tinyxml2.cpp && git apply <SOURCE_DIR>/tinyxml2.cpp.patch)
ExternalProject_Add(tinyxml2
PREFIX ${tinyxml2_PREFIX}
GIT_REPOSITORY https://github.com/leethomason/tinyxml2
GIT_TAG tags/7.1.0
UPDATE_DISCONNECTED 1
PATCH_COMMAND ${patch_command}
CMAKE_ARGS
-DBUILD_SHARED_LIBS=OFF
-DBUILD_TESTS=OFF
-DHTTP_ONLY=ON
-DCMAKE_INSTALL_PREFIX=${tinyxml2_INSTALL_DIR}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET}
)
set(tinyxml2_INSTALL_DIR ${tinyxml2_INSTALL_DIR} PARENT_SCOPE)
and a patch file patches/tinyxml2.cpp.patch:
diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index 6b79917..6b91686 100755
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -2501,6 +2501,7 @@ XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) :
_restrictedEntityFlag[static_cast<unsigned char>('&')] = true;
_restrictedEntityFlag[static_cast<unsigned char>('<')] = true;
_restrictedEntityFlag[static_cast<unsigned char>('>')] = true; // not required, but consistency is nice
+ _restrictedEntityFlag[static_cast<unsigned char>('"')] = true;
_buffer.Push( 0 );
}
What I do: I configure build with cmake . -Bbuild
and build it with cmake --build build
. I then run build one more time.
For the old version 3.14.7: configuring and building work fine. The second build command does nothing.
For the latest version 3.18.1: configuring and building also work fine and identically to the old version. However, the second build command applies patch again and causes building external project again. And so the third run and fourth and so on.
I thought that when GIT_TAG is present and when nothing is changed in external project parameters, patch command should not be executed again. What's changed in the cmake logic? I could not find it in the man pages.
It's on Windows 10 x64. Generator is Visual Studio 15 2017.