Skip to content

Commit

Permalink
read baseline commit from manifest and checkout specified vcpkg version
Browse files Browse the repository at this point in the history
  • Loading branch information
bitmeal committed Mar 25, 2022
1 parent 24a7950 commit bfcca19
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ When a `vcpkg.json` manifest file is present, all packages from this manifest wi
cmake -DVCPKG_PARENT_DIR=<path-to-build-directory> -P <path-to>/vcpkg.cmake
```
* **Set your build directory** using `-DVCPKG_PARENT_DIR=<path-to-build-directory>` (directory will be created if not exists)
* Set your *vcpkg* version as outlined below in ***vcpkg* versions** (`-DVCPKG_VERSION=<version>`)
* if your manifest has no `builtin-baseline`, set your *vcpkg* version as outlined below in ***vcpkg* versions** (`-DVCPKG_VERSION=<version>`)
* `VCPKG_TARGET_TRIPLET`/`VCPKG_DEFAULT_TRIPLET` CMake variables will set `ENV{VCPKG_DEFAULT_TRIPLET}`
* `VCPKG_HOST_TRIPLET`/`VCPKG_DEFAULT_HOST_TRIPLET` CMake variables will set `ENV{VCPKG_DEFAULT_HOST_TRIPLET}`

Expand All @@ -71,6 +71,8 @@ Valid values for `<version>` are:
* `<empty>`: gets you `latest`
* `edge`: latest commit on *vcpkg* master branch
* `<commit-hash>/<tag>`: any tag or commit hash from the *vcpkg*-repo may be used

> 📌 if a `vcpkg.json` manifest exists and specifies a `builtin-baseline`, this commit will be checked out

## setting target/host architecture
Expand Down
25 changes: 24 additions & 1 deletion vcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ endfunction()

# determine git checkout target in: VCPKG_VERSION_CHECKOUT
# vcpkg_set_version_checkout([VCPKG_VERSION_EXPLICIT] [VCPKG_DIRECTORY_EXPLICIT])
# TODO: set hash from vcpkg.json manifest if version==""
function(vcpkg_set_version_checkout)
if(ARGV0 EQUAL "" OR NOT DEFINED ARGV0)
set(VCPKG_VERSION_EXPLICIT ${VCPKG_VERSION})
Expand All @@ -304,6 +303,30 @@ function(vcpkg_set_version_checkout)
string(REGEX REPLACE "\n$" "" VCPKG_GIT_TAG_LATEST "${VCPKG_GIT_TAG_LATEST}")

# resolve versions
if(EXISTS "./vcpkg.json")
# set hash from vcpkg.json manifest
file(READ "./vcpkg.json" VCPKG_MANIFEST_CONTENTS)

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
string(JSON VCPKG_BASELINE GET "${VCPKG_MANIFEST_CONTENTS}" "builtin-baseline")
else()
string(REGEX REPLACE "[\n ]" "" VCPKG_MANIFEST_CONTENTS "${VCPKG_MANIFEST_CONTENTS}")
message(STATUS "manifest: ${VCPKG_MANIFEST_CONTENTS}")
string(REGEX MATCH "\"builtin-baseline\":\"[0-9a-f]+\"" VCPKG_BASELINE "${VCPKG_MANIFEST_CONTENTS}")
string(REPLACE "\"builtin-baseline\":" "" VCPKG_BASELINE "${VCPKG_BASELINE}")
string(REPLACE "\"" "" VCPKG_BASELINE "${VCPKG_BASELINE}")
message(STATUS "basline commit: ${VCPKG_BASELINE}")
endif()

if(NOT "${VCPKG_BASELINE}" EQUAL "")
if(NOT "${VCPKG_VERSION}" EQUAL "" AND DEFINED VCPKG_VERSION)
message(WARNING "VCPKG_VERSION was specified, but vcpkg.json manifest is used and specifies a builtin-baseline; using builtin-baseline: ${VCPKG_BASELINE}")
endif()
set(VCPKG_VERSION_EXPLICIT "${VCPKG_BASELINE}")
message(STATUS "Using VCPKG Version: <manifest builtin-baseline>")
endif()
endif()

if("${VCPKG_VERSION_EXPLICIT}" STREQUAL "latest" OR "${VCPKG_VERSION_EXPLICIT}" EQUAL "" OR NOT DEFINED VCPKG_VERSION_EXPLICIT)
set(VCPKG_VERSION_CHECKOUT ${VCPKG_GIT_TAG_LATEST})
message(STATUS "Using VCPKG Version: ${VCPKG_VERSION_EXPLICIT} (latest)")
Expand Down

0 comments on commit bfcca19

Please sign in to comment.