CMAKE uses CMD or Powershell depending on Computer

The Problem:
When executing CMAKE the generated Build-Commands use either the cmd or powershell cli.
This can cause errors with long build command, as cmd has a much smaller character limit.
The shell that will be used seems to differ per PC.

We are using:
cmake version 3.19.6
GNU Make 4.1

What we tried:
When using the CMAKE build task, on some PCs it works and on some it won´t work.
When using a single build command from the compile_commands.json it works on every PC.
When the Build fails it will cite not finding certain includes as the cause for the error,
leading us to believe that certain include-paths will be cut off due to the cmd character limit.

My Questions:
On what does the selection of the shell depend?
Is this problem exclusive to Windows?
Is it possible to force CMAKE to use Powershell?

Does anybody have a hint how this can be resolved?

Could you provide a SSCCE that shows the problem?

Assuming you’re using MSYS2 or MinGW, on the failing computers, does typing this in the binary dir work from powershell?

mingw32-make

I have seen a different issue with generated source /headers getting too long paths that wasn’t shell dependent but did depend on length of source path. Even with powershell.

I was able to find the cause of the problem.

The generated makefiles contain the following command:

# The shell in which to execute make rules.
SHELL = /bin/sh

By executing the make command with debug information I was able to see that on the failing computers make finds the cygwin shell for this path and uses it then. So it is not the cmd shell but the cygwin bash shell, which apparentlys also has a charactler limit.

On the computers where the build works, make can not find a valid path, and therefore executes the compiler calls directly.

Make documentation of the shell:
https://www.gnu.org/software/make/manual/html_node/Choosing-the-Shell.html#Choosing-the-Shell

So for now the issue can be solved by just removing the cygwin shell.

But is there an option in cmake to set the shell for make?

This is defined by the generator. IIRC, MSys Makefiles generator used cmd.exe as shell.

Best is to stop using make (it has a really bad performance on Windows and it’s stability with parallel builds is not better) and use ninja as alternativ.

1 Like