# Limit on add\_custom\_command COMMAND arguments

**URL:** https://discourse.cmake.org/t/limit-on-add-custom-command-command-arguments/6346
**Category:** Usage
**Created:** [August 25, 2022, 6:47pm UTC](https://discourse.cmake.org/t/limit-on-add-custom-command-command-arguments/6346 "2022-08-25T18:47:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tkacvins](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/9f8e36/32.png) [@tkacvins](https://discourse.cmake.org/u/tkacvins)
#### Post date: [August 25, 2022, 6:47pm UTC](https://discourse.cmake.org/t/limit-on-add-custom-command-command-arguments/6346/1 "2022-08-25T18:47:06Z")

</div>

Hi,

Recently I have run into a problem where the data I pass to COMMAND in an add\_custom\_command,  
like this:

```cmake
add_custom_command(
OUTPUT
"${CMAKE_BINARY_DIR}/list.txt"
COMMAND
python3 "${CMAKE_SOURCE_DIR}/make_list.py"
"${CMAKE_BINARY_DIR}/list.txt"
$<TARGET_OBJECTS:foo>
COMMAND_EXPAND_LISTS
DEPENDS
$<TARGET_OBJECTS:foo>
"${CMAKE_SOURCE_DIR}/build/ada_obj_to_ali.py"
VERBATIM
)

```

results in make\_list.py have some corrupted values in argv (the majority  
are correct, though).

This doesn’t happen on Linux, or Windows 10. What we have seen, though,  
is that this code snippet fails on Windows Server 2012 and 2016.

I am in the process of making a reproducer (if I can) so you have something  
to go on for a diagnosis.

So, for now, the question is there a know limit on how many arguments can  
be passed to COMMAND?

Thanks,

Tom

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [August 25, 2022, 11:10pm UTC](https://discourse.cmake.org/t/limit-on-add-custom-command-command-arguments/6346/2 "2022-08-25T23:10:56Z")

</div>

If you have many object files, you may be hitting Windows command line length limits. A more robust arrangement may be to write the file list into a file and read that file from `make_list.py`. It might look something like this (untested, and I leave the modification of `make_list.py` up to you):

```cmake
set(out_file "${CMAKE_BINARY_DIR}/list.txt")
set(objects_file "${CMAKE_CURRENT_BINARY_DIR}/file_list.txt")
file(GENERATE
    OUTPUT "${objects_file}"
    CONTENT "$<JOIN:$<TARGET_OBJECTS:foo>,\n>"
)
add_custom_command(
    OUTPUT "${out_file}"
    COMMAND python3 "${CMAKE_SOURCE_DIR}/make_list.py" "${out_file}" "${objects_file}"
    DEPENDS
        "${objects_file}"
        $<TARGET_OBJECTS:foo>
        "${CMAKE_SOURCE_DIR}/build/ada_obj_to_ali.py"
    VERBATIM
)

```

---

<div class="post-metadata">

### Author: ![tkacvins](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/9f8e36/32.png) [@tkacvins](https://discourse.cmake.org/u/tkacvins)
#### Post date: [August 26, 2022, 10:44am UTC](https://discourse.cmake.org/t/limit-on-add-custom-command-command-arguments/6346/3 "2022-08-26T10:44:12Z")

</div>

Thank you Craig,

We had originally `used file(GENERATE ...)`, but we wanted to have targets and dependencies to trigger the generation of the files only when necessary.

Tom

---

<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: [August 26, 2022, 5:11pm UTC](https://discourse.cmake.org/t/limit-on-add-custom-command-command-arguments/6346/4 "2022-08-26T17:11:34Z")

</div>

> [@tkacvins](#):
>
> we wanted to have targets and dependencies to trigger the generation of the files only when necessary.

`file(GENERATE)` should only replace the file if the contents change.
