Skip to content

Commit

Permalink
build: alias VCPKG_TARGET_TRIPLET to VCPKG_ARCH
Browse files Browse the repository at this point in the history
Include the build_option() function introduced in b0d325d4bd (Add
build_option() to cmake/Utilities.cmake., 2022-02-10).

Initialize VCPKG_ARCH with an alias to VCPKG_TARGET_TRIPLET with
build_option().

Add a note about this to the cmake doc.

Signed-off-by: Rafael Kitover <[email protected]>
  • Loading branch information
rkitover committed Mar 17, 2022
1 parent 5bdfc4d commit 51b3673
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions contrib/buildsystems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Open git.sln on Windows and build Git.
NOTE: By default CMake will install vcpkg locally to your source tree on configuration,
to avoid this, add `-DUSE_VCPKG=FALSE` to the command line when configuring.
To set the vcpkg arch (target triplet) pass `VCPKG_ARCH` or
`VCPKG_TARGET_TRIPLET` e.g.: `-DVCPKG_ARCH=x64-windows`.
The Visual Studio default generator changed in v16.6 from its Visual Studio
implemenation to `Ninja` This required changes to many CMake scripts.
Expand All @@ -56,6 +59,10 @@ cmake_minimum_required(VERSION 3.14)
#set the source directory to root of git
set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

include(Utilities)

option(USE_VCPKG "Whether or not to use vcpkg for obtaining dependencies. Only applicable to Windows platforms" ON)
if(NOT WIN32)
set(USE_VCPKG OFF CACHE BOOL FORCE)
Expand All @@ -67,18 +74,21 @@ if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS)
endif()

if(USE_VCPKG)
build_option(
VCPKG_ARCH
STRING "vcpkg arch/triplet, e.g. x64-windows."
x64-windows
ALIASES VCPKG_TARGET_TRIPLET
)

set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg")
set(ENV{VCPKG_ROOT} "${VCPKG_DIR}")
message(STATUS "WIN32: ${WIN32}") # show its underlying text values
message(STATUS "VCPKG_DIR: ${VCPKG_DIR}")
message(STATUS "VCPKG_ARCH: ${VCPKG_ARCH}") # maybe unset
message(STATUS "VCPKG_ARCH: ${VCPKG_ARCH}")
message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
message(STATUS "CMAKE_EXPORT_COMPILE_COMMANDS: ${CMAKE_EXPORT_COMPILE_COMMANDS}")
message(STATUS "ENV(CMAKE_EXPORT_COMPILE_COMMANDS): $ENV{CMAKE_EXPORT_COMPILE_COMMANDS}")
if(NOT DEFINED VCPKG_ARCH)
message(STATUS "VCPKG_ARCH: unset, using 'x64-windows'")
set(VCPKG_ARCH "x64-windows") # default from vcpkg_install.bat
endif()
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg_install.bat ${VCPKG_ARCH})
list(APPEND CMAKE_PREFIX_PATH "${VCPKG_DIR}/installed/${VCPKG_ARCH}")

Expand Down

0 comments on commit 51b3673

Please sign in to comment.