Skip to content

Commit 3170f78

Browse files
committed
cmake: add knob to disable vcpkg
When building on windows users have the option to use vcpkg to provide the dependencies needed to compile. Previously, this was used only when using the Visual Studio generator which was not ideal because: - Not all users who want to use vcpkg use the Visual Studio generators. - Some versions of Visual Studio 2019 moved away from using the VS 2019 by default, making it impossible for Visual Studio to configure the project in the likely event that it couldn't find the dependencies. - Inexperienced users of CMake are very likely to get tripped up by the errors caused by a lack of vcpkg, making the above bullet point both annoying and hard to debug. As such, lets make using vcpkg the default on windows. Users who want to avoid using vcpkg can disable it by passing -DNO_VCPKG=TRUE. Signed-off-by: Matthew Rogers <[email protected]>
1 parent c09b630 commit 3170f78

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

contrib/buildsystems/CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,24 @@ NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studi
4343
to use another tool say `ninja` add this to the command line when configuring.
4444
`-G Ninja`
4545
46+
NOTE: By default CMake will install vcpkg locally to your source tree on configuration,
47+
to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.
48+
4649
]]
4750
cmake_minimum_required(VERSION 3.14)
4851

4952
#set the source directory to root of git
5053
set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
51-
if(WIN32)
54+
55+
if (WIN32 AND NOT NO_VCPKG)
56+
set(USING_VCPKG TRUE)
57+
else()
58+
set(USING_VCPKG FALSE)
59+
endif()
60+
61+
if(USING_VCPKG)
5262
set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg")
53-
if(MSVC AND NOT EXISTS ${VCPKG_DIR})
63+
if(NOT EXISTS ${VCPKG_DIR})
5464
message("Initializing vcpkg and building the Git's dependencies (this will take a while...)")
5565
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg_install.bat)
5666
endif()
@@ -178,7 +188,9 @@ endif()
178188

179189
find_program(MSGFMT_EXE msgfmt)
180190
if(NOT MSGFMT_EXE)
181-
set(MSGFMT_EXE ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg/downloads/tools/msys2/msys64/usr/bin/msgfmt.exe)
191+
if (USING_VCPKG)
192+
set(MSGFMT_EXE ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg/downloads/tools/msys2/msys64/usr/bin/msgfmt.exe)
193+
endif()
182194
if(NOT EXISTS ${MSGFMT_EXE})
183195
message(WARNING "Text Translations won't be built")
184196
unset(MSGFMT_EXE)
@@ -982,7 +994,7 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n"
982994
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n")
983995
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n")
984996
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SUPPORTS_SIMPLE_IPC='${SUPPORTS_SIMPLE_IPC}'\n")
985-
if(WIN32)
997+
if(USING_VCPKG)
986998
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n")
987999
endif()
9881000

0 commit comments

Comments
 (0)