23

There is a VS2015 project which is generated by CMake and I want to change its "Platform Toolset".

"Platform Toolset" Location

I have tried these solutions but it doesn't work:

  1. set (CMAKE_VS_PLATFORM_TOOLSET "v120")

  2. cmake -T "v120"

Can anyone help? Thanks.

Kevin
  • 16,549
  • 8
  • 60
  • 74
P.X
  • 551
  • 1
  • 3
  • 14

4 Answers4

36

First of all: remove the CMakeCache.txt if you have already generated your project. Next run cmake:

cmake -G "Visual Studio 14" -T v120

Whenever you need to change your generator(and the toolset is a part of it) you should remove the CMakeCache.txt file.

ixSci
  • 13,100
  • 5
  • 45
  • 79
  • 1
    @P.X, if it helped you, please, accept the answer by hitting a tick sign near the answer – ixSci Mar 02 '16 at 07:50
6

Using CMAKE_GENERATOR_TOOLSET is better than using the -T option.

It's not required to remove the CMakeCache.txt file when re-generating CMake.

e.g.

cmake -G "Visual Studio 16" -A Win32 -DCMAKE_GENERATOR_TOOLSET=v140
Kevin
  • 16,549
  • 8
  • 60
  • 74
FrankPIE
  • 61
  • 1
  • 1
  • 2
    Why is `CMAKE_GENERATOR_TOOLSET` better than `-T`? Do they do different things, or do you mean it is easier to read/maintain build scripts when you use the full name? – Stéphane Nov 03 '20 at 22:06
2

you can also assign platform toolset per-project using example below:

set_target_properties( MyProjectName 
          PROPERTIES
               VS_PLATFORM_TOOLSET ClangCL )
-1

For anyone finding this, the solution is to use CMAKE_SYSTEM_VERSION.

eg.

cmake -DCMAKE_SYSTEM_VERSION=8.1 .
evilrix
  • 152
  • 1
  • 3
  • I don't think this is correct. `CMAKE_SYSTEM_VERSION` is used to set the CMake *host system version* (i.e. the OS version), **not** the *target platform toolset* version. – Kevin Nov 27 '19 at 19:59
  • You appear to be confusing CMAKE_SYSTEM_VERSION with CMAKE_HOST_SYSTEM_VERSION. https://cmake.org/cmake/help/v3.18/variable/CMAKE_SYSTEM_VERSION.html "The version of the operating system for which CMake is to build" https://cmake.org/cmake/help/v3.18/variable/CMAKE_HOST_SYSTEM_VERSION.html#variable:CMAKE_HOST_SYSTEM_VERSION "The OS version CMake is running on." – evilrix Jul 28 '20 at 12:45