OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "tools/gn/visual_studio_utils.h" |
| 6 |
| 7 #include "base/md5.h" |
| 8 #include "base/strings/string_util.h" |
| 9 |
| 10 CompilerOptions::CompilerOptions() = default; |
| 11 |
| 12 CompilerOptions::~CompilerOptions() = default; |
| 13 |
| 14 std::string MakeGuid(const std::string& entry_path, const std::string& seed) { |
| 15 std::string str = base::ToUpperASCII(base::MD5String(seed + entry_path)); |
| 16 return '{' + str.substr(0, 8) + '-' + str.substr(8, 4) + '-' + |
| 17 str.substr(12, 4) + '-' + str.substr(16, 4) + '-' + |
| 18 str.substr(20, 12) + '}'; |
| 19 } |
| 20 |
| 21 #define SetOption(condition, member, value) \ |
| 22 if (condition) { \ |
| 23 options->member = value; \ |
| 24 return; \ |
| 25 } |
| 26 |
| 27 #define AppendOption(condition, member, value, separator) \ |
| 28 if (condition) { \ |
| 29 options->member += value + separator; \ |
| 30 return; \ |
| 31 } |
| 32 |
| 33 void ParseCompilerOption(const std::string& cflag, CompilerOptions* options) { |
| 34 if (cflag.size() > 2 && cflag[0] == '/') { |
| 35 switch (cflag[1]) { |
| 36 case 'F': |
| 37 AppendOption(cflag.size() > 3 && cflag[2] == 'I', forced_include_files, |
| 38 cflag.substr(3), ';') |
| 39 break; |
| 40 |
| 41 case 'G': |
| 42 if (cflag[2] == 'S') { |
| 43 SetOption(cflag.size() == 3, buffer_security_check, "true") |
| 44 SetOption(cflag.size() == 4 && cflag[3] == '-', |
| 45 buffer_security_check, "false") |
| 46 } |
| 47 break; |
| 48 |
| 49 case 'M': |
| 50 switch (cflag[2]) { |
| 51 case 'D': |
| 52 SetOption(cflag.size() == 3, runtime_library, "MultiThreadedDLL") |
| 53 SetOption(cflag.size() == 4 && cflag[3] == 'd', runtime_library, |
| 54 "MultiThreadedDebugDLL") |
| 55 break; |
| 56 |
| 57 case 'T': |
| 58 SetOption(cflag.size() == 3, runtime_library, "MultiThreaded") |
| 59 SetOption(cflag.size() == 4 && cflag[3] == 'd', runtime_library, |
| 60 "MultiThreadedDebug") |
| 61 break; |
| 62 } |
| 63 break; |
| 64 |
| 65 case 'O': |
| 66 switch (cflag[2]) { |
| 67 case '1': |
| 68 SetOption(cflag.size() == 3, optimization, "MinSpace") |
| 69 break; |
| 70 |
| 71 case '2': |
| 72 SetOption(cflag.size() == 3, optimization, "MaxSpeed") |
| 73 break; |
| 74 |
| 75 case 'd': |
| 76 SetOption(cflag.size() == 3, optimization, "Disabled") |
| 77 break; |
| 78 |
| 79 case 'x': |
| 80 SetOption(cflag.size() == 3, optimization, "Full") |
| 81 break; |
| 82 } |
| 83 break; |
| 84 |
| 85 case 'T': |
| 86 // Skip flags that cause treating all source files as C and C++ files. |
| 87 if (cflag.size() == 3 && (cflag[2] == 'C' || cflag[2] == 'P')) |
| 88 return; |
| 89 break; |
| 90 |
| 91 case 'W': |
| 92 switch (cflag[2]) { |
| 93 case '0': |
| 94 case '1': |
| 95 case '2': |
| 96 case '3': |
| 97 case '4': |
| 98 SetOption(cflag.size() == 3, warning_level, |
| 99 std::string("Level") + cflag[2]) |
| 100 break; |
| 101 |
| 102 case 'X': |
| 103 SetOption(cflag.size() == 3, treat_warning_as_error, "true") |
| 104 break; |
| 105 } |
| 106 break; |
| 107 |
| 108 case 'w': |
| 109 AppendOption(cflag.size() > 3 && cflag[2] == 'd', |
| 110 disable_specific_warnings, cflag.substr(3), ';') |
| 111 break; |
| 112 } |
| 113 } |
| 114 |
| 115 // Put everything else into additional_options. |
| 116 options->additional_options += cflag + ' '; |
| 117 } |
OLD | NEW |