Skip to content

Commit

Permalink
Configure vcpkg only if not already done.
Browse files Browse the repository at this point in the history
  • Loading branch information
abeltrano committed Dec 8, 2023
1 parent 4eaaf5e commit bbe71ac
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions cmake/vcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,34 @@ function(vcpkg_configure)
${ARGN}
)

# If the vcpkg root has been specified externally, use it.
if (DEFINED ENV{VCPKG_ROOT})
set(VCPKG_ROOT "$ENV{VCPKG_ROOT}")
# Otherwise, use the specified submodule root.
else()
set(VCPKG_ROOT ${VCPKG_SUBMODULE_ROOT})

find_package(Git REQUIRED)

# Initialize vcpkg sub-module if not already done.
if (NOT EXISTS ${VCPKG_SUBMODULE_ROOT}/.git)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive -- ${VCPKG_SUBMODULE_ROOT}
WORKING_DIRECTORY ${VCPKG_SUBMODULE_ROOT}/../
COMMAND_ERROR_IS_FATAL ANY)
# Only configure vcpkg if not already done externally.
if ("${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}" STREQUAL "")
# If the vcpkg root has been specified externally, use it.
if (DEFINED ENV{VCPKG_ROOT})
set(VCPKG_ROOT "$ENV{VCPKG_ROOT}")
# Otherwise, use the specified submodule root.
else()
set(VCPKG_ROOT ${VCPKG_SUBMODULE_ROOT})

find_package(Git REQUIRED)

# Initialize vcpkg sub-module if not already done.
if (NOT EXISTS ${VCPKG_SUBMODULE_ROOT}/.git)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive -- ${VCPKG_SUBMODULE_ROOT}
WORKING_DIRECTORY ${VCPKG_SUBMODULE_ROOT}/../
COMMAND_ERROR_IS_FATAL ANY)
endif()

# Ignore all changes to the submodule tree.
get_filename_component(VCPKG_SUBMODULE_NAME ${VCPKG_SUBMODULE_ROOT} NAME)
execute_process(COMMAND ${GIT_EXECUTABLE} "config submodule.${VCPKG_SUBMODULE_NAME}.ignore all"
WORKING_DIRECTORY ${VCPKG_SUBMODULE_ROOT}../
)
endif()

# Ignore all changes to the submodule tree.
get_filename_component(VCPKG_SUBMODULE_NAME ${VCPKG_SUBMODULE_ROOT} NAME)
execute_process(COMMAND ${GIT_EXECUTABLE} "config submodule.${VCPKG_SUBMODULE_NAME}.ignore all"
WORKING_DIRECTORY ${VCPKG_SUBMODULE_ROOT}../
)
endif()
# Set the CMake toolchain file to use vcpkg.
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE FILEPATH "CMake toolchain file")

# Set the CMake toolchain file to use vcpkg.
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE FILEPATH "CMake toolchain file")
endif()

endfunction()

0 comments on commit bbe71ac

Please sign in to comment.