# Pass optional arguments to \`ExternalProject\_Add\` using a variable

**URL:** <https://discourse.cmake.org/t/pass-optional-arguments-to-externalproject-add-using-a-variable/6910>\
**Category:** Code\
**Created:** [November 19, 2022, 9:34pm UTC](https://discourse.cmake.org/t/pass-optional-arguments-to-externalproject-add-using-a-variable/6910 "2022-11-19T21:34:45Z")\
**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:** [November 19, 2022, 9:34pm UTC](https://discourse.cmake.org/t/pass-optional-arguments-to-externalproject-add-using-a-variable/6910/1 "2022-11-19T21:34:45Z")

</div>

Hi CMake folks,  
we have a case in ITK where we would like to pass some additional arguments to the `ExternalProject_Add` command depending on the CMake version:

> <https://github.com/InsightSoftwareConsortium/ITK/pull/3709/files#diff-257f8c554e48118b1a537183ee05207cc10b1d5deb6902cc66814d00e533a983R156>
>
> Set \`DOWNLOAD\_EXTRACT\_TIMESTAMP\` to \`FALSE\`: the timestamps of the
> extracted fi…les will reflect the time at which the extraction was
> performed.
> 
> Configure/autoconf based projects like SWIG and PCRE depend on the
> timestamps of the extracted files, and the external projects require
> setting \`DOWNLOAD\_EXTRACT\_TIMESTAMP\` to \`FALSE\` to build robustly.
> 
> Suppresses CMake warnings in wrapping modules.
> 
> Fixes:
> \`\`\`
> CMake Warning (dev) at /usr/local/share/cmake-3.24/Modules/ExternalProject.cmake:3074 (message):
> The DOWNLOAD\_EXTRACT\_TIMESTAMP option was not given and policy CMP0135 is
> not set. The policy's OLD behavior will be used. When using a URL
> download, the timestamps of extracted files should preferably be that of
> the time of extraction, otherwise code that depends on the extracted
> contents might not be rebuilt if the URL changes. The OLD behavior
> preserves the timestamps from the archive instead, but this is usually not
> what you want. Update your project to the NEW behavior or specify the
> DOWNLOAD\_EXTRACT\_TIMESTAMP option with a value of true to avoid this
> robustness issue.
> Call Stack (most recent call first):
> /usr/local/share/cmake-3.24/Modules/ExternalProject.cmake:4170 (\_ep\_add\_download\_command)
> Wrapping/Generators/SwigInterface/CMakeLists.txt:142 (ExternalProject\_Add)
> This warning is for project developers. Use -Wno-dev to suppress it.
> 
> \-- Found BISON: /usr/bin/bison (found version "3.5.1")
> CMake Warning (dev) at /usr/local/share/cmake-3.24/Modules/ExternalProject.cmake:3074 (message):
> The DOWNLOAD\_EXTRACT\_TIMESTAMP option was not given and policy CMP0135 is
> not set. The policy's OLD behavior will be used. When using a URL
> download, the timestamps of extracted files should preferably be that of
> the time of extraction, otherwise code that depends on the extracted
> contents might not be rebuilt if the URL changes. The OLD behavior
> preserves the timestamps from the archive instead, but this is usually not
> what you want. Update your project to the NEW behavior or specify the
> DOWNLOAD\_EXTRACT\_TIMESTAMP option with a value of true to avoid this
> robustness issue.
> Call Stack (most recent call first):
> /usr/local/share/cmake-3.24/Modules/ExternalProject.cmake:4170 (\_ep\_add\_download\_command)
> Wrapping/Generators/SwigInterface/CMakeLists.txt:243 (ExternalProject\_Add)
> This warning is for project developers. Use -Wno-dev to suppress it.
> 
> CMake Warning (dev) at /usr/local/share/cmake-3.24/Modules/ExternalProject.cmake:3074 (message):
> The DOWNLOAD\_EXTRACT\_TIMESTAMP option was not given and policy CMP0135 is
> not set. The policy's OLD behavior will be used. When using a URL
> download, the timestamps of extracted files should preferably be that of
> the time of extraction, otherwise code that depends on the extracted
> contents might not be rebuilt if the URL changes. The OLD behavior
> preserves the timestamps from the archive instead, but this is usually not
> what you want. Update your project to the NEW behavior or specify the
> DOWNLOAD\_EXTRACT\_TIMESTAMP option with a value of true to avoid this
> robustness issue.
> Call Stack (most recent call first):
> /usr/local/share/cmake-3.24/Modules/ExternalProject.cmake:4170 (\_ep\_add\_download\_command)
> Wrapping/Generators/CastXML/CMakeLists.txt:63 (ExternalProject\_Add)
> This warning is for project developers. Use -Wno-dev to suppress it.
> \`\`\`
> 
> raised for example in:
> https://open.cdash.org/build/8245525/configure
> 
> Related documentation:
> https://cmake.org/cmake/help/latest/module/ExternalProject.html?highlight=download\_extract\_timestamp
> https://cmake.org/cmake/help/latest/policy/CMP0135.html
> 
> \## PR Checklist
> \- \[x\] No \[API changes\](https://github.com/InsightSoftwareConsortium/ITK/blob/master/CONTRIBUTING.md#breaking-changes) were made (or the changes have been approved)
> \- \[x\] No \[major design changes\](https://github.com/InsightSoftwareConsortium/ITK/blob/master/CONTRIBUTING.md#design-changes) were made (or the changes have been approved)

The approach does not seem to work: CMake does not understand as we had expected the passed extra arguments:

> <https://github.com/InsightSoftwareConsortium/ITK/pull/3709#issuecomment-1297826313>
>
> \> Shouldn't that already have preserved the old behavior, even when using CMake …3.24?
> 
> @N-Dekker According to
> https://github.com/InsightSoftwareConsortium/ITK/blob/49150c8a701f629a122646f708a802f961d1ace7/CMakeLists.txt#L10
> 
> \`\`\`
> \# CMake versions greater than the ITK\_NEWEST\_VALIDATED\_POLICIES\_VERSION policies will
> \# continue to generate policy warnings "CMake Warning (dev)...Policy CMP0XXX is not set:"
> \`\`\`
> 
> So I guess they will appear for 3.24.
> 
> \> Yes, for this project likely either behavior of the timestamp should be OK. However, I thought there was motivation to use the NEW CMP135 behavior where it could be used, like the castXML project. To do that the CMP135 could be set to new, and this line removed, or the value could be set to TRUE.
> 
> \> The minimum require version certainly should not be updated to 3.24. ExternalProject\_Add appears to ignore unknown names arguments, however I am not sure this is behavior that should be relied upon?
> \> The alternate would be conditionally assign DOWNLOAD\_EXTRACT\_TIMESTAMP FALSE to a variable and use that.
> 
> @blowekamp Thanks for the suggestions and directions forward. Tried to do them in 6e20e06.
> \- The warning in the \`CastXML\` has been silenced.
> \- They are back for \`SWIG\` though, and the variable contents are not properly parsed by \`ExternalProject\_Add\`:
> https://open.cdash.org/build/8248990/configure
> 
> \`\`\`
> CMake Error at /usr/local/share/cmake-3.24/Modules/ExternalProject.cmake:3479 (get\_property):
> get\_property could not find TARGET DOWNLOAD\_EXTRACT\_TIMESTAMP FALSE.
> Perhaps it has not yet been created.
> Call Stack (most recent call first):
> /usr/local/share/cmake-3.24/Modules/ExternalProject.cmake:3661 (\_ep\_get\_file\_deps)
> /usr/local/share/cmake-3.24/Modules/ExternalProject.cmake:4173 (\_ep\_add\_configure\_command)
> Wrapping/Generators/SwigInterface/CMakeLists.txt:254 (ExternalProject\_Add)
> \`\`\` 
> 
> The variable value seems to be OK, though. Not sure what's going on here; I run out of ideas.

Any guess/suggestion of what I may be missing?

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:** [November 19, 2022, 11:09pm UTC](https://discourse.cmake.org/t/pass-optional-arguments-to-externalproject-add-using-a-variable/6910/2 "2022-11-19T23:09:31Z")

</div>

Use `set(download_extract_timestamp_flag DOWNLOAD_EXTRACT_TIMESTAMP FALSE)`. The quoting here causes EP to see a single `DOWNLOAD_EXTRACT_TIMESTAMP FALSE` argument which has no meaning to it.

---

<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:** [November 20, 2022, 2:13pm UTC](https://discourse.cmake.org/t/pass-optional-arguments-to-externalproject-add-using-a-variable/6910/3 "2022-11-20T14:13:11Z")

</div>

Worked like a charm. Thanks Ben !
