Initial vcpkg support

toml-checker archive_5a20c0fe
Duncan Ogilvie 4 years ago
parent b5752b7c2b
commit 5a20c0fe42

@ -130,9 +130,10 @@ CMake::CMake(const std::string &path, bool build) {
if (pkg.second.is_string()) {
p.version = pkg.second.as_string();
} else {
p.version = toml::find_or(pkg.second, "version", "");
p.required = toml::find_or(pkg.second, "required", false);
p.components = toml::find_or(pkg.second, "components", std::vector<std::string>());
p.version = toml::find_or(pkg.second, "version", p.version);
p.required = toml::find_or(pkg.second, "required", p.required);
p.config = toml::find_or(pkg.second, "config", p.config);
p.components = toml::find_or(pkg.second, "components", p.components);
}
packages.push_back(p);
}
@ -186,8 +187,8 @@ CMake::CMake(const std::string &path, bool build) {
target.properties = toml::find<prop_map>(t, "properties");
}
target.cmake_before = toml::find_or(t, "cmake-before", "");
target.cmake_after = toml::find_or(t, "cmake-after", "");
target.cmake_before = toml::find_or(t, "cmake-before", target.cmake_before);
target.cmake_after = toml::find_or(t, "cmake-after", target.cmake_after);
target.include_before = optional_array(t, "include-before");
target.include_after = optional_array(t, "include-after");
@ -218,6 +219,19 @@ CMake::CMake(const std::string &path, bool build) {
installs.push_back(inst);
}
}
if (toml.contains("vcpkg")) {
const auto &v = toml::find(toml, "vcpkg");
vcpkg.version = toml::find(v, "version").as_string();
vcpkg.packages = toml::find<decltype(vcpkg.packages)>(v, "packages");
// This allows the user to use a custom pmm version if desired
if (contents.count("pmm") == 0) {
contents["pmm"]["url"] = "https://github.com/vector-of-bool/pmm/archive/refs/tags/1.5.1.tar.gz";
// Hack to not execute pmm's example CMakeLists.txt
contents["pmm"]["SOURCE_SUBDIR"] = "pmm";
}
}
}
}
} // namespace cmake

@ -28,9 +28,15 @@ struct Package {
std::string name;
std::string version;
bool required = true;
bool config = true;
std::vector<std::string> components;
};
struct Vcpkg {
std::string version;
std::vector<std::string> packages;
};
enum TargetType {
target_executable,
target_library,
@ -102,6 +108,7 @@ struct CMake {
std::vector<Setting> settings;
std::vector<Option> options;
std::vector<Package> packages;
Vcpkg vcpkg;
tsl::ordered_map<std::string, std::map<std::string, std::string>> contents;
std::vector<Target> targets;
std::vector<Test> tests;

@ -231,10 +231,6 @@ struct Command {
template <class K, class V>
bool print_arg(const std::pair<K, V> &kv) {
std::stringstream tmp;
tmp << kv.second;
auto str = tmp.str();
if (kv.second.empty()) {
return true;
}
@ -242,7 +238,7 @@ struct Command {
had_newline = true;
print_arg(kv.first);
depth++;
print_arg(str);
print_arg(kv.second);
depth--;
return true;
@ -410,17 +406,6 @@ int generate_cmake(const char *path, bool root) {
inject_includes(cmake.include_after);
inject_cmake(cmake.cmake_after);
if (!cmake.packages.empty()) {
for (const auto &dep : cmake.packages) {
auto version = dep.version;
if (version == "*")
version.clear();
auto required = dep.required ? "REQUIRED" : "";
auto components = std::make_pair("COMPONENTS", dep.components);
cmd("find_package")(dep.name, version, required, components).endl();
}
}
if (!cmake.contents.empty()) {
cmd("include")("FetchContent").endl();
for (const auto &dep : cmake.contents) {
@ -450,7 +435,32 @@ int generate_cmake(const char *path, bool root) {
}
}
if (!cmake.vcpkg.version.empty()) {
assert("pmm is required in fetch-content for vcpkg to work" && cmake.contents.count("pmm") != 0);
comment("Bootstrap vcpkg");
cmd("include")("${pmm_SOURCE_DIR}/pmm.cmake");
tsl::ordered_map<std::string, std::vector<std::string>> vcpkg_args;
vcpkg_args["REVISION"] = { cmake.vcpkg.version };
vcpkg_args["REQUIRES"] = cmake.vcpkg.packages;
auto vcpkg = std::make_pair("VCPKG", vcpkg_args);
cmd("pmm")(vcpkg).endl();
}
if (!cmake.packages.empty()) {
comment("Packages");
for (const auto &dep : cmake.packages) {
auto version = dep.version;
if (version == "*")
version.clear();
auto required = dep.required ? "REQUIRED" : "";
auto config = dep.config ? "CONFIG" : "";
auto components = std::make_pair("COMPONENTS", dep.components);
cmd("find_package")(dep.name, version, required, config, components).endl();
}
}
if (!cmake.options.empty()) {
comment("Options");
for (const auto &opt : cmake.options) {
cmd("option")(opt.name, opt.comment, opt.val ? "ON" : "OFF");
}
@ -458,6 +468,7 @@ int generate_cmake(const char *path, bool root) {
}
if (!cmake.settings.empty()) {
comment("Settings");
for (const auto &set : cmake.settings) {
std::string set_val;
if (set.val.index() == 1) {

Loading…
Cancel
Save