Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add [vcpkg].overlay-ports feature #156

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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