# Apply configure options to git checkout when adding external projects

**URL:** https://discourse.cmake.org/t/apply-configure-options-to-git-checkout-when-adding-external-projects/8562
**Category:** Usage
**Tags:** tool:cmake
**Created:** [July 20, 2023, 1:01pm UTC](https://discourse.cmake.org/t/apply-configure-options-to-git-checkout-when-adding-external-projects/8562 "2023-07-20T13:01:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jhlegarreta](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jhlegarreta/32/2910_2.png) [@jhlegarreta](https://discourse.cmake.org/u/jhlegarreta)
#### Post date: [July 20, 2023, 1:01pm UTC](https://discourse.cmake.org/t/apply-configure-options-to-git-checkout-when-adding-external-projects/8562/1 "2023-07-20T13:01:10Z")

</div>

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](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](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](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](https://open.cdash.org/viewBuildError.php?type=1&buildid=8848075)

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](https://discourse.cmake.org/t/completely-hiding-output-from-externalproject-add/3468) 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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 20, 2023, 5:19pm UTC](https://discourse.cmake.org/t/apply-configure-options-to-git-checkout-when-adding-external-projects/8562/2 "2023-07-20T17:19:26Z")

</div>

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](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5389/diffs?commit_id=1cb65e680d11ab705d737ecd96f7ebea853ca668).

---

<div class="post-metadata">

### Author: ![jhlegarreta](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jhlegarreta/32/2910_2.png) [@jhlegarreta](https://discourse.cmake.org/u/jhlegarreta)
#### Post date: [July 21, 2023, 1:04pm UTC](https://discourse.cmake.org/t/apply-configure-options-to-git-checkout-when-adding-external-projects/8562/3 "2023-07-21T13:04:05Z")

</div>

Thanks for the answer @ben.boeckel.

> [@ben.boeckel](#):
>
> 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](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5389/diffs?commit_id=1cb65e680d11ab705d737ecd96f7ebea853ca668).

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.
