ninja command line too long

I am getting a The command line is too long. error when building on Windows using CMake 3.20.0 and Ninja 1.10.2.
I have tried the answer for cmake-command-line-too-long-windows, but it did not work.
The actual command that is failing is the archiver:

cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E rm -f path\to\mylib.a && C:\ti\ccs1010\ccs\tools\compiler\ti-cgt-arm_20.2.1.LTS\bin\armar.exe qr path\to\mylib.a <a-bunch-of-obj-files> && cd ."

I’m wondering if this is a bug (or lacking feature) of CMake where it needs to support using response files for archiving?
Is there a workaround or solution for this?

It looks like you’re might be using a custom toolchain. There are some variables you can use to indicate that your compiler does support them. From a grep:

  • CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG
  • CMAKE_${lang}_USE_RESPONSE_FILE_FOR_LIBRARIES
  • CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS

If you’re not using a custom toolchain, CMake’s TI support might need updated if the compiler/linker does support response files now in different configurations. Please file an issue if that is the case.

Ahh, ok, so this is really an issue with the TI compiler? I did notice that the TI.cmake mentioned # After the --run_linker flag a response file is not possible. I guess I didn’t realize that response files were a compiler-specific feature; I thought it was a Ninja-specific feature.

I guess for the time being, the workaround I’ve found is to just split my target into multiple targets to reduce the command line length.

Ninja has support for making them, but the tool itself needs to provide the core logic for them. Splitting your libraries up can be suitable (though not always possible depending on the API you plan on providing).