6

I am trying to create a CMakeLists.txt which can generate VS solution for the project and compile it using build tools from a portable Visual Studio kit. Unfortunately, every time I try to run cmake still detects the installed MSVC compiler.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)

project(app C)

add_executable(app main.c)

What I have tried:

  1. Set CC environment variable and set-up the needed variables for portable VS. Also I tried to run vcvarsall.bat from this kit.

Example:

SET CC=path/vs/build/tools/cl.exe
SET CMAKE_LINKER=path/vs/build/tools/link.exe
SET CMAKE_RC_COMPILER=path/vs/build/tools/rc.exe
SET PATH=path/vs/build/tools/;%PATH%
SET INCLUDES=path/vs/build/tools/includes
SET LIBPATH=path/vs/build/tools/libs
...

Then I tried to run:

  • cmake.exe -Bbuild .
  • cmake.exe -Bbuild -G "Visual Studio 16" .

    1. Created a toolchain file (vs.cmake) where I explicitly set CMAKE_C_COMPIER and set-up the include and lib path for the portable VS.
SET(CMAKE_C_COMPILER    "path/vs/build/tools/cl.exe")
SET(CMAKE_LINKER        "path/vs/build/tools/link.exe")
SET(CMAKE_RC_COMPILER   "path/vs/build/tools/rc.exe")
...

Then I tried to run:

  • cmake.exe -Bbuild -DCMAKE_TOOLCHAIN_FILE=vs.cmake .
  • cmake.exe -Bbuild -DCMAKE_TOOLCHAIN_FILE=vs.cmake -G "Visual Studio 16" .

In both cases it failed to set CMAKE_C_COMPILER to the portable VS, still detects installed MSVC compiler. Only the linker and RC compiler path has been changed.

Does anyone know how to solve this? Any help would be greatly appreciated. Thank you!

Maxim
  • 61
  • 4
  • CMake wont recognize portable MS Build tools. recognizes only installed ones: https://gitlab.kitware.com/cmake/cmake/-/issues/21762 – knockshore Oct 27 '22 at 19:14

0 Answers0