prelim vcpkg manifest support

toml-checker
MoAlyousef 3 years ago
parent 4988f141e4
commit dc4b59f05d

1
CMakeLists.txt generated

@ -125,6 +125,7 @@ target_link_libraries(cmkr PRIVATE
ghc_filesystem
mpark_variant
ordered_map
nlohmann_json
)
unset(CMKR_TARGET)

@ -33,7 +33,6 @@ struct Package {
};
struct Vcpkg {
std::string version;
std::vector<std::string> packages;
};
@ -64,6 +63,7 @@ struct Target {
ConditionVector link_libraries;
ConditionVector link_options;
ConditionVector precompile_headers;
ConditionVector headers;
ConditionVector sources;
std::string alias;

@ -181,6 +181,7 @@ CMake::CMake(const std::string &path, bool build) {
target.name = itr.first;
target.type = to_enum<TargetType>(toml::find(t, "type").as_string(), "target type");
get_optional(t, "headers", target.headers);
get_optional(t, "sources", target.sources);
get_optional(t, "compile-definitions", target.compile_definitions);
get_optional(t, "compile-features", target.compile_features);
@ -250,15 +251,7 @@ CMake::CMake(const std::string &path, bool build) {
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";
}
}
// Reasonable default conditions (you can override these if you desire)

@ -8,6 +8,8 @@
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <nlohmann/json.hpp>
#include <new>
#include <sstream>
#include <stdexcept>
@ -294,7 +296,7 @@ struct Command {
}
template <class... Ts>
CommandEndl operator()(Ts &&...values) {
CommandEndl operator()(Ts &&... values) {
generated = true;
ss << indent(depth) << command << '(';
(void)std::initializer_list<bool>{print_arg(values)...};
@ -520,15 +522,20 @@ 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.vcpkg.packages.empty()) {
cmd("include")("FetchContent");
cmd("message")("STATUS \"Fetching vcpkg...\"");
cmd("FetchContent_Declare")("vcpkg\n\tURL\thttps://github.com/microsoft/vcpkg/archive/refs/tags/2021.05.12.tar.gz");
cmd("FetchContent_MakeAvailable")("vcpkg");
cmd("include")("${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake");
using namespace nlohmann;
json j;
j["$schema"] = "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json";
j["name"] = cmake.project_name;
j["version"] = cmake.project_version;
j["dependencies"] = cmake.vcpkg.packages;
std::ofstream ofs("vcpkg.json");
ofs << std::setw(4) << j << std::endl;
}
if (!cmake.packages.empty()) {
@ -603,8 +610,21 @@ int generate_cmake(const char *path, bool root) {
[&](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); });
gen.handle_condition(target.cmake_before, [&](const std::string &, const std::string &cmake) { inject_cmake(cmake); });
auto headers_var = target.name + "_HEADERS";
auto sources_var = target.name + "_SOURCES";
if (!target.headers.empty()) {
cmd("set")(headers_var, RawArg("\"\"")).endl();
gen.handle_condition(target.headers, [&](const std::string &condition, const std::vector<std::string> &condition_headers) {
auto headers = expand_cmake_paths(condition_headers, path);
if (headers.empty()) {
auto header_key = condition.empty() ? "headers" : (condition + ".headers");
throw std::runtime_error(target.name + " " + header_key + " wildcard found 0 files");
}
cmd("list")("APPEND", headers_var, headers);
});
}
bool added_toml = false;
cmd("set")(sources_var, RawArg("\"\"")).endl();
gen.handle_condition(target.sources, [&](const std::string &condition, const std::vector<std::string> &condition_sources) {
@ -682,8 +702,12 @@ int generate_cmake(const char *path, bool root) {
// clang-format on
}
if (!target.headers.empty()) {
cmd("source_group")("TREE", "${CMAKE_CURRENT_SOURCE_DIR}", "FILES", "${" + headers_var + "}").endl();
}
if (!target.sources.empty()) {
cmd("source_group")("TREE", "${CMAKE_CURRENT_SOURCE_DIR}", "FILES", "${" + target.name + "_SOURCES}").endl();
cmd("source_group")("TREE", "${CMAKE_CURRENT_SOURCE_DIR}", "FILES", "${" + sources_var + "}").endl();
}
if (!target.alias.empty()) {

4
third_party/CMakeLists.txt generated vendored

@ -16,3 +16,7 @@ target_include_directories(toml11 INTERFACE toml11-3.6.0)
# https://github.com/mpark/variant (BSL-1.0)
add_library(mpark_variant INTERFACE)
target_include_directories(mpark_variant INTERFACE variant-1.4.0/include)
# https://github.com/nlohmann/json (MIT)
add_library(nlohmann_json INTERFACE)
target_include_directories(nlohmann_json INTERFACE nlohmann-3.9.1/include)

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2013-2021 Niels Lohmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save