Skip to content

Commit

Permalink
allow additional triplet options/flags for script mode; update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bitmeal committed Mar 25, 2022
1 parent a79e44e commit 24a7950
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ vcpkg_add_package(fmt)
...
```

### What it does & intended use
## What it does & intended use
* fetch *vcpkg* & build if required
* provide *"numeric"* or semantic versioning of *vcpkg* itself
* enable the *vcpkg*-*CMake* toolchain
Expand All @@ -30,22 +30,32 @@ vcpkg_add_package(fmt)

Intention of this script is to provide rapid setup and integration for *vcpkg* to kickstart your *C++* development on **(mainly) new** projects. Secondary use-case is sharing and reliable builds of projects by persons unfamiliar with *CMake* and managing dependencies for *C++* projects.

#### `vcpkg_add_package()`
This wrapper around `vcpkg install` makes the use of *vcpkg* completely transparent and is intended for the **setup and prototyping phase** of your project, allowing to focus on your code and not getting distracted by dependency management.
## using `vcpkg_add_package()`
This wrapper around `vcpkg install` makes the use of *vcpkg* completely transparent and is intended for the **setup and prototyping phase** of your project, allowing to focus on your build and not getting distracted by setting up package management systems.

What it does more, is **generating a `vcpkg.json`-manifest** in your build directory, *to be used at a later stage* of your project to pin dependencies!
> **📌 CMake 3.19 or later is required for automatic manifest generation!**
## using `vcpkg.json`-manifests
When a `vcpkg.json` manifest file is present, all packages from this manifest will be installed. Per default, `manifests` and `versions` features are enabled. **Using manifests is (at time of writing) still considered *experimental*. Using versioning and the `versions`-key may currently require a newer *vcpkg* version than tagged as latest release! Check the [official resources](https://github.com/microsoft/vcpkg) for the state of manifest use! The `edge`-version supports versioning, as per the examples.**

To transition to manifests from `vcpkg_add_package()` calls, use the auto-generated manifest in your build directory.
> **To transition to manifests from `vcpkg_add_package()` calls, use the *auto-generated manifest in your build directory*.**
### manifests and container layer caching
To make use of the manifest to setup your dependencies independently of you project, use following recipe:
### manifests, CMake scripting mode & container layer caching
`vcpkg.cmake` can be called in *CMake* scripting mode to bootstrap *vcpkg* and install dependencies from a manifest. Allowing you to separate dependency installation and configuration of your project. This is mainly useful in building containers and not fetching and rebuilding all dependencies on every new build.
```shell
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>`)
* `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}`

As no *CMake* configuration step is performed, *vcpkgs* own toolchain integration does not execute its magic itself, so be careful to set your target triplets accordingly.

#### container recipe
* `ADD` `vcpkg.json`-manifest to your project root inside the container
* `ADD` your copy of `vcpkg.cmake` to your container
* create your build directory
* run `cmake -DVCPKG_PARENT_DIR=<path-to-build-directory> -DVCPKG_VERSION=<desired-vcpkg-version> -DVCPKG_DEFAULT_TRIPLET=<triplet> -P <path-to>/vcpkg.cmake` in your project root


Expand Down
8 changes: 7 additions & 1 deletion vcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2021, Arne Wendt
# Copyright (C) 2022, Arne Wendt
#

# vcpkg examples use 3.0.0, assuming this as minimum version for vcpkg cmake toolchain
Expand Down Expand Up @@ -58,9 +58,15 @@ function(vcpkg_init)

# for use in scripting mode
if(CMAKE_SCRIPT_MODE_FILE)
if(VCPKG_TARGET_TRIPLET)
set(ENV{VCPKG_DEFAULT_TRIPLET} "${VCPKG_DEFAULT_TRIPLET}")
endif()
if(VCPKG_DEFAULT_TRIPLET)
set(ENV{VCPKG_DEFAULT_TRIPLET} "${VCPKG_DEFAULT_TRIPLET}")
endif()
if(VCPKG_HOST_TRIPLET)
set(ENV{VCPKG_DEFAULT_HOST_TRIPLET} "${VCPKG_DEFAULT_HOST_TRIPLET}")
endif()
if(VCPKG_DEFAULT_HOST_TRIPLET)
set(ENV{VCPKG_DEFAULT_HOST_TRIPLET} "${VCPKG_DEFAULT_HOST_TRIPLET}")
endif()
Expand Down

0 comments on commit 24a7950

Please sign in to comment.