1#ifndef COMPILERINFO_H
2#define COMPILERINFO_H
3
4#include <QString>
5#include <QMap>
6#include <memory>
7#include <QMutex>
8#define COMPILER_CLANG "Clang"
9#define COMPILER_GCC "GCC"
10#define COMPILER_GCC_UTF8 "GCC_UTF8"
11
12#define CC_CMD_OPT_ANSI "cc_cmd_opt_ansi"
13#define CC_CMD_OPT_NO_ASM "cc_cmd_opt_no_asm"
14#define CC_CMD_OPT_TRADITIONAL_CPP "cc_cmd_opt_traditional_cpp"
15
16#define CC_CMD_OPT_ARCH "cc_cmd_opt_arch"
17#define CC_CMD_OPT_TUNE "cc_cmd_opt_tune"
18#define CC_CMD_OPT_INSTRUCTION "cc_cmd_opt_instruction"
19#define CC_CMD_OPT_OPTIMIZE "cc_cmd_opt_optimize"
20#define CC_CMD_OPT_POINTER_SIZE "cc_cmd_opt_pointer_size"
21#define CC_CMD_OPT_STD "cc_cmd_opt_std"
22
23#define CC_CMD_OPT_INHIBIT_ALL_WARNING "cc_cmd_opt_inhibit_all_warning"
24#define CC_CMD_OPT_WARNING_ALL "cc_cmd_opt_warning_all"
25#define CC_CMD_OPT_WARNING_EXTRA "cc_cmd_opt_warning_extra"
26#define CC_CMD_OPT_CHECK_ISO_CONFORMANCE "cc_cmd_opt_check_iso_conformance"
27#define CC_CMD_OPT_SYNTAX_ONLY "cc_cmd_opt_syntax_only"
28#define CC_CMD_OPT_WARNING_AS_ERROR "cc_cmd_opt_warning_as_error"
29#define CC_CMD_OPT_ABORT_ON_ERROR "cc_cmd_opt_abort_on_error"
30
31#define CC_CMD_OPT_PROFILE_INFO "cc_cmd_opt_profile_info"
32
33#define LINK_CMD_OPT_LINK_OBJC "link_cmd_opt_link_objc"
34#define LINK_CMD_OPT_NO_LINK_STDLIB "link_cmd_opt_no_link_stdlib"
35#define LINK_CMD_OPT_NO_CONSOLE "link_cmd_opt_no_console"
36#define LINK_CMD_OPT_STRIP_EXE "link_cmd_opt_strip_exe"
37#define CC_CMD_OPT_DEBUG_INFO "cc_cmd_opt_debug_info"
38
39#define CC_CMD_OPT_VERBOSE_ASM "cc_cmd_opt_verbose_asm"
40#define CC_CMD_OPT_ONLY_GEN_ASM_CODE "cc_cmd_opt_only_gen_asm_code"
41#define CC_CMD_OPT_STOP_AFTER_PREPROCESSING "cc_cmd_opt_stop_after_preprocessing"
42#define CC_CMD_OPT_USE_PIPE "cc_cmd_opt_use_pipe"
43
44#define COMPILER_OPTION_ON "on"
45
46using CompileOptionChoiceList = QList<QPair<QString,QString>>;
47
48typedef struct {
49 QString key;
50 QString name; // "Generate debugging info"
51 QString section; // "C options"
52 bool isC;
53 bool isCpp; // True (C++ option?) - can be both C and C++ option...
54 bool isLinker; // Is it a linker param
55 QString setting; // "-g3"
56 CompileOptionChoiceList choices; // replaces "Yes/No" standard choices (max 30 different choices)
57} CompilerOption;
58
59using PCompilerOption = std::shared_ptr<CompilerOption>;
60
61using CompilerOptionMap=QMap<QString,PCompilerOption>;
62
63class CompilerInfo
64{
65public:
66 CompilerInfo(const QString& name);
67 const QList<PCompilerOption> &compilerOptions() const;
68 const QString &name() const;
69 PCompilerOption getCompilerOption(const QString& key) const;
70 bool hasCompilerOption(const QString& key) const;
71
72 virtual bool supportConvertingCharset()=0;
73 virtual bool forceUTF8InDebugger()=0;
74protected:
75 void addOption(const QString& key,
76 const QString& name,
77 const QString section,
78 bool isC,
79 bool isCpp,
80 bool isLinker,
81 const QString& setting,
82 const CompileOptionChoiceList& choices = CompileOptionChoiceList());
83 void init();
84 virtual void prepareCompilerOptions();
85protected:
86 CompilerOptionMap mCompilerOptions;
87 QList<PCompilerOption> mCompilerOptionList;
88 QString mName;
89};
90
91using PCompilerInfo = std::shared_ptr<CompilerInfo>;
92
93class CompilerInfoManager;
94using PCompilerInfoManager = std::shared_ptr<CompilerInfoManager>;
95
96class CompilerInfoManager {
97public:
98 CompilerInfoManager();
99 static PCompilerInfo getInfo(const QString& compilerType);
100 static bool hasCompilerOption(const QString& compilerType, const QString& optKey);
101 static PCompilerOption getCompilerOption(const QString& compilerType, const QString& optKey);
102 static QList<PCompilerOption> getCompilerOptions(const QString& compilerType);
103 static bool supportCovertingCharset(const QString& compilerType);
104 static bool forceUTF8InDebugger(const QString& compilerType);
105 static PCompilerInfoManager getInstance();
106 static void addInfo(const QString& name, PCompilerInfo info);
107private:
108 static PCompilerInfoManager instance;
109 QMap<QString,PCompilerInfo> mInfos;
110};
111
112class ClangCompilerInfo: public CompilerInfo{
113public:
114 ClangCompilerInfo();
115 bool supportConvertingCharset() override;
116 bool forceUTF8InDebugger() override;
117};
118
119class GCCCompilerInfo: public CompilerInfo{
120public:
121 GCCCompilerInfo();
122 bool supportConvertingCharset() override;
123 bool forceUTF8InDebugger() override;
124};
125
126class GCCUTF8CompilerInfo: public CompilerInfo{
127public:
128 GCCUTF8CompilerInfo();
129 bool supportConvertingCharset() override;
130 bool forceUTF8InDebugger() override;
131};
132
133
134
135#endif // COMPILERINFO_H
136