Skip to content

Allow disabling default features with vcpkg #158

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

Merged
merged 1 commit into from
Nov 27, 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
2 changes: 1 addition & 1 deletion docs/cmake-toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ 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]`.
To specify package features you can use the following syntax: `imgui[docking-experimental,freetype,sdl2-binding,opengl3-binding]`. To disable the [default features](https://learn.microsoft.com/en-us/vcpkg/concepts/default-features) you can do: `cpp-httplib[core,openssl]`

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

Expand Down
1 change: 1 addition & 0 deletions include/project_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct Vcpkg {
struct Package {
std::string name;
std::vector<std::string> features;
bool default_features = true;
};

std::vector<Package> packages;
Expand Down
7 changes: 5 additions & 2 deletions src/cmake_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,17 +957,20 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
throw std::runtime_error("Invalid vcpkg package feature '" + feature + "', name is reserved");
}
}
if (features.empty()) {
if (features.empty() && package.default_features) {
ofs << " \"" << package.name << '\"';
} else {
ofs << " {\n";
ofs << " \"name\": \"" << package.name << "\",\n";
if (!package.default_features) {
ofs << " \"default-features\": false,\n";
}
ofs << " \"features\": [";
for (size_t j = 0; j < features.size(); j++) {
const auto &feature = features[j];
ofs << '\"' << feature << '\"';
if (j + 1 < features.size()) {
ofs << ',';
ofs << ", ";
}
}
ofs << "]\n";
Expand Down
7 changes: 6 additions & 1 deletion src/project_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,12 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
std::istringstream feature_stream{features};
std::string feature;
while (std::getline(feature_stream, feature, ',')) {
package.features.emplace_back(feature);
// Disable default features with package-name[core,feature1]
if (feature == "core") {
package.default_features = false;
} else {
package.features.emplace_back(feature);
}
}
} else {
throw_key_error("Invalid package name '" + package_str + "'", "packages", p);
Expand Down