# Calling CMake from Powershell does not process files correctly

**URL:** https://discourse.cmake.org/t/calling-cmake-from-powershell-does-not-process-files-correctly/4556
**Category:** Usage
**Tags:** os:windows
**Created:** [November 26, 2021, 5:47pm UTC](https://discourse.cmake.org/t/calling-cmake-from-powershell-does-not-process-files-correctly/4556 "2021-11-26T17:47:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Kerstin\_Keller](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kerstin_keller/32/180_2.png) [@Kerstin\_Keller](https://discourse.cmake.org/u/Kerstin_Keller)
#### Post date: [November 26, 2021, 5:47pm UTC](https://discourse.cmake.org/t/calling-cmake-from-powershell-does-not-process-files-correctly/4556/1 "2021-11-26T17:47:11Z")

</div>

When I am invoking CMake from the Powershell, it behaves differently then when calling from cmd.  
Mainly, it doesn’t parse any files specified by `-DCMAKE_TOOLCHAIN_FILE=...`.

When e.g. I run

```auto
cmake .. -DCMAKE_TOOLCHAIN_FILE=..\my_toolchain.cmake

```

from cmd, the toolchain file is read, but when I am running from powershell, the toolchain file is not processed at all.

I am well aware that this might be a powershell thing, how powershell passes arguments and such. But it has already cost me various hours of my life, so my question is: is this a bug, or am I doing things wrong? any other options i pass with `-DSOME_OPTION=ON` are processed just fine from both cmd and powershell.

Any help is highly appreciated!

```auto
# CMakeLists.txt

cmake_minimum_required(VERSION 3.20)

project(toolchain_test)
option(TEST_VAR "my option" OFF)
message(STATUS "Test variable ${TEST_VAR}")

```

and

```auto
#my_toolchain.cmake
set(TEST_VAR ON)

```

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [November 26, 2021, 5:52pm UTC](https://discourse.cmake.org/t/calling-cmake-from-powershell-does-not-process-files-correctly/4556/2 "2021-11-26T17:52:06Z")

</div>

My bet is on the “\” character. It’s nottoriously broken on Windows. I tend to do one of two things:

- use “/” as path separtor always and everywhere
- add type to variables that are supposed to be paths like so `-DCMAKE_TOOLCHAIN_FILE:FILEPATH=..\my_toolchain.cmake`

---

<div class="post-metadata">

### Author: ![Kerstin\_Keller](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kerstin_keller/32/180_2.png) [@Kerstin\_Keller](https://discourse.cmake.org/u/Kerstin_Keller)
#### Post date: [November 26, 2021, 5:58pm UTC](https://discourse.cmake.org/t/calling-cmake-from-powershell-does-not-process-files-correctly/4556/3 "2021-11-26T17:58:30Z")

</div>

Justing using the `../` did not do the trick.  
explicitly specifying it’s a path via `:FILEPATH` did, though. It even doesn’t matter if it’s `\` or `/`.

Thanks for the hint (and the quick reply), I will start using `:FILEPATH` whenever I specify a toolchain file, to avoid the problem altogether.

---

<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 26, 2021, 6:09pm UTC](https://discourse.cmake.org/t/calling-cmake-from-powershell-does-not-process-files-correctly/4556/4 "2021-11-26T18:09:49Z")

</div>

I enclose the options in quotes, even for non-paths, to ensure they’re processed correctly on Windows.

```cmake
cmake "-Dversion=1.2.3"

```

etc

---

<div class="post-metadata">

### Author: ![rbaleksandar](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/13edae/32.png) [@rbaleksandar](https://discourse.cmake.org/u/rbaleksandar)
#### Post date: [August 17, 2024, 3:36am UTC](https://discourse.cmake.org/t/calling-cmake-from-powershell-does-not-process-files-correctly/4556/5 "2024-08-17T03:36:10Z")

</div>

Last time I checked Powershell is slash agnostic. If anything the problem with slashes might come from CMake.
