Weird behavior of CMAKE_GENERATOR_TOOLSET
As it known, from version 11 2012 Visual Studio have two default toolsets on Windows:
- v###, which is default, supports new features and targets Windows versions above XP;
v###_xp, which is for backward compatibility, lacks new features and targets Windows XP.
where ### is a version of Visual Studio (110 for 11-2012, 120 for 12-2013 and 140 for 14-2015/15-2017)
You can read more about differences here:
CMake was influenced by this functionality by introducing support for toolsets in 2.8.11:
But there's problems with usage of
If I change it not inside
if at all, project generation will fail on any other generator that doesn't support toolsets.
So, I must put it inside something like
if (MSVC). But then there's another problem:
- If I change
project(), it has no effect - project will be generated with v### toolset, not v###_xp.
- If I change
project(), it will take effect, but all variables with compiler info (e.g.
CMAKE_<LANG>_COMPILER_IDetc.) are still undefined here.
There's also a subproblem - it may be necessary to set needed WinXP compatible toolset accordingly to MSVC version, because project can support some of them. And you can't set, for example, v120_xp as one-stop solution - Visual Studio 14 2015 has v140_xp, but has no v120_xp by default.
Currently the only known for me way to resolve this problem is to parse
MATCHES. So it should be?
In the end, I note funny thing that
CMAKE_GENERATOR_TOOLSET, being set after
project(), affects generator if I use cmake-gui and press "Configure" button twice before pressing "Generate".