Skip to content

Commit b52cf5b

Browse files
authored
Merge pull request #158 from build-cpp/vcpkg-default-features
Allow disabling default features with vcpkg
2 parents 13a7a87 + e9480a6 commit b52cf5b

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

docs/cmake-toml.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ overlay-ports = ["my-ports"]
168168

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

171-
To specify package features you can use the following syntax: `imgui[docking-experimental,freetype,sdl2-binding,opengl3-binding]`.
171+
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]`
172172

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

include/project_parser.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct Vcpkg {
4545
struct Package {
4646
std::string name;
4747
std::vector<std::string> features;
48+
bool default_features = true;
4849
};
4950

5051
std::vector<Package> packages;

src/cmake_generator.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -957,17 +957,20 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
957957
throw std::runtime_error("Invalid vcpkg package feature '" + feature + "', name is reserved");
958958
}
959959
}
960-
if (features.empty()) {
960+
if (features.empty() && package.default_features) {
961961
ofs << " \"" << package.name << '\"';
962962
} else {
963963
ofs << " {\n";
964964
ofs << " \"name\": \"" << package.name << "\",\n";
965+
if (!package.default_features) {
966+
ofs << " \"default-features\": false,\n";
967+
}
965968
ofs << " \"features\": [";
966969
for (size_t j = 0; j < features.size(); j++) {
967970
const auto &feature = features[j];
968971
ofs << '\"' << feature << '\"';
969972
if (j + 1 < features.size()) {
970-
ofs << ',';
973+
ofs << ", ";
971974
}
972975
}
973976
ofs << "]\n";

src/project_parser.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,12 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
847847
std::istringstream feature_stream{features};
848848
std::string feature;
849849
while (std::getline(feature_stream, feature, ',')) {
850-
package.features.emplace_back(feature);
850+
// Disable default features with package-name[core,feature1]
851+
if (feature == "core") {
852+
package.default_features = false;
853+
} else {
854+
package.features.emplace_back(feature);
855+
}
851856
}
852857
} else {
853858
throw_key_error("Invalid package name '" + package_str + "'", "packages", p);

0 commit comments

Comments
 (0)