Apply configure options to git checkout when adding external projects

Hi,
in ITK we have some third-party modules that we checkout using CMake’s ExternalProject_Add() function’s git capabilities:
https://cmake.org/cmake/help/latest/module/ExternalProject.html

Specifically, we donwload DCMTK:
https://github.com/InsightSoftwareConsortium/ITK/blob/9baa34b6998cfb4034d64f0c4f37072e05db356e/Modules/ThirdParty/DCMTK/CMakeLists.txt#L304

using a given git commit hash:
https://github.com/InsightSoftwareConsortium/ITK/blob/9baa34b6998cfb4034d64f0c4f37072e05db356e/Modules/ThirdParty/DCMTK/DCMTKGitTag.cmake

which results in git telling us that we are in detached HEAD status:
CDash

In order to silence the warning, we would pass the -c advice.detachedHead=false flag to the git checkout command.

However, it is not evident to me how CMake allows us to do so: I found this post where a GIT_CONFIG field is specified with the exact flag that we would require. However, I’m wondering whether this effectively applies to the git checkout step.

Thanks

That seems to apply to the git clone only according to the docs. However, I see that if you’re using Git >= 1.7.7, ExternalProject should apply this config automatically as of CMake 3.20. See this MR.

Thanks for the answer @ben.boeckel.

What that MR brings seems like what we’re looking for. We should update our minimum required version in ITK to benefit from it (we’re now requiring 3.16.3). Thanks Again Ben.