prelim vcpkg manifest support

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

1
CMakeLists.txt generated

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

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

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

@ -8,6 +8,8 @@
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <iomanip>
#include <nlohmann/json.hpp>
#include <new> #include <new>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
@ -294,7 +296,7 @@ struct Command {
} }
template <class... Ts> template <class... Ts>
CommandEndl operator()(Ts &&...values) { CommandEndl operator()(Ts &&... values) {
generated = true; generated = true;
ss << indent(depth) << command << '('; ss << indent(depth) << command << '(';
(void)std::initializer_list<bool>{print_arg(values)...}; (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()) { if (!cmake.vcpkg.packages.empty()) {
assert("pmm is required in fetch-content for vcpkg to work" && cmake.contents.count("pmm") != 0); cmd("include")("FetchContent");
comment("Bootstrap vcpkg"); cmd("message")("STATUS \"Fetching vcpkg...\"");
cmd("include")("${pmm_SOURCE_DIR}/pmm.cmake"); cmd("FetchContent_Declare")("vcpkg\n\tURL\thttps://github.com/microsoft/vcpkg/archive/refs/tags/2021.05.12.tar.gz");
tsl::ordered_map<std::string, std::vector<std::string>> vcpkg_args; cmd("FetchContent_MakeAvailable")("vcpkg");
vcpkg_args["REVISION"] = {cmake.vcpkg.version}; cmd("include")("${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake");
vcpkg_args["REQUIRES"] = cmake.vcpkg.packages; using namespace nlohmann;
auto vcpkg = std::make_pair("VCPKG", vcpkg_args); json j;
cmd("pmm")(vcpkg).endl(); 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()) { 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); }); [&](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); }); 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"; 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; bool added_toml = false;
cmd("set")(sources_var, RawArg("\"\"")).endl(); cmd("set")(sources_var, RawArg("\"\"")).endl();
gen.handle_condition(target.sources, [&](const std::string &condition, const std::vector<std::string> &condition_sources) { 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 // clang-format on
} }
if (!target.headers.empty()) {
cmd("source_group")("TREE", "${CMAKE_CURRENT_SOURCE_DIR}", "FILES", "${" + headers_var + "}").endl();
}
if (!target.sources.empty()) { 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()) { 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) # https://github.com/mpark/variant (BSL-1.0)
add_library(mpark_variant INTERFACE) add_library(mpark_variant INTERFACE)
target_include_directories(mpark_variant INTERFACE variant-1.4.0/include) 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