From 5a20c0fe428b7773fb393d5d8e70e68aa6e1e0e8 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Mon, 5 Apr 2021 16:47:18 +0200 Subject: [PATCH] Initial vcpkg support --- src/cmkrlib/cmake.cpp | 24 +++++++++++++++++++----- src/cmkrlib/cmake.hpp | 7 +++++++ src/cmkrlib/gen.cpp | 43 +++++++++++++++++++++++++++---------------- 3 files changed, 53 insertions(+), 21 deletions(-) diff --git a/src/cmkrlib/cmake.cpp b/src/cmkrlib/cmake.cpp index c8de88a..b9ebc7e 100644 --- a/src/cmkrlib/cmake.cpp +++ b/src/cmkrlib/cmake.cpp @@ -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()); + 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(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(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 diff --git a/src/cmkrlib/cmake.hpp b/src/cmkrlib/cmake.hpp index cfce1c5..03827aa 100644 --- a/src/cmkrlib/cmake.hpp +++ b/src/cmkrlib/cmake.hpp @@ -28,9 +28,15 @@ struct Package { std::string name; std::string version; bool required = true; + bool config = true; std::vector components; }; +struct Vcpkg { + std::string version; + std::vector packages; +}; + enum TargetType { target_executable, target_library, @@ -102,6 +108,7 @@ struct CMake { std::vector settings; std::vector