Windows/Powershell: -DCMAKE_TOOLCHAIN_FILE= is ignored when set to a relative path
I am using CMake 3.21.1 on Windows and seems to ignore toolchain specified via -DCMAKE_TOOLCHAIN_FILE
. It works fine with --toolchain=
switch though.
Steps to reproduce:
- create empty dir with a single
CMakeLists.txt
file and this line in it:project(test-toolchain LANGUAGES C)
- grab https://github.com/MarkSchofield/Toolchain and clone into own directory
Toolchain
under parent directory.
Now if we run cmake with --toolchain
it all works:
C:\Users\ivano\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\213.6461.75\bin\cmake\win\bin\cmake.exe -S . -B . -DCMAKE_MAKE_PROGRAM=C:/Users/ivano/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/213.6461.75/bin/ninja/win/ninja.exe -DCMAKE_BUILD_TYPE=Debug -G Ninja --toolchain=../Toolchain/Windows.MSVC.toolchain.cmake
-- The C compiler identification is MSVC 19.30.30706.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/ivano/Documents/repos/test-toolchain
But it ignores toolchain if I set it via -DCMAKE_TOOLCHAIN_FILE
:
C:\Users\ivano\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\213.6461.75\bin\cmake\win\bin\cmake.exe -S . -B . -DCMAKE_MAKE_PROGRAM=C:/Users/ivano/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/213.6461.75/bin/ninja/win/ninja.exe -DCMAKE_BUILD_TYPE=Debug -G Ninja -DCMAKE_TOOLCHAIN_FILE=../Toolchain/Windows.MSVC.toolchain.cmake
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:1 (project):
No CMAKE_C_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "C:/Users/ivano/Documents/repos/test-toolchain/CMakeFiles/CMakeOutput.log".
See also "C:/Users/ivano/Documents/repos/test-toolchain/CMakeFiles/CMakeError.log".