|
8 | 8 | #include <cstdio> |
9 | 9 | #include <cstring> |
10 | 10 | #include <fstream> |
| 11 | +#include <iomanip> |
| 12 | +#include <nlohmann/json.hpp> |
11 | 13 | #include <new> |
12 | 14 | #include <sstream> |
13 | 15 | #include <stdexcept> |
@@ -294,7 +296,7 @@ struct Command { |
294 | 296 | } |
295 | 297 |
|
296 | 298 | template <class... Ts> |
297 | | - CommandEndl operator()(Ts &&...values) { |
| 299 | + CommandEndl operator()(Ts &&... values) { |
298 | 300 | generated = true; |
299 | 301 | ss << indent(depth) << command << '('; |
300 | 302 | (void)std::initializer_list<bool>{print_arg(values)...}; |
@@ -520,15 +522,20 @@ int generate_cmake(const char *path, bool root) { |
520 | 522 | } |
521 | 523 | } |
522 | 524 |
|
523 | | - if (!cmake.vcpkg.version.empty()) { |
524 | | - assert("pmm is required in fetch-content for vcpkg to work" && cmake.contents.count("pmm") != 0); |
525 | | - comment("Bootstrap vcpkg"); |
526 | | - cmd("include")("${pmm_SOURCE_DIR}/pmm.cmake"); |
527 | | - tsl::ordered_map<std::string, std::vector<std::string>> vcpkg_args; |
528 | | - vcpkg_args["REVISION"] = {cmake.vcpkg.version}; |
529 | | - vcpkg_args["REQUIRES"] = cmake.vcpkg.packages; |
530 | | - auto vcpkg = std::make_pair("VCPKG", vcpkg_args); |
531 | | - cmd("pmm")(vcpkg).endl(); |
| 525 | + if (!cmake.vcpkg.packages.empty()) { |
| 526 | + cmd("include")("FetchContent"); |
| 527 | + cmd("message")("STATUS \"Fetching vcpkg...\""); |
| 528 | + cmd("FetchContent_Declare")("vcpkg\n\tURL\thttps://github.com/microsoft/vcpkg/archive/refs/tags/2021.05.12.tar.gz"); |
| 529 | + cmd("FetchContent_MakeAvailable")("vcpkg"); |
| 530 | + cmd("include")("${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake"); |
| 531 | + using namespace nlohmann; |
| 532 | + json j; |
| 533 | + j["$schema"] = "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json"; |
| 534 | + j["name"] = cmake.project_name; |
| 535 | + j["version"] = cmake.project_version; |
| 536 | + j["dependencies"] = cmake.vcpkg.packages; |
| 537 | + std::ofstream ofs("vcpkg.json"); |
| 538 | + ofs << std::setw(4) << j << std::endl; |
532 | 539 | } |
533 | 540 |
|
534 | 541 | if (!cmake.packages.empty()) { |
@@ -603,8 +610,21 @@ int generate_cmake(const char *path, bool root) { |
603 | 610 | [&](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); }); |
604 | 611 | gen.handle_condition(target.cmake_before, [&](const std::string &, const std::string &cmake) { inject_cmake(cmake); }); |
605 | 612 |
|
| 613 | + auto headers_var = target.name + "_HEADERS"; |
606 | 614 | auto sources_var = target.name + "_SOURCES"; |
607 | 615 |
|
| 616 | + if (!target.headers.empty()) { |
| 617 | + cmd("set")(headers_var, RawArg("\"\"")).endl(); |
| 618 | + gen.handle_condition(target.headers, [&](const std::string &condition, const std::vector<std::string> &condition_headers) { |
| 619 | + auto headers = expand_cmake_paths(condition_headers, path); |
| 620 | + if (headers.empty()) { |
| 621 | + auto header_key = condition.empty() ? "headers" : (condition + ".headers"); |
| 622 | + throw std::runtime_error(target.name + " " + header_key + " wildcard found 0 files"); |
| 623 | + } |
| 624 | + cmd("list")("APPEND", headers_var, headers); |
| 625 | + }); |
| 626 | + } |
| 627 | + |
608 | 628 | bool added_toml = false; |
609 | 629 | cmd("set")(sources_var, RawArg("\"\"")).endl(); |
610 | 630 | 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) { |
682 | 702 | // clang-format on |
683 | 703 | } |
684 | 704 |
|
| 705 | + if (!target.headers.empty()) { |
| 706 | + cmd("source_group")("TREE", "${CMAKE_CURRENT_SOURCE_DIR}", "FILES", "${" + headers_var + "}").endl(); |
| 707 | + } |
| 708 | + |
685 | 709 | if (!target.sources.empty()) { |
686 | | - cmd("source_group")("TREE", "${CMAKE_CURRENT_SOURCE_DIR}", "FILES", "${" + target.name + "_SOURCES}").endl(); |
| 710 | + cmd("source_group")("TREE", "${CMAKE_CURRENT_SOURCE_DIR}", "FILES", "${" + sources_var + "}").endl(); |
687 | 711 | } |
688 | 712 |
|
689 | 713 | if (!target.alias.empty()) { |
|
0 commit comments