Skip to content

Commit 92bc53f

Browse files
committed
fix bug
1 parent 2af75d0 commit 92bc53f

8 files changed

Lines changed: 45 additions & 31 deletions

File tree

src/GccCpp2ObjAction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ bool GccCpp2ObjAction::execute(const DepInfo& info)
3333
// birthcert_path += ".birthcert";
3434

3535
string cmd = compile_cpp_cmd;
36+
37+
cmd += compiler_specific_extra_compile_flags[cpp_path];
3638

3739
cmd += " ";
3840
cmd += compile_cmd_include_dirs;

src/GccObj2ExeAction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bool GccObj2ExeAction::execute(const DepInfo& info)
5151
cmd += link_cmd_libs;
5252

5353
// -l 选项的位置很重要,必须放在使用它的.o文件之后
54-
cmd += extra_link_flags;
54+
cmd += compiler_specific_extra_link_flags;
5555

5656
MINILOG(build_exe_summay_logger, "linking " << exe_path.filename().string());
5757
MINILOG(build_exe_detail_logger, cmd);

src/VcCpp2ObjAction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ bool VcCpp2ObjAction::execute(const DepInfo& info)
3838
string cmd = R"(")"; // cmd的怪癖,传给system函数的东西,前后还得一个引号。 参考: https://stackoverflow.com/questions/9964865/c-system-not-working-when-there-are-spaces-in-two-different-parameters
3939
cmd += compile_cpp_cmd;
4040

41+
cmd += compiler_specific_extra_compile_flags[cpp_path];
42+
4143
cmd += " ";
4244
cmd += compile_cmd_include_dirs;
4345

src/VcObj2ExeAction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ bool VcObj2ExeAction::execute(const DepInfo& info)
5757

5858
// -l 选项的位置很重要,必须放在使用它的.o文件之后
5959
cmd += " ";
60-
cmd += extra_link_flags;
60+
cmd += compiler_specific_extra_link_flags;
6161

6262

6363
cmd += R"(")"; // 传给system函数的东西最后额外的引号

src/global.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,8 @@ vector<fs::path> headers_to_pc; // 所有需要预编译的头文件的绝对路
6464
bool vc_use_pch = false; // vc是否使用预编译头文件。(目前只支持一个预编译头文件)
6565
fs::path vc_h_to_precompile; // vc需要预编译的头文件。等于headers_to_pc[0]
6666
fs::path vc_cpp_to_generate_pch; // vc用于产生预编译头文件的cpp文件
67-
string extra_compile_flags; // 源文件中指定的,编译时用的其他选项
68-
string extra_link_flags; // 源文件中指定的,链接时用的其他选项
67+
//string compiler_specific_extra_compile_flags; // 源文件中指定的,编译时用的其他选项
68+
map<fs::path, string> compiler_specific_extra_compile_flags; // 源文件中指定的,编译时用的其他选项。不同文件可能用不同的编译选项
69+
string compiler_specific_extra_link_flags; // 源文件中指定的,链接时用的其他选项
70+
71+

src/global.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ extern map<fs::path, fs::path> source2header_to_pc;
2626
extern bool vc_use_pch;
2727
extern fs::path vc_h_to_precompile;
2828
extern fs::path vc_cpp_to_generate_pch;
29-
extern string extra_compile_flags;
30-
extern string extra_link_flags;
29+
//extern string compiler_specific_extra_compile_flags;
30+
extern map<fs::path, string> compiler_specific_extra_compile_flags;
31+
extern string compiler_specific_extra_link_flags;
3132
extern string compiler_dir;
3233
extern string compile_cmd_include_dirs;
3334
extern string link_cmd_lib_dirs;

src/main.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,30 @@
44
int main(int argc, char* argv[])
55
try {
66

7-
// 解析命令行选项,读取配置文件
8-
parse(argc, argv);
7+
// 解析命令行选项,读取配置文件
8+
parse(argc, argv);
99

1010
// 扫描源文件,搜集信息
1111
collect();
1212
if (collect_only) return 0;
1313

14-
// todo: 额外的flags,是各个.cpp文件独立设置?还是?独立设置吧
15-
compile_cpp_cmd += extra_compile_flags;
16-
compile_h_cmd += extra_compile_flags;
17-
//gcc_link_cmd += extra_link_flags;
14+
// todo: 额外的flags,是各个.cpp文件独立设置?还是?独立设置吧
15+
//compile_cpp_cmd += compiler_specific_extra_compile_flags;
16+
//compile_h_cmd += compiler_specific_extra_compile_flags;
1817

1918
// 构建
2019
bool success = build();
21-
if (!success) return 0;
20+
if (!success) return 0;
2221
if (build_only) return 0;
2322

24-
// 运行
23+
// 运行
2524
run();
2625

2726
return 0;
2827
}
2928
catch (const po::error& ex) {
30-
std::cerr << ex.what() << '\n';
31-
return 1;
29+
std::cerr << ex.what() << '\n';
30+
return 1;
3231
}
3332
catch (int exit_code) {
3433
return exit_code;

src/scan.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)