Last active
August 4, 2024 13:34
-
-
Save nickelpro/b9961165eee762f0e2f00cb8689e62a5 to your computer and use it in GitHub Desktop.
Bootstrapping script that sets up vcpkg without having to clone the entire repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(NOT SKIP_VCPKG AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) | |
include(FetchContent) | |
if(WIN32) | |
set(VCPKG vcpkg.exe) | |
elseif(LINUX) | |
if(EXISTS "/etc/alpine-release") | |
set(VCPKG vcpkg-musl) | |
else() | |
set(VCPKG vcpkg-glibc) | |
endif() | |
elseif(APPLE) | |
set(VCPKG vcpkg-macos) | |
else() | |
message(FATAL_ERROR "Cannot bootstrap vcpkg: Unsupported platform") | |
endif() | |
FetchContent_Declare(vcpkg | |
URL https://github.com/microsoft/vcpkg-tool/releases/latest/download/${VCPKG} | |
DOWNLOAD_NO_EXTRACT TRUE | |
) | |
FetchContent_MakeAvailable(vcpkg) | |
set(VCPKG ${vcpkg_SOURCE_DIR}/${VCPKG}) | |
file(CHMOD ${VCPKG} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE) | |
set(ENV{VCPKG_ROOT} ${vcpkg_SOURCE_DIR}) | |
execute_process(COMMAND ${VCPKG} bootstrap-standalone) | |
if(NOT WIN32) | |
file(RENAME ${VCPKG} ${vcpkg_SOURCE_DIR}/vcpkg) | |
set(VCPKG ${vcpkg_SOURCE_DIR}/vcpkg) | |
endif() | |
set(CMAKE_TOOLCHAIN_FILE | |
${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake | |
CACHE FILEPATH "Vcpkg toolchain file" | |
) | |
set(VCPKG_ROOT_DIR ${vcpkg_SOURCE_DIR} CACHE PATH "Vcpkg root directory") | |
set(VCPKG_EXECUTABLE ${VCPKG} CACHE FILEPATH "Vcpkg tool executable") | |
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.29) | |
include(cmake/BootstrapVcpkg.cmake) | |
if(DEFINED VCPKG_EXECUTABLE) | |
add_custom_target(UpdateVcpkgBaseline | |
${VCPKG_EXECUTABLE} x-update-baseline | |
) | |
endif() | |
project(vcpkg-test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment