Apply configure options to git checkout when adding external projects

in ITK we have some third-party modules that we checkout using CMake’s ExternalProject_Add() function’s git capabilities:

Specifically, we donwload DCMTK:

using a given git commit hash:

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

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.


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.