Use installed CMake instead of embedded one in Visual Studio 2017 - cmake

I've a CMake project. It uses the last version of Boost (1.66.0) that are supported in actual installed CMake version (3.11.0 rc2) but not in previous one (3.10.0).
If I build it with CMake from command line, everything is ok, but if I open the folder in Visual Studio 2017, I obtain an error because Visual Studio uses a CMake installation that's not mine, but is the one embededed with its installation: in the output panel the full cmake command path is C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe, that's not the version that I've installed and it is also the previous version (3.10.0) so project it does not compile.
Is there a way to tell to Visual Studio to use my CMake installation instead of its one?

No (with the exception of the trick shown below), you can only use your own CMake version when doing Visual C++ for Linux Development with CMake on a remote machine with a CMakeSettings.json like this:
{
"name": "Linux-Debug",
"generator": "Unix Makefiles",
"remoteMachineName": "${defaultRemoteMachineName}",
"configurationType": "Debug",
"remoteCMakeListsRoot": "/var/tmp/src/${workspaceHash}/${name}",
"cmakeExecutable": "/usr/local/bin/cmake",
"buildRoot": "${env.LOCALAPPDATA}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"remoteBuildRoot": "/var/tmp/build/${workspaceHash}/build/${name}",
"remoteCopySources": true,
"remoteCopySourcesOutputVerbosity": "Normal",
"remoteCopySourcesConcurrentCopies": "10",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "linux-x64" ]
}
But you can give support to a feature request utilizing the cmakeExecutable property more generally:
CMakeSettings.json: cmakeExecutable only working for remote machines
Some Background Information
As with #usr1234567's answer Visual Studio 2017 uses - as of Version 15.6.1 - it's own branch of CMake:
https://github.com/Microsoft/CMake/tree/cmake-daemon
That the version shipped with Visual Studio 2017 is not an official build you can see be calling:
> "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake" --version
cmake version 3.10.18011902-MSVC_2
So I'm not sure if a official CMake release would nicely/fully integrate into Visual Studio 2017. But there is already a request to merge the Microsoft specific changes back to CMake's main branch:
Issue #16998: Visual Studio 2017: merge Microsoft cmake-daemon branch to master
EDIT: Possible Workaround
A short test has shown that I could trick Visual Studio into taking your installed version by doing a simple renaming of Visual Studio's CMake folder and replacing it a symbolic link to your systems installed CMake version (from a cmd prompt with a administrative rights):
> ren "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake" _CMake
...
> mklink /d "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake" "C:\Program Files\CMake"
...
Warning: You have to undo this with before you update Visual Studio 2017. Otherwise the VS2017 udpate process will replace/overwrite your original CMake installation.

You have already learned from other answers that currently, that is using VS2017 15.6.6 and VS2017 15.7.0 Preview 3.0, you can not force Visual Studio to use your preferred installation of CMake.
However, you can approach your actual problem differently and work around it.
It uses the last version of Boost (1.66.0) that are supported in actual
installed CMake version (3.11.0 rc2) but not in previous one (3.10.0).
Simply, download newer version of FindBoost.cmake and install it inside CMAKE_BINARY_DIR, then point your CMakeLists.txt to prefer it:
if (CMAKE_VERSION VERSION_LESS 3.11)
# Latest FindBoost.cmake has likely been updated to detect Boost version not yet released
if (NOT EXISTS "${CMAKE_BINARY_DIR}/cmake/FindBoost.cmake")
message(STATUS "Downloading FindBoost.cmake from https://gitlab.kitware.com/cmake/ release branch")
file(DOWNLOAD
"https://gitlab.kitware.com/cmake/cmake/raw/release/Modules/FindBoost.cmake"
"${CMAKE_BINARY_DIR}/cmake/FindBoost.cmake")
endif()
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_BINARY_DIR}/cmake)
endif()
I've used this approach for quite a while now for Boost.GIL, https://github.com/boostorg/gil

in Visual Studio 2022, setting the cmakeExecutable option in CMakeSettings.json will make VS use your preferred cmake. (https://stackoverflow.com/a/58774277/16550663)
You can also hide the your machine-specific path using environment variable. (https://stackoverflow.com/a/72612017/16550663)

For Visual Studio 2015 it was not supported to use an external CMake.
Source: Marians answer to Dmitry's question / comment.
The wording in a recent blog post (January 2018)
In our effort to make sure you have access to the latest features of CMake, we have upgraded the version of CMake that ships with Visual Studio from 3.9 to 3.10.
doesn't indicate this has not changed.
Update: There as a recent preview from Visual Studio including CMake 3.11.

Related

How to target Windows XP with MSVC2017 and CMake?

I wanted to accomplish what other 2 threads are doing, but with latest MSVC to support targetting Windows XP and CMake support.
I keep following the advice given in How can I generate a Visual Studio 2012 project targeting Windows XP with CMake? and How does CMake specify "Platform Toolset" for a Visual Studio 2015 project? but CMake keeps telling me that it configured the source code for Windows 10.foo.bar SDK version which is not going to work. I tried hamfisting v141_xp into the project as CMAKE_GENERATOR_TOOLSET and -T parameter for cmake but it all ultimately fails. How can I accomplish this? And if possible, where can I specify this in CMakeSettings.json?
Bonus points for amd64 support, since the target system I want to make binaries for is Windows XP x64.
For what it's worth, I have tried to open a .sln file and I confirm that v141_xp is available as a platform toolset.
I figured it out on my own. From x64 tools console:
Prepare .sln files
cmake path/to/CMakeLists.txt -G "Visual Studio 15 2017 Win64" -A x64 -T v141_xp
Build from .sln:
msbuild path/to/.sln /p:XPDeprecationWarning=false /p:Platform=x64

Where is cmake located when downloaded from visual studio 2022

Where is cmake located when downloading it from visual studio 2022 as I wanted to add it in environmental variables
Launch the Native Tools Command Prompt (accessible via the Start Menu). From here you can run:
> where cmake
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe
to determine the location. I expect that for VS2022 the path will be very similar.
However, the version of CMake distributed with Visual Studio has patches from Microsoft. You should either install upstream CMake for use outside of the Native Tools Command Prompt, or just use the Native Tools Command Prompt.

How perform Visual studio 2019 Ninja builds with custom CMake version?

I'm trying to build a project with Ninja on Visual Studio 2019 from the IDE. I want to use a CMake version different from the one integrated in the VS 2019 distribution. I have set the cmakeExecutable variable in my CMakeSettings.json file to point to my system installation of CMake and the build works fine using the Visual Studio generator. However, if I use Ninja as generator, Visual Studio falls back using the VS-integrated version of CMake. Is there a way to build with Ninja and a custom CMake version from the IDE?

CMake generator for Visual Studio in msys2?

I'm running cmake in msys2, but it doesn't seem to find Visual Studio 2015 (missing generator option). I am launching the msys2 prompt from within Visual Studio Developer Command Prompt, so I have cl.exe, link.exe etc in the path.
This other question seems to be asking the same thing (however for Cygwin not msys2).
Talked to the msys2 devs on IRC, turns out I needed to install package mingw-w64-x86_64-cmake instead of cmake. Using that fixed the problem.

Getting msbuild.exe without installing Visual Studio

How do you get msbuild.exe without installing those crazy Visual Studio programs?
I need it for an npm install to finish working. I'm on Windows 7 and can't get on older version of Visual Studio 2013 Express online.
The latest (as of Jan 2019) stand-alone MSBuild installers can be found here: https://www.visualstudio.com/downloads/
Scroll down to "Tools for Visual Studio 2019" and choose "Build Tools for Visual Studio 2019" (despite the name, it's for users who don't want the full IDE)
See this question for additional information.
It used to be installed with the .NET framework. MsBuild v12.0 (2013) is now bundled as a stand-alone utility and has it's own installer.
http://www.microsoft.com/en-us/download/confirmation.aspx?id=40760
To reference the location of MsBuild.exe from within an MsBuild script, use the default $(MsBuildToolsPath) property.
You can also get the MSBuild executable as a Nuget package https://www.nuget.org/packages/Microsoft.Build.Runtime/.
Download MSBuild with the link from #Nicodemeus answer was OK, yet the installation was broken until I've added these keys into a register:
[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\MSBuild\ToolsVersions\12.0]
"VCTargetsPath11"="$([MSBuild]::ValueOrDefault('$(VCTargetsPath11)','$(MSBuildExtensionsPath32)\\Microsoft.Cpp\\v4.0\\V110\\'))"
"VCTargetsPath"="$([MSBuild]::ValueOrDefault('$(VCTargetsPath)','$(MSBuildExtensionsPath32)\\Microsoft.Cpp\\v4.0\\V110\\'))"