How do I find vcpkg’s installed copy of CMake, independent of CMake version?

  batch-file, c++, cmake, vcpkg

I am building a CMake/C++ cross-platform project on Windows, in conjunction with vcpkg as the package manager, and Visual Studio 2019 as the compiler. I got the project to build; now I just want to make my build process reproducible, by me and others.

I am using a vcpkg.json manifest file to specify the project’s dependencies. I have a file called bootstrap.bat that does the following:

set VCKPG_PARENT_DIR=C:Projects
set CMAKE_VERSION="3.20.2"

mkdir /p "%VCKPG_PARENT_DIR%"
pushd "%VCKPG_PARENT_DIR%"
git clone https://github.com/Microsoft/vcpkg.git
.vcpkgbootstrap-vcpkg.bat -disableMetrics
set PATH=%PATH%;%VCKPG_PARENT_DIR%vcpkgdownloadstoolscmake-%CMAKE_VERSION%-windowscmake-%CMAKE_VERSION%-windows-i386bin
set VCPKG_DEFAULT_TRIPLET=x64-windows
set PYTHONHOME=%VCKPG_PARENT_DIR%vcpkgpackagespython3_x64-windowstoolspython3
popd

On the line where I set the PATH, is there a better way to specify CMake’s directory location? Like one that would use a vcpkg built-in environment variable or something? I’d rather not hard-code the CMake version if I can help it. I’ve searched for answers to this question, but haven’t come up with anything so far.

I am not willing to assume that the user already has either CMake or vcpkg installed, just Visual Studio and git.

For the sake of completeness, here is the companion batch file, build.bat:

cmake -B build -S .engine -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%scriptsbuildsystemsvcpkg.cmake -DCMAKE_BUILD_TYPE=Release -DUSE_PYTHON_3=ON
cmake --build .build --config Release
mkdir bin
xcopy .buildRelease*.* .bin
xcopy .buildobjconvRelease*.* .bin
xcopy .buildsetupRelease*.* .bin

Any help would be appreciated.

Source: Windows Questions C++

LEAVE A COMMENT