# CMAKE uses CMD or Powershell depending on Computer

**URL:** <https://discourse.cmake.org/t/cmake-uses-cmd-or-powershell-depending-on-computer/4252>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [October 12, 2021, 1:22pm UTC](https://discourse.cmake.org/t/cmake-uses-cmd-or-powershell-depending-on-computer/4252 "2021-10-12T13:22:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![xllNessllx](https://discourse.cmake.org/user_avatar/discourse.cmake.org/xllnessllx/32/1872_2.png) [@xllNessllx](https://discourse.cmake.org/u/xllNessllx)\
**Post date:** [October 12, 2021, 1:22pm UTC](https://discourse.cmake.org/t/cmake-uses-cmd-or-powershell-depending-on-computer/4252/1 "2021-10-12T13:22:48Z")

</div>

**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?

---

<div class="post-metadata">

**Author:** ![OliverBlasius](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/aca169/32.png) [@OliverBlasius](https://discourse.cmake.org/u/OliverBlasius)\
**Post date:** [October 29, 2021, 11:47am UTC](https://discourse.cmake.org/t/cmake-uses-cmd-or-powershell-depending-on-computer/4252/2 "2021-10-29T11:47:18Z")

</div>

Does anybody have a hint how this can be resolved?

---

<div class="post-metadata">

**Author:** ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)\
**Post date:** [October 29, 2021, 4:57pm UTC](https://discourse.cmake.org/t/cmake-uses-cmd-or-powershell-depending-on-computer/4252/3 "2021-10-29T16:57:10Z")

</div>

Could you provide a [SSCCE](http://sscce.org/) that shows the problem?

---

<div class="post-metadata">

**Author:** ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)\
**Post date:** [November 1, 2021, 11:37am UTC](https://discourse.cmake.org/t/cmake-uses-cmd-or-powershell-depending-on-computer/4252/4 "2021-11-01T11:37:11Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![OliverBlasius](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/aca169/32.png) [@OliverBlasius](https://discourse.cmake.org/u/OliverBlasius)\
**Post date:** [November 2, 2021, 7:54am UTC](https://discourse.cmake.org/t/cmake-uses-cmd-or-powershell-depending-on-computer/4252/5 "2021-11-02T07:54:33Z")

</div>

I was able to find the cause of the problem.

The generated makefiles contain the following command:

```auto
# 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](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?

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [November 2, 2021, 6:55pm UTC](https://discourse.cmake.org/t/cmake-uses-cmd-or-powershell-depending-on-computer/4252/6 "2021-11-02T18:55:35Z")

</div>

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.
