| 716 | } |
| 717 | |
| 718 | void generate_cmake(const char *path, const parser::Project *parent_project) { |
| 719 | if (!fs::exists(fs::path(path) / "cmake.toml")) { |
| 720 | throw std::runtime_error("No cmake.toml found!"); |
| 721 | } |
| 722 | |
| 723 | // Root project doesn't have a parent |
| 724 | auto is_root_project = parent_project == nullptr; |
| 725 | |
| 726 | parser::Project project(parent_project, path, false); |
| 727 | |
| 728 | tsl::ordered_set<std::string> flat_project_languages; |
| 729 | for (const auto &itr : project.project_languages) { |
| 730 | for (const auto &language : itr.second) { |
| 731 | flat_project_languages.insert(language); |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | // Reference: https://gitlab.kitware.com/cmake/cmake/-/issues/24340#note_1304703 |
| 736 | flat_project_languages.insert("RC"); |
| 737 | |
| 738 | // All acceptable extensions based off our given languages. |
| 739 | tsl::ordered_set<std::string> project_extensions; |
| 740 | for (const auto &language : flat_project_languages) { |
| 741 | auto itr = known_languages.find(language); |
| 742 | if (itr == known_languages.end()) { |
| 743 | if (project.project_allow_unknown_languages) { |
| 744 | printf("[warning] Unknown language '%s' specified\n", language.c_str()); |
| 745 | } else { |
| 746 | throw std::runtime_error("Unknown language '" + language + "' specified"); |
| 747 | } |
| 748 | } else { |
| 749 | project_extensions.insert(itr->second.begin(), itr->second.end()); |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | auto contains_language_source = [&project_extensions](const std::vector<std::string> &sources) { |
| 754 | for (const auto &source : sources) { |
| 755 | auto extension = fs::path(source).extension().string(); |
| 756 | if (project_extensions.count(extension) > 0) { |
| 757 | return true; |
| 758 | } |
| 759 | } |
| 760 | return false; |
| 761 | }; |
| 762 | |
| 763 | Generator gen(project, path); |
| 764 | |
| 765 | // Helper lambdas for more convenient CMake generation |
| 766 | auto &ss = gen.ss; |
| 767 | auto cmd = [&gen](const std::string &command) { |
| 768 | return gen.cmd(command); |
| 769 | }; |
| 770 | auto comment = [&gen](const std::string &comment) { |
| 771 | return gen.comment(comment); |
| 772 | }; |
| 773 | auto endl = [&gen]() { |
| 774 | gen.endl(); |
| 775 | }; |
no test coverage detected