diff --git a/README.chinese.md b/README.chinese.md index 5b98a7a..2067c2f 100755 --- a/README.chinese.md +++ b/README.chinese.md @@ -387,6 +387,24 @@ include-dir = F:\vcpkg\installed\x86-windows\include lib-dir = F:\vcpkg\installed\x86-windows\lib dll-dir = F:\vcpkg\installed\x86-windows\bin ``` +## 内嵌的Make +现实中的C++工程,源代码除了C++的.cpp跟.h外,还会涉及到其他一些类型的文件。 + +比如Qt的界面描述文件.ui,FLTK的界面描述文件.fl。 +这些文件经过编译之后,会产生.cpp或.h文件。 +除此之外,Qt著名的moc还会从.h生成.cpp。 +对于这类千变万化的东西,cpps提供了嵌入式的make脚本。 +```c++ +#include "finddialog.h" // usingcpp +// using nocheck finddialog.h.moc.cpp +/* cpps-make +finddialog.h.moc.cpp : finddialog.h + moc finddialog.h -o finddialog.h.moc.cpp +*/ +``` +`using`指令后的`nocheck`告诉cpps,这个叫finddialog.h.moc.cpp的文件是build阶段生成出来的,即便扫描阶段不存在,也不要报错。 + +`cpps-make`指令引入一条用户自定义规则,语法同Makefile,当然,不会有普通Makefile那么完备。具体请参考examples里fltk跟qt的例子。 ## 其他 QQ交流群:492455203 diff --git a/examples/hello-qt-moc/main.cpp b/examples/hello-qt-moc/main.cpp index abddeba..3c73381 100644 --- a/examples/hello-qt-moc/main.cpp +++ b/examples/hello-qt-moc/main.cpp @@ -6,6 +6,7 @@ // using nocheck finddialog.h.moc.cpp // cpps-make finddialog.h.moc.cpp : finddialog.h // moc finddialog.h -o finddialog.h.moc.cpp +// 上面这是单行make。只支持一条命令。命令写在//之后 int main(int argc, char *argv[]) { diff --git a/examples/hello-qt-uic/main.cpp b/examples/hello-qt-uic/main.cpp index 4a776a1..3768082 100644 --- a/examples/hello-qt-uic/main.cpp +++ b/examples/hello-qt-uic/main.cpp @@ -1,16 +1,18 @@ #include #include -#include "gotocelldialog.h" - -// cpps-make ui_gotocelldialog.h : gotocelldialog.ui // uic gotocelldialog.ui -o gotocelldialog.h +#include "ui_gotocelldialog.h" // vc-extra-compile-flags: -IF:\vcpkg\installed\x86-windows\include\QtWidgets /* cpps-make ui_gotocelldialog.h : gotocelldialog.ui uic gotocelldialog.ui -o gotocelldialog.h + del ui_gotocelldialog.h > NUL 2>&1 + ren gotocelldialog.h ui_gotocelldialog.h */ +// ǶmakeӸҪôӣõmakeɡֻΪ˾ٸӡ//֮Ǹ-Ϊ˱cpps䵱ָ +//- cpps-make ui_gotocelldialog.h : gotocelldialog.ui // uic gotocelldialog.ui -o ui_gotocelldialog.h int main(int argc, char *argv[]) { diff --git a/examples/hello-qt-uic/gotocelldialog.h b/examples/hello-qt-uic/ui_gotocelldialog.h similarity index 100% rename from examples/hello-qt-uic/gotocelldialog.h rename to examples/hello-qt-uic/ui_gotocelldialog.h diff --git a/src/UserDefinedRule.cpp b/src/UserDefinedRule.cpp index f1c57b8..657516c 100644 --- a/src/UserDefinedRule.cpp +++ b/src/UserDefinedRule.cpp @@ -69,3 +69,53 @@ void process_user_defined_rule(fs::path src_path, string rule_string, InfoPackag } +void process_user_defined_rule_multi_lines(fs::path src_path, string dependency_relationship, + vector commands, InfoPackageScanned& pack) +{ + // 分离dependency relationship中的targets与prerequisites + auto colon_pos = dependency_relationship.find(":"); + string targets = dependency_relationship.substr(0, colon_pos); + boost::algorithm::trim(targets); + string prerequisites = dependency_relationship.substr(colon_pos + 1); + boost::algorithm::trim(prerequisites); + //cout << targets << endl; + //cout << prerequisites << endl; + + // 分离dependency relationship中的各个target + vector target_vector; + std::string target_delimiters(" "); // 支持多个分界符 + boost::split(target_vector, targets, boost::is_any_of(target_delimiters), boost::token_compress_on); // token_compress_on是为了将单词之间的多个空格视为一个 + //for (auto t : target_vector) { + // cout << ">>>" << t << "<<<" << endl; + //} + + // 分离prerequisites中的各个prerequisite + vector prerequisite_vector; + std::string prerequisite_delimiters(" "); // 支持多个分界符 + boost::split(prerequisite_vector, prerequisites, boost::is_any_of(prerequisite_delimiters), boost::token_compress_on); // token_compress_on是为了将单词之间的多个空格视为一个 + //for (auto p : prerequisite_vector) { + // cout << ">>>" << p << "<<<" << endl; + //} + + UserDefinedRule rule; + rule.dir = src_path; + rule.dir.remove_filename(); + + for (auto t : target_vector) { + fs::path a = rule.dir; + a /= t; + rule.targets.push_back(a); + } + + for (auto p : prerequisite_vector) { + fs::path a = rule.dir; + a /= p; + rule.prerequisites.push_back(a); + } + + + rule.commands = commands; + + pack.user_defined_rules.push_back(rule); + +} \ No newline at end of file diff --git a/src/UserDefinedRule.h b/src/UserDefinedRule.h index 6e58051..d6c6493 100644 --- a/src/UserDefinedRule.h +++ b/src/UserDefinedRule.h @@ -23,5 +23,7 @@ struct UserDefinedRule { }; void process_user_defined_rule(fs::path src_path, string rule, InfoPackageScanned& pack); +void process_user_defined_rule_multi_lines(fs::path src_path, string dependency_relationship, + vector commands, InfoPackageScanned& pack); #endif // USERDEFINEDRULE_H diff --git a/src/scan.cpp b/src/scan.cpp index 8ab39ae..4c30bee 100644 --- a/src/scan.cpp +++ b/src/scan.cpp @@ -81,7 +81,8 @@ void scan(fs::path src_path, InfoPackageScanned& pack) // cpps-before-link shell命令 在链接之前执行的操作 // cpps-after-link shell命令 在链接之后执行的操作 - regex user_defined_rule_pat{ R"(//\scpps-make\s+(.+\w))" }; + regex user_defined_rule_pat{ R"(//\scpps-make\s+(.+\w))" }; // 单行 + regex user_defined_rule_multi_lines_pat{R"(/\* cpps-make)"}; int n = 0; while (getline(in, line)) { @@ -186,7 +187,23 @@ void scan(fs::path src_path, InfoPackageScanned& pack) process_user_defined_rule(src_path, matches[1], pack); } + else if (regex_search(line, matches, user_defined_rule_multi_lines_pat)) { + //cout << matches[1] << endl; + string dependency_relationship; + getline(in, dependency_relationship); + + vector commands; + string c; + getline(in, c); + boost::algorithm::trim(c); + while (c != "*/") { + commands.push_back(c); + getline(in, c); + boost::algorithm::trim(c); + } + process_user_defined_rule_multi_lines(src_path, dependency_relationship, commands, pack); + } if (max_line_scan != -1) { n++;