Skip to content

Commit

Permalink
fix: use full vcpkg history (#397)
Browse files Browse the repository at this point in the history
Signed-off-by: msclock <[email protected]>
  • Loading branch information
msclock authored Nov 30, 2024
1 parent 1c7a570 commit 2fd2672
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 60 deletions.
28 changes: 16 additions & 12 deletions cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ endfunction()
function(_vcpkg_checkout vcpkg_root vcpkg_ref)
message(STATUS "vcpkg checkout to ${vcpkg_ref}")

execute_process(
COMMAND ${GIT_EXECUTABLE} fetch origin ${vcpkg_ref}
WORKING_DIRECTORY ${vcpkg_root}
RESULT_VARIABLE result)

if(NOT result EQUAL "0")
if(EXISTS "${vcpkg_root}/.git/shallow")
message(
FATAL_ERROR "${GIT_EXECUTABLE} fetch ${vcpkg_ref} failed with ${result}")
WARNING
"vcpkg is shallow now and unshallow to retrieve the Git tree object hash for a specific version port......"
)
execute_process(
COMMAND ${GIT_EXECUTABLE} fetch --unshallow
WORKING_DIRECTORY ${vcpkg_root}
RESULT_VARIABLE result)

if(NOT result EQUAL "0")
message(
FATAL_ERROR "${GIT_EXECUTABLE} fetch --unshallow failed with ${result}")
endif()
endif()

execute_process(
Expand All @@ -47,7 +53,7 @@ endfunction()
# clone
function(_vcpkg_clone vcpkg_root vcpkg_repo vcpkg_ref)
execute_process(
COMMAND ${GIT_EXECUTABLE} clone ${vcpkg_repo} ${vcpkg_root} --depth=1
COMMAND ${GIT_EXECUTABLE} clone ${vcpkg_repo} ${vcpkg_root}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE result)

Expand Down Expand Up @@ -123,7 +129,7 @@ function(_vcpkg_upgrade vcpkg_root vcpkg_repo vcpkg_ref)

message(STATUS "Upgrade vcpkg")
message(STATUS "vcpkg current commit: ${current_git_hash}")
message(STATUS "vcpkg release: ${vcpkg_ref}")
message(STATUS "vcpkg target commit: ${vcpkg_ref}")

execute_process(
COMMAND ${GIT_EXECUTABLE} remote set-url origin ${vcpkg_repo}
Expand All @@ -150,9 +156,7 @@ endfunction()

# find root
function(_vcpkg_find_root cache_dir_name out_vcpkg_root)
if(DEFINED ENV{VCPKG_ROOT} AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "")
set(root "$ENV{VCPKG_ROOT}")
elseif("${__vcpkg_bootstrap_host}" STREQUAL "Windows")
if("${__vcpkg_bootstrap_host}" STREQUAL "Windows")
set(root "$ENV{LOCALAPPDATA}/vcpkg/projects/${cache_dir_name}/cache")
else()
set(root "$ENV{HOME}/.cache/vcpkg/projects/${cache_dir_name}")
Expand Down
18 changes: 18 additions & 0 deletions cmake/vcpkg/bootstrap/vcpkg_configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,26 @@ function(_vcpkg_export_mode)
message(STATUS "Disable manifest mode for using vcpkg exported artifacts")
endfunction()

macro(detect_vcpkg)
# Respect environment variable VCPKG_ROOT and VCPKG_INSTALLATION_ROOT if set
if(DEFINED ENV{VCPKG_ROOT} AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "")
set(_VCPKG_ROOT
"$ENV{VCPKG_ROOT}"
CACHE PATH "Vcpkg root directory" FORCE)
elseif(DEFINED ENV{VCPKG_INSTALLATION_ROOT}
AND NOT "$ENV{VCPKG_INSTALLATION_ROOT}" STREQUAL "")
set(_VCPKG_ROOT
"$ENV{VCPKG_INSTALLATION_ROOT}"
CACHE PATH "Vcpkg root directory" FORCE)
else()
unset(_VCPKG_ROOT CACHE)
endif()
endmacro()

# bootstrap and configure vcpkg
macro(vcpkg_configure)
detect_vcpkg()

if(NOT VCPKG_EXPORT_MODE)
_vcpkg_bootstrap(${ARGN})
_vcpkg_skip_install_on_reconfigure()
Expand Down
20 changes: 2 additions & 18 deletions cmake/vcpkg/vcpkg.toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,13 @@ unset(IN_TRY_COMPILE)
# Load the common settings
include(${CMAKE_CURRENT_LIST_DIR}/scripts/build_type.cmake)

# Vcpkg build environment
file(READ ${CMAKE_SOURCE_DIR}/vcpkg.json _vcpkg_json)
string(JSON _builtin_baseline GET ${_vcpkg_json} builtin-baseline)

# Respect environment variable VCPKG_ROOT and VCPKG_INSTALLATION_ROOT if set
if(DEFINED ENV{VCPKG_ROOT} AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "")
set(_VCPKG_ROOT
"$ENV{VCPKG_ROOT}"
CACHE PATH "Vcpkg root directory" FORCE)
elseif(DEFINED ENV{VCPKG_INSTALLATION_ROOT}
AND NOT "$ENV{VCPKG_INSTALLATION_ROOT}" STREQUAL "")
set(_VCPKG_ROOT
"$ENV{VCPKG_INSTALLATION_ROOT}"
CACHE PATH "Vcpkg root directory" FORCE)
else()
unset(_VCPKG_ROOT CACHE)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/bootstrap/vcpkg-config.cmake)

set(VCPKG_VERBOSE
ON
CACHE BOOL "Vcpkg VCPKG_VERBOSE")

file(READ ${CMAKE_SOURCE_DIR}/vcpkg.json _vcpkg_json)
string(JSON _builtin_baseline GET ${_vcpkg_json} builtin-baseline)
vcpkg_configure(CACHE_DIR_NAME ss-cpp REPO
https://github.com/microsoft/vcpkg.git REF ${_builtin_baseline})
28 changes: 16 additions & 12 deletions template/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ endfunction()
function(_vcpkg_checkout vcpkg_root vcpkg_ref)
message(STATUS "vcpkg checkout to ${vcpkg_ref}")

execute_process(
COMMAND ${GIT_EXECUTABLE} fetch origin ${vcpkg_ref}
WORKING_DIRECTORY ${vcpkg_root}
RESULT_VARIABLE result)

if(NOT result EQUAL "0")
if(EXISTS "${vcpkg_root}/.git/shallow")
message(
FATAL_ERROR "${GIT_EXECUTABLE} fetch ${vcpkg_ref} failed with ${result}")
WARNING
"vcpkg is shallow now and unshallow to retrieve the Git tree object hash for a specific version port......"
)
execute_process(
COMMAND ${GIT_EXECUTABLE} fetch --unshallow
WORKING_DIRECTORY ${vcpkg_root}
RESULT_VARIABLE result)

if(NOT result EQUAL "0")
message(
FATAL_ERROR "${GIT_EXECUTABLE} fetch --unshallow failed with ${result}")
endif()
endif()

execute_process(
Expand All @@ -47,7 +53,7 @@ endfunction()
# clone
function(_vcpkg_clone vcpkg_root vcpkg_repo vcpkg_ref)
execute_process(
COMMAND ${GIT_EXECUTABLE} clone ${vcpkg_repo} ${vcpkg_root} --depth=1
COMMAND ${GIT_EXECUTABLE} clone ${vcpkg_repo} ${vcpkg_root}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE result)

Expand Down Expand Up @@ -123,7 +129,7 @@ function(_vcpkg_upgrade vcpkg_root vcpkg_repo vcpkg_ref)

message(STATUS "Upgrade vcpkg")
message(STATUS "vcpkg current commit: ${current_git_hash}")
message(STATUS "vcpkg release: ${vcpkg_ref}")
message(STATUS "vcpkg target commit: ${vcpkg_ref}")

execute_process(
COMMAND ${GIT_EXECUTABLE} remote set-url origin ${vcpkg_repo}
Expand All @@ -150,9 +156,7 @@ endfunction()

# find root
function(_vcpkg_find_root cache_dir_name out_vcpkg_root)
if(DEFINED ENV{VCPKG_ROOT} AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "")
set(root "$ENV{VCPKG_ROOT}")
elseif("${__vcpkg_bootstrap_host}" STREQUAL "Windows")
if("${__vcpkg_bootstrap_host}" STREQUAL "Windows")
set(root "$ENV{LOCALAPPDATA}/vcpkg/projects/${cache_dir_name}/cache")
else()
set(root "$ENV{HOME}/.cache/vcpkg/projects/${cache_dir_name}")
Expand Down
18 changes: 18 additions & 0 deletions template/cmake/vcpkg/bootstrap/vcpkg_configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,26 @@ function(_vcpkg_export_mode)
message(STATUS "Disable manifest mode for using vcpkg exported artifacts")
endfunction()

macro(detect_vcpkg)
# Respect environment variable VCPKG_ROOT and VCPKG_INSTALLATION_ROOT if set
if(DEFINED ENV{VCPKG_ROOT} AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "")
set(_VCPKG_ROOT
"$ENV{VCPKG_ROOT}"
CACHE PATH "Vcpkg root directory" FORCE)
elseif(DEFINED ENV{VCPKG_INSTALLATION_ROOT}
AND NOT "$ENV{VCPKG_INSTALLATION_ROOT}" STREQUAL "")
set(_VCPKG_ROOT
"$ENV{VCPKG_INSTALLATION_ROOT}"
CACHE PATH "Vcpkg root directory" FORCE)
else()
unset(_VCPKG_ROOT CACHE)
endif()
endmacro()

# bootstrap and configure vcpkg
macro(vcpkg_configure)
detect_vcpkg()

if(NOT VCPKG_EXPORT_MODE)
_vcpkg_bootstrap(${ARGN})
_vcpkg_skip_install_on_reconfigure()
Expand Down
20 changes: 2 additions & 18 deletions template/cmake/vcpkg/vcpkg.toolchain.cmake.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,13 @@ unset(IN_TRY_COMPILE)
# Load the common settings
include(${CMAKE_CURRENT_LIST_DIR}/scripts/build_type.cmake)

# Vcpkg build environment
file(READ ${CMAKE_SOURCE_DIR}/vcpkg.json _vcpkg_json)
string(JSON _builtin_baseline GET ${_vcpkg_json} builtin-baseline)

# Respect environment variable VCPKG_ROOT and VCPKG_INSTALLATION_ROOT if set
if(DEFINED ENV{VCPKG_ROOT} AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "")
set(_VCPKG_ROOT
"$ENV{VCPKG_ROOT}"
CACHE PATH "Vcpkg root directory" FORCE)
elseif(DEFINED ENV{VCPKG_INSTALLATION_ROOT}
AND NOT "$ENV{VCPKG_INSTALLATION_ROOT}" STREQUAL "")
set(_VCPKG_ROOT
"$ENV{VCPKG_INSTALLATION_ROOT}"
CACHE PATH "Vcpkg root directory" FORCE)
else()
unset(_VCPKG_ROOT CACHE)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/bootstrap/vcpkg-config.cmake)

set(VCPKG_VERBOSE
ON
CACHE BOOL "Vcpkg VCPKG_VERBOSE")

file(READ ${CMAKE_SOURCE_DIR}/vcpkg.json _vcpkg_json)
string(JSON _builtin_baseline GET ${_vcpkg_json} builtin-baseline)
vcpkg_configure(CACHE_DIR_NAME {{ repo_name}} REPO
https://github.com/microsoft/vcpkg.git REF ${_builtin_baseline})

0 comments on commit 2fd2672

Please sign in to comment.