Skip to content

Commit ae3d738

Browse files
committed
Add [vcpkg].overlay-ports feature
1 parent 5704256 commit ae3d738

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

docs/cmake-toml.md

+3
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,15 @@ Variables emit a [`set`](https://cmake.org/cmake/help/latest/command/set.html) a
163163
version = "2024.03.25"
164164
url = "https://github.com/microsoft/vcpkg/archive/refs/tags/2024.03.25.tar.gz"
165165
packages = ["fmt", "zlib"]
166+
overlay-ports = ["my-ports"]
166167
```
167168

168169
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).
169170

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

173+
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).
174+
172175
## Packages
173176

174177
```toml

include/project_parser.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct Vcpkg {
4848
};
4949

5050
std::vector<Package> packages;
51+
std::vector<std::string> overlay_ports;
5152

5253
bool enabled() const {
5354
return !packages.empty();

src/cmake_generator.cpp

+24-2
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
936936
ofs << R"({
937937
"$cmkr": "This file is automatically generated from cmake.toml - DO NOT EDIT",
938938
"$cmkr-url": "https://github.com/build-cpp/cmkr",
939-
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
939+
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
940940
"dependencies": [
941941
)";
942942

@@ -993,7 +993,29 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
993993
ofs << " ],\n";
994994
ofs << " \"description\": \"" << escape(project.project_description) << "\",\n";
995995
ofs << " \"name\": \"" << escape(vcpkg_escape_identifier(project.project_name)) << "\",\n";
996-
ofs << R"( "version-string": "")" << '\n';
996+
ofs << " \"version-string\": \"none\"";
997+
const auto &overlay_ports = project.vcpkg.overlay_ports;
998+
if (!overlay_ports.empty()) {
999+
ofs << ",\n";
1000+
// Reference: https://learn.microsoft.com/en-us/vcpkg/reference/vcpkg-json#vcpkg-configuration
1001+
ofs << " \"vcpkg-configuration\": {\n";
1002+
ofs << " \"overlay-ports\": [\n";
1003+
for (size_t i = 0; i < overlay_ports.size(); i++) {
1004+
const auto &directory = overlay_ports[i];
1005+
if (!fs::is_directory(directory)) {
1006+
throw std::runtime_error("[vcpkg].overlay-ports is not a directory: " + directory);
1007+
}
1008+
ofs << " \"" << escape(directory) << "\"";
1009+
if (i > 0) {
1010+
ofs << ",";
1011+
}
1012+
ofs << "\n";
1013+
}
1014+
ofs << " ]\n";
1015+
ofs << " }\n";
1016+
} else {
1017+
ofs << "\n";
1018+
}
9971019
ofs << "}\n";
9981020
}
9991021

src/project_parser.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,8 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
854854
}
855855
vcpkg.packages.emplace_back(std::move(package));
856856
}
857+
858+
v.optional("overlay-ports", vcpkg.overlay_ports);
857859
}
858860

859861
checker.check(conditions, true);

0 commit comments

Comments
 (0)