Skip to content

Commit

Permalink
Merge pull request #152 from aminya/vcpkg [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Sep 13, 2022
2 parents da16f4d + ec9be4a commit 59462c0
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/Vcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ macro(run_vcpkg)
""
${ARGN})

find_program(GIT_EXECUTABLE "git" REQUIRED)

if(NOT
"${_vcpkg_args_VCPKG_DIR}"
STREQUAL
Expand All @@ -39,8 +41,26 @@ macro(run_vcpkg)
if(EXISTS "${_vcpkg_args_VCPKG_DIR}" AND EXISTS "${_vcpkg_args_VCPKG_DIR}/vcpkg${CMAKE_EXECUTABLE_SUFFIX}")
message(STATUS "vcpkg is already installed at ${_vcpkg_args_VCPKG_DIR}.")
if(${_vcpkg_args_ENABLE_VCPKG_UPDATE})

if(NOT
"${_vcpkg_args_VCPKG_REV}"
STREQUAL
"")
# detect if the head is detached, if so, switch back before calling git pull on a detached head
set(GIT_STATUS "")
execute_process(
COMMAND "${GIT_EXECUTABLE}" "rev-parse" "--abbrev-ref" "--symbolic-full-name" "HEAD"
OUTPUT_VARIABLE GIT_STATUS
WORKING_DIRECTORY "${_vcpkg_args_VCPKG_DIR}"
OUTPUT_STRIP_TRAILING_WHITESPACE)
if("${GIT_STATUS}" STREQUAL "HEAD")
message(STATUS "Switching back before updating")
execute_process(COMMAND "${GIT_EXECUTABLE}" "switch" "-" WORKING_DIRECTORY "${_vcpkg_args_VCPKG_DIR}")
endif()
endif()

message(STATUS "Updating the repository...")
execute_process(COMMAND "git" "pull" WORKING_DIRECTORY "${_vcpkg_args_VCPKG_DIR}")
execute_process(COMMAND "${GIT_EXECUTABLE}" "pull" WORKING_DIRECTORY "${_vcpkg_args_VCPKG_DIR}")
endif()
else()
message(STATUS "Installing vcpkg at ${_vcpkg_args_VCPKG_DIR}")
Expand All @@ -49,7 +69,6 @@ macro(run_vcpkg)
if("${_vcpkg_args_VCPKG_URL}" STREQUAL "")
set(_vcpkg_args_VCPKG_URL "https://github.com/microsoft/vcpkg.git")
endif()
find_program(GIT_EXECUTABLE "git" REQUIRED)
execute_process(COMMAND "${GIT_EXECUTABLE}" "clone" "${_vcpkg_args_VCPKG_URL}"
WORKING_DIRECTORY "${VCPKG_PARENT_DIR}" COMMAND_ERROR_IS_FATAL LAST)
endif()
Expand All @@ -67,7 +86,6 @@ macro(run_vcpkg)
"${_vcpkg_args_VCPKG_REV}"
STREQUAL
"")
find_program(GIT_EXECUTABLE "git" REQUIRED)
execute_process(COMMAND "${GIT_EXECUTABLE}" "checkout" "${_vcpkg_args_VCPKG_REV}"
WORKING_DIRECTORY "${VCPKG_PARENT_DIR}/vcpkg" COMMAND_ERROR_IS_FATAL LAST)
endif()
Expand Down

0 comments on commit 59462c0

Please sign in to comment.