Skip to content

Commit

Permalink
Merge pull request #156 from build-cpp/vcpkg-overlay-ports
Browse files Browse the repository at this point in the history
Add [vcpkg].overlay-ports feature
  • Loading branch information
mrexodia authored Nov 26, 2024
2 parents 5704256 + ae3d738 commit 45ca740
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/cmake-toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,15 @@ Variables emit a [`set`](https://cmake.org/cmake/help/latest/command/set.html) a
version = "2024.03.25"
url = "https://github.com/microsoft/vcpkg/archive/refs/tags/2024.03.25.tar.gz"
packages = ["fmt", "zlib"]
overlay-ports = ["my-ports"]
```

The vcpkg `version` will automatically generate the `url` from the [official repository](https://github.com/microsoft/vcpkg/releases). For a custom registry you can specify your own `url` (and omit the `version`). You can browse available packages on [vcpkg.io](https://vcpkg.io/en/packages.html).

To specify package features you can use the following syntax: `imgui[docking-experimental,freetype,sdl2-binding,opengl3-binding]`.

The `overlay-ports` feature allows you to embed vcpkg ports inside your project, without having to fork the main vcpkg registry or creating a custom registry. You can find more information in the relevant [documentation](https://learn.microsoft.com/en-us/vcpkg/concepts/overlay-ports).

## Packages

```toml
Expand Down
1 change: 1 addition & 0 deletions include/project_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct Vcpkg {
};

std::vector<Package> packages;
std::vector<std::string> overlay_ports;

bool enabled() const {
return !packages.empty();
Expand Down
26 changes: 24 additions & 2 deletions src/cmake_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
ofs << R"({
"$cmkr": "This file is automatically generated from cmake.toml - DO NOT EDIT",
"$cmkr-url": "https://github.com/build-cpp/cmkr",
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"dependencies": [
)";

Expand Down Expand Up @@ -993,7 +993,29 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
ofs << " ],\n";
ofs << " \"description\": \"" << escape(project.project_description) << "\",\n";
ofs << " \"name\": \"" << escape(vcpkg_escape_identifier(project.project_name)) << "\",\n";
ofs << R"( "version-string": "")" << '\n';
ofs << " \"version-string\": \"none\"";
const auto &overlay_ports = project.vcpkg.overlay_ports;
if (!overlay_ports.empty()) {
ofs << ",\n";
// Reference: https://learn.microsoft.com/en-us/vcpkg/reference/vcpkg-json#vcpkg-configuration
ofs << " \"vcpkg-configuration\": {\n";
ofs << " \"overlay-ports\": [\n";
for (size_t i = 0; i < overlay_ports.size(); i++) {
const auto &directory = overlay_ports[i];
if (!fs::is_directory(directory)) {
throw std::runtime_error("[vcpkg].overlay-ports is not a directory: " + directory);
}
ofs << " \"" << escape(directory) << "\"";
if (i > 0) {
ofs << ",";
}
ofs << "\n";
}
ofs << " ]\n";
ofs << " }\n";
} else {
ofs << "\n";
}
ofs << "}\n";
}

Expand Down
2 changes: 2 additions & 0 deletions src/project_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,8 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
}
vcpkg.packages.emplace_back(std::move(package));
}

v.optional("overlay-ports", vcpkg.overlay_ports);
}

checker.check(conditions, true);
Expand Down

0 comments on commit 45ca740

Please sign in to comment.