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 generator 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, let's 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 <mattr94@gmail.com> Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matthew Rogers committed Jun 6, 2021 at 12:02 UTC cd0a852981162fb77f9fac68f231e3d41a99c993
1 file changed +15 -4
contrib/buildsystems/CMakeLists.txt
+15 -4
@@ -43,14 +43,23 @@ NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studi
43 to use another tool say `ninja` add this to the command line when configuring.
44 `-G Ninja`
45
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 +
49 ]]
50 cmake_minimum_required(VERSION 3.14)
51
52 #set the source directory to root of git
53 set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
51 -if(WIN32)
54 +
55 +option(USE_VCPKG "Whether or not to use vcpkg for obtaining dependencies. Only applicable to Windows platforms" ON)
56 +if(NOT WIN32)
57 + set(USE_VCPKG OFF CACHE BOOL FORCE)
58 +endif()
59 +
60 +if(USE_VCPKG)
61 set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg")
53 - if(MSVC AND NOT EXISTS ${VCPKG_DIR})
62 + if(NOT EXISTS ${VCPKG_DIR})
63 message("Initializing vcpkg and building the Git's dependencies (this will take a while...)")
64 execute_process(COMMAND ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg_install.bat)
65 endif()
@@ -174,7 +183,9 @@ endif()
183
184 find_program(MSGFMT_EXE msgfmt)
185 if(NOT MSGFMT_EXE)
177 - set(MSGFMT_EXE ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg/downloads/tools/msys2/msys64/usr/bin/msgfmt.exe)
186 + if (USE_VCPKG)
187 + set(MSGFMT_EXE ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg/downloads/tools/msys2/msys64/usr/bin/msgfmt.exe)
188 + endif()
189 if(NOT EXISTS ${MSGFMT_EXE})
190 message(WARNING "Text Translations won't be built")
191 unset(MSGFMT_EXE)
@@ -956,7 +967,7 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X='${EXE_EXTENSION}'\n")
967 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n")
968 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n")
969 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n")
959 -if(WIN32)
970 +if(USE_VCPKG)
971 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n")
972 endif()
973