@@ -26,22 +26,28 @@ void scan(fs::path src_path)
2626 ifstream in (src_path.string ());
2727
2828 string line;
29+
2930 regex usingcpp_pat{ R"( ^\s*#include\s+"([\w\./]+)\.h"\s+//\s+usingcpp)" };
3031 regex using_pat{ R"( using\s+([\w\./]+\.(cpp|cxx|c\+\+|cc|c)))" }; // | 或的顺序还挺重要,把长的排前边。免得前缀就匹配。
3132 regex linklib_pat{ R"( //\s+linklib\s+([\w\-\.]+))" };
33+
3234 string compiler_specific_linklib_string = R"( //\s+)" + cc_info[cc].compiler_name ;
3335 compiler_specific_linklib_string += R"( -linklib\s+([\w\-\.]+))" ;
3436 regex compiler_specific_linklib_pat{ compiler_specific_linklib_string };
3537
3638 // 下面这行,前后三个*号,不是正则的一部分,而是c++ raw-string的自定义delimiter
3739 // https://stackoverflow.com/questions/49416631/escape-r-in-a-raw-string-in-c
3840 regex precompile_pat{ R"***( ^\s*#include\s+"([\w\./]+\.(h|hpp|H|hh))"\s+//\s+precompile)***" };
39- string extra_compile_flags_string = R"( //\s+)" + cc_info[cc].compiler_name ;
40- extra_compile_flags_string += R"( -extra-compile-flags:\s+(.*)$)" ;
41- regex extra_compile_flags_pat{ extra_compile_flags_string };
42- string extra_link_flags_string = R"( //\s+)" + cc_info[cc].compiler_name ;
43- extra_link_flags_string += R"( -extra-link-flags:\s+(.*)$)" ;
44- regex extra_link_flags_pat{ extra_link_flags_string };
41+
42+ string compiler_specific_extra_compile_flags_string = R"( //\s+)" + cc_info[cc].compiler_name ;
43+ compiler_specific_extra_compile_flags_string += R"( -extra-compile-flags:\s+(.*)$)" ;
44+ regex compiler_specific_extra_compile_flags_pat{ compiler_specific_extra_compile_flags_string };
45+
46+ string compiler_specific_extra_link_flags_string = R"( //\s+)" + cc_info[cc].compiler_name ;
47+ compiler_specific_extra_link_flags_string += R"( -extra-link-flags:\s+(.*)$)" ;
48+ regex compiler_specific_extra_link_flags_pat{ compiler_specific_extra_link_flags_string };
49+
50+
4551 int n = 0 ;
4652 while (getline (in, line)) {
4753 smatch matches;
@@ -90,17 +96,18 @@ void scan(fs::path src_path)
9096 libs.push_back (matches[1 ]);
9197 }
9298
93- if (regex_search (line, matches, extra_compile_flags_pat)) {
94- MINILOG (collect_info_logger, " found extra compile flags: " << matches[1 ]);
95- extra_compile_flags += " " ;
96- extra_compile_flags += matches[1 ];
99+ if (regex_search (line, matches, compiler_specific_extra_compile_flags_pat)) {
100+ MINILOG (collect_info_logger, " found extra link flags: " << matches[1 ]);
101+ string flags = " " ;
102+ flags += matches[1 ];
103+ compiler_specific_extra_compile_flags[src_path] += flags;
97104 }
98105
99- if (regex_search (line, matches, extra_link_flags_pat )) {
100- MINILOG (collect_info_logger, " found extra link flags: " << matches[1 ]);
101- extra_link_flags += " " ;
102- extra_link_flags += matches[1 ];
103- }
106+ if (regex_search (line, matches, compiler_specific_extra_link_flags_pat )) {
107+ MINILOG (collect_info_logger, " found extra compile flags: " << matches[1 ]);
108+ compiler_specific_extra_link_flags += " " ;
109+ compiler_specific_extra_link_flags += matches[1 ];
110+ }
104111
105112 // 搜集需要预编译的头文件
106113 if (regex_search (line, matches, precompile_pat)) {
0 commit comments