| 1 | #include "compilerinfo.h" |
| 2 | #include <QObject> |
| 3 | |
| 4 | CompilerInfo::CompilerInfo(const QString &name): |
| 5 | mName(name) |
| 6 | { |
| 7 | init(); |
| 8 | } |
| 9 | |
| 10 | const QList<PCompilerOption> &CompilerInfo::compilerOptions() const |
| 11 | { |
| 12 | return mCompilerOptionList; |
| 13 | } |
| 14 | |
| 15 | const QString &CompilerInfo::name() const |
| 16 | { |
| 17 | return mName; |
| 18 | } |
| 19 | |
| 20 | PCompilerOption CompilerInfo::getCompilerOption(const QString &key) const |
| 21 | { |
| 22 | return mCompilerOptions.value(key,PCompilerOption()); |
| 23 | } |
| 24 | |
| 25 | bool CompilerInfo::hasCompilerOption(const QString &key) const |
| 26 | { |
| 27 | return mCompilerOptions.contains(key); |
| 28 | } |
| 29 | |
| 30 | void CompilerInfo::addOption(const QString &key, const QString &name, const QString section, bool isC, bool isCpp, bool isLinker, const QString &setting, const CompileOptionChoiceList &choices) |
| 31 | { |
| 32 | PCompilerOption pOption = std::make_shared<CompilerOption>(); |
| 33 | pOption->key = key; |
| 34 | pOption->name = name; |
| 35 | pOption->section = section; |
| 36 | pOption->isC = isC; |
| 37 | pOption->isCpp = isCpp; |
| 38 | pOption->isLinker = isLinker; |
| 39 | pOption->setting= setting; |
| 40 | pOption->choices = choices; |
| 41 | mCompilerOptions.insert(key,pOption); |
| 42 | mCompilerOptionList.append(pOption); |
| 43 | } |
| 44 | |
| 45 | void CompilerInfo::init() |
| 46 | { |
| 47 | prepareCompilerOptions(); |
| 48 | } |
| 49 | |
| 50 | void CompilerInfo::prepareCompilerOptions() |
| 51 | { |
| 52 | QList<QPair<QString,QString>> sl; |
| 53 | // C options |
| 54 | QString groupName = QObject::tr("C options" ); |
| 55 | addOption(CC_CMD_OPT_ANSI, QObject::tr("Support all ANSI standard C programs (-ansi)" ), groupName, true, true, false, "-ansi" ); |
| 56 | addOption(CC_CMD_OPT_NO_ASM, QObject::tr("Do not recognize asm,inline or typeof as a keyword (-fno-asm)" ), groupName, true, true, false, "-fno-asm" ); |
| 57 | addOption(CC_CMD_OPT_TRADITIONAL_CPP, QObject::tr("Imitate traditional C preprocessors (-traditional-cpp)" ), groupName, true, true, false, "-traditional-cpp" ); |
| 58 | |
| 59 | groupName = QObject::tr("Code Generation" ); |
| 60 | addOption(CC_CMD_OPT_DEBUG_INFO, QObject::tr("Generate debugging information (-g3)" ), groupName, true, true, false, "-g3" ); |
| 61 | // Optimization |
| 62 | sl.clear(); |
| 63 | sl.append(QPair<QString,QString>("Low" ,"1" )); |
| 64 | sl.append(QPair<QString,QString>("Med" ,"2" )); |
| 65 | sl.append(QPair<QString,QString>("High" ,"3" )); |
| 66 | sl.append(QPair<QString,QString>("Highest (fast)" ,"fast" )); |
| 67 | sl.append(QPair<QString,QString>("Size (s)" ,"s" )); |
| 68 | sl.append(QPair<QString,QString>("Debug (g)" ,"g" )); |
| 69 | addOption(CC_CMD_OPT_OPTIMIZE, QObject::tr("Optimization level (-Ox)" ), groupName, true, true, false, "-O" , sl); |
| 70 | |
| 71 | // Language Standards |
| 72 | sl.clear(); |
| 73 | sl.append(QPair<QString,QString>("ISO C90" ,"c90" )); |
| 74 | sl.append(QPair<QString,QString>("ISO C99" ,"c99" )); |
| 75 | sl.append(QPair<QString,QString>("ISO C11" ,"c11" )); |
| 76 | sl.append(QPair<QString,QString>("ISO C17" ,"c17" )); |
| 77 | sl.append(QPair<QString,QString>("ISO C++" ,"c++98" )); |
| 78 | sl.append(QPair<QString,QString>("ISO C++11" ,"c++11" )); |
| 79 | sl.append(QPair<QString,QString>("ISO C++14" ,"c++14" )); |
| 80 | sl.append(QPair<QString,QString>("ISO C++17" ,"c++17" )); |
| 81 | sl.append(QPair<QString,QString>("ISO C++20" ,"c++2a" )); |
| 82 | sl.append(QPair<QString,QString>("GNU C90" ,"gnu90" )); |
| 83 | sl.append(QPair<QString,QString>("GNU C99" ,"gnu99" )); |
| 84 | sl.append(QPair<QString,QString>("GNU C11" ,"gnu11" )); |
| 85 | sl.append(QPair<QString,QString>("GNU C17" ,"gnu17" )); |
| 86 | sl.append(QPair<QString,QString>("GNU C++" ,"gnu++98" )); |
| 87 | sl.append(QPair<QString,QString>("GNU C++11" ,"gnu++11" )); |
| 88 | sl.append(QPair<QString,QString>("GNU C++14" ,"gnu++14" )); |
| 89 | sl.append(QPair<QString,QString>("GNU C++17" ,"gnu++17" )); |
| 90 | sl.append(QPair<QString,QString>("GNU C++20" ,"gnu++2a" )); |
| 91 | addOption(CC_CMD_OPT_STD, QObject::tr("Language standard (-std)" ), groupName, true, true, false, "-std=" , sl); |
| 92 | |
| 93 | // Optimization for cpu type |
| 94 | sl.clear(); |
| 95 | sl.append(QPair<QString,QString>(QObject::tr("This CPU" ),"native" )); |
| 96 | sl.append(QPair<QString,QString>("i386" ,"i386" )); |
| 97 | sl.append(QPair<QString,QString>("i486" ,"i486" )); |
| 98 | sl.append(QPair<QString,QString>("i586" ,"i586" )); |
| 99 | sl.append(QPair<QString,QString>("i686" ,"i686" )); |
| 100 | sl.append(QPair<QString,QString>("Pentium" ,"pentium" )); |
| 101 | sl.append(QPair<QString,QString>("Pentium MMX" ,"pentium-mmx" )); |
| 102 | sl.append(QPair<QString,QString>("Pentium Pro" ,"pentiumpro" )); |
| 103 | sl.append(QPair<QString,QString>("Pentium 2" ,"pentium2" )); |
| 104 | sl.append(QPair<QString,QString>("Pentium 3" ,"pentium3" )); |
| 105 | sl.append(QPair<QString,QString>("Pentium 4" ,"pentium4" )); |
| 106 | sl.append(QPair<QString,QString>("Conroe" ,"core2" )); |
| 107 | sl.append(QPair<QString,QString>("Nehalem" ,"corei7" )); |
| 108 | sl.append(QPair<QString,QString>("Sandy" ,"corei7-avx" )); |
| 109 | sl.append(QPair<QString,QString>("K6" ,"k6" )); |
| 110 | sl.append(QPair<QString,QString>("K6-2" ,"k6-2" )); |
| 111 | sl.append(QPair<QString,QString>("K6-3" ,"k6-3" )); |
| 112 | sl.append(QPair<QString,QString>("Athlon" ,"athlon" )); |
| 113 | sl.append(QPair<QString,QString>("Athlon Tbird" ,"athlon-tbird" )); |
| 114 | sl.append(QPair<QString,QString>("Athlon 4" ,"athlon-4" )); |
| 115 | sl.append(QPair<QString,QString>("Athlon XP" ,"athlon-xp" )); |
| 116 | sl.append(QPair<QString,QString>("Athlon MP" ,"athlon-mp" )); |
| 117 | sl.append(QPair<QString,QString>("K8" ,"k8" )); |
| 118 | sl.append(QPair<QString,QString>("K8 Rev.E" ,"k8-sse3" )); |
| 119 | sl.append(QPair<QString,QString>("K10" ,"barcelona" )); |
| 120 | sl.append(QPair<QString,QString>("Bulldozer" ,"bdver1" )); |
| 121 | addOption(CC_CMD_OPT_ARCH, QObject::tr("Optimize for the following machine (-march)" ), groupName, true, true, false, "-march=" , sl); |
| 122 | addOption(CC_CMD_OPT_TUNE, QObject::tr("Optimize less, while maintaining full compatibility (-tune)" ), groupName, true, true, false, "-mtune=" , sl); |
| 123 | |
| 124 | // Enable use of the specific instructions |
| 125 | sl.clear(); |
| 126 | sl.append(QPair<QString,QString>("MMX" ,"mmx" )); |
| 127 | sl.append(QPair<QString,QString>("3D Now" ,"3dnow" )); |
| 128 | sl.append(QPair<QString,QString>("SSE" ,"sse" )); |
| 129 | sl.append(QPair<QString,QString>("SSE2" ,"sse2" )); |
| 130 | sl.append(QPair<QString,QString>("SSE3" ,"sse3" )); |
| 131 | sl.append(QPair<QString,QString>("SSSE3" ,"ssse3" )); |
| 132 | sl.append(QPair<QString,QString>("SSE4" ,"sse4" )); |
| 133 | sl.append(QPair<QString,QString>("SSE4A" ,"sse4a" )); |
| 134 | sl.append(QPair<QString,QString>("SSE4.1" ,"sse4.1" )); |
| 135 | sl.append(QPair<QString,QString>("SSE4.2" ,"sse4.2" )); |
| 136 | sl.append(QPair<QString,QString>("AVX" ,"avx" )); |
| 137 | sl.append(QPair<QString,QString>("AVX2" ,"avx2" )); |
| 138 | sl.append(QPair<QString,QString>("FMA4" ,"fma4" )); |
| 139 | sl.append(QPair<QString,QString>("XOP" ,"xop" )); |
| 140 | sl.append(QPair<QString,QString>("AES" ,"aes" )); |
| 141 | addOption(CC_CMD_OPT_INSTRUCTION,QObject::tr("Enable use of specific instructions (-mx)" ), groupName, true, true, false, "-m" , sl); |
| 142 | |
| 143 | // 32bit/64bit |
| 144 | sl.clear(); |
| 145 | sl.append(QPair<QString,QString>("32bit" ,"32" )); |
| 146 | sl.append(QPair<QString,QString>("64bit" ,"64" )); |
| 147 | addOption(CC_CMD_OPT_POINTER_SIZE, QObject::tr("Compile with the following pointer size (-mx)" ), groupName, true, true, true, "-m" , sl); |
| 148 | |
| 149 | addOption(CC_CMD_OPT_PROFILE_INFO, QObject::tr("Generate profiling info for analysis (-pg)" ), groupName, true, true, true, "-pg" ); |
| 150 | |
| 151 | // Warnings |
| 152 | groupName = QObject::tr("Warnings" ); |
| 153 | addOption(CC_CMD_OPT_INHIBIT_ALL_WARNING, QObject::tr("Inhibit all warning messages (-w)" ), groupName, true, true, false, "-w" ); |
| 154 | addOption(CC_CMD_OPT_WARNING_ALL,QObject::tr("Show most warnings (-Wall)" ), groupName, true, true, false, "-Wall" ); |
| 155 | addOption(CC_CMD_OPT_WARNING_EXTRA,QObject::tr("Show some more warnings (-Wextra)" ), groupName, true, true, false, "-Wextra" ); |
| 156 | addOption(CC_CMD_OPT_CHECK_ISO_CONFORMANCE, QObject::tr("Check ISO C/C++/C++0x conformance (-pedantic)" ), groupName, true, true, false, "-pedantic" ); |
| 157 | addOption(CC_CMD_OPT_SYNTAX_ONLY, QObject::tr("Only check the code for syntax errors (-fsyntax-only)" ), groupName, true, true, false, "-fsyntax-only" ); |
| 158 | addOption(CC_CMD_OPT_WARNING_AS_ERROR, QObject::tr("Make all warnings into errors (-Werror)" ), groupName, true, true, false, "-Werror" ); |
| 159 | addOption(CC_CMD_OPT_ABORT_ON_ERROR , QObject::tr("Abort compilation on first error (-Wfatal-errors)" ), groupName, true, true, false, "-Wfatal-errors" ); |
| 160 | |
| 161 | |
| 162 | // Output |
| 163 | groupName = QObject::tr("Output" ); |
| 164 | addOption(CC_CMD_OPT_VERBOSE_ASM, QObject::tr("Put comments in generated assembly code (-fverbose-asm)" ), groupName, true, true, false, "-fverbose-asm" ); |
| 165 | addOption(CC_CMD_OPT_ONLY_GEN_ASM_CODE, QObject::tr("Do not assemble, compile and generate the assemble code (-S)" ), groupName, true, true, false, "-S" ); |
| 166 | addOption(CC_CMD_OPT_STOP_AFTER_PREPROCESSING, QObject::tr("Do not compile, stop after the preprocessing stage (-E)" ), groupName, true, true, false, "-E" ); |
| 167 | addOption(CC_CMD_OPT_USE_PIPE, QObject::tr("Use pipes instead of temporary files during compilation (-pipe)" ), groupName, true, true, false, "-pipe" ); |
| 168 | |
| 169 | // Linker |
| 170 | groupName = QObject::tr("Linker" ); |
| 171 | addOption(LINK_CMD_OPT_LINK_OBJC, QObject::tr("Link an Objective C program (-lobjc)" ), groupName, false, false, true, "-lobjc" ); |
| 172 | addOption(LINK_CMD_OPT_NO_LINK_STDLIB,QObject::tr("Do not use standard system libraries (-nostdlib)" ), groupName, false, false, true, "-nostdlib" ); |
| 173 | addOption(LINK_CMD_OPT_NO_CONSOLE, QObject::tr("Do not create a console window (-mwindows)" ), groupName,false, false, true, "-mwindows" ); |
| 174 | addOption(LINK_CMD_OPT_STRIP_EXE, QObject::tr("Strip executable (-s)" ), groupName, false, false, true, "-s" ); |
| 175 | } |
| 176 | |
| 177 | CompilerInfoManager::CompilerInfoManager() |
| 178 | { |
| 179 | mInfos.insert(COMPILER_CLANG, std::make_shared<ClangCompilerInfo>()); |
| 180 | mInfos.insert(COMPILER_GCC, std::make_shared<GCCCompilerInfo>()); |
| 181 | } |
| 182 | |
| 183 | PCompilerInfo CompilerInfoManager::getInfo(const QString &compilerType) |
| 184 | { |
| 185 | return getInstance()->mInfos.value(compilerType,PCompilerInfo()); |
| 186 | } |
| 187 | |
| 188 | bool CompilerInfoManager::hasCompilerOption(const QString &compilerType, const QString &optKey) |
| 189 | { |
| 190 | PCompilerInfo pInfo = getInfo(compilerType); |
| 191 | if (!pInfo) |
| 192 | return false; |
| 193 | return pInfo->hasCompilerOption(optKey); |
| 194 | } |
| 195 | |
| 196 | PCompilerOption CompilerInfoManager::getCompilerOption(const QString &compilerType, const QString &optKey) |
| 197 | { |
| 198 | PCompilerInfo pInfo = getInfo(compilerType); |
| 199 | if (!pInfo) |
| 200 | return PCompilerOption(); |
| 201 | return pInfo->getCompilerOption(optKey); |
| 202 | } |
| 203 | |
| 204 | QList<PCompilerOption> CompilerInfoManager::getCompilerOptions(const QString &compilerType) |
| 205 | { |
| 206 | PCompilerInfo pInfo = getInfo(compilerType); |
| 207 | if (!pInfo) |
| 208 | return QList<PCompilerOption>(); |
| 209 | return pInfo->compilerOptions(); |
| 210 | } |
| 211 | |
| 212 | bool CompilerInfoManager::supportCovertingCharset(const QString &compilerType) |
| 213 | { |
| 214 | PCompilerInfo pInfo = getInfo(compilerType); |
| 215 | if (!pInfo) |
| 216 | return false; |
| 217 | return pInfo->supportConvertingCharset(); |
| 218 | } |
| 219 | |
| 220 | bool CompilerInfoManager::forceUTF8InDebugger(const QString &compilerType) |
| 221 | { |
| 222 | PCompilerInfo pInfo = getInfo(compilerType); |
| 223 | if (!pInfo) |
| 224 | return false; |
| 225 | return pInfo->forceUTF8InDebugger(); |
| 226 | } |
| 227 | |
| 228 | PCompilerInfoManager CompilerInfoManager::instance; |
| 229 | |
| 230 | PCompilerInfoManager CompilerInfoManager::getInstance() |
| 231 | { |
| 232 | if (!instance) { |
| 233 | instance = std::make_shared<CompilerInfoManager>(); |
| 234 | } |
| 235 | return instance; |
| 236 | } |
| 237 | |
| 238 | void CompilerInfoManager::addInfo(const QString &name, PCompilerInfo info) |
| 239 | { |
| 240 | getInstance()->mInfos.insert(name,info); |
| 241 | } |
| 242 | |
| 243 | ClangCompilerInfo::ClangCompilerInfo():CompilerInfo(COMPILER_CLANG) |
| 244 | { |
| 245 | } |
| 246 | |
| 247 | bool ClangCompilerInfo::supportConvertingCharset() |
| 248 | { |
| 249 | return false; |
| 250 | } |
| 251 | |
| 252 | bool ClangCompilerInfo::forceUTF8InDebugger() |
| 253 | { |
| 254 | return true; |
| 255 | } |
| 256 | |
| 257 | GCCCompilerInfo::GCCCompilerInfo():CompilerInfo(COMPILER_GCC) |
| 258 | { |
| 259 | } |
| 260 | |
| 261 | bool GCCCompilerInfo::supportConvertingCharset() |
| 262 | { |
| 263 | return true; |
| 264 | } |
| 265 | |
| 266 | bool GCCCompilerInfo::forceUTF8InDebugger() |
| 267 | { |
| 268 | return false; |
| 269 | } |
| 270 | |
| 271 | GCCUTF8CompilerInfo::GCCUTF8CompilerInfo():CompilerInfo(COMPILER_GCC_UTF8) |
| 272 | { |
| 273 | } |
| 274 | |
| 275 | bool GCCUTF8CompilerInfo::supportConvertingCharset() |
| 276 | { |
| 277 | return true; |
| 278 | } |
| 279 | |
| 280 | bool GCCUTF8CompilerInfo::forceUTF8InDebugger() |
| 281 | { |
| 282 | return true; |
| 283 | } |
| 284 | |