From 58b7c55cd6167f9215dd4676b942f91e3d805f2b Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 13 May 2022 20:22:16 +0800 Subject: [PATCH] work save --- RedPandaIDE/RedPandaIDE.pro | 69 +++--- RedPandaIDE/compiler/compiler.cpp | 6 +- RedPandaIDE/compiler/compilerinfo.cpp | 234 ++++++++++++++++++ RedPandaIDE/compiler/compilerinfo.h | 130 ++++++++++ RedPandaIDE/project.cpp | 97 +++++--- RedPandaIDE/project.h | 3 +- RedPandaIDE/projectoptions.cpp | 2 +- RedPandaIDE/settings.cpp | 178 ++----------- RedPandaIDE/settings.h | 67 +---- .../settingsdialog/compilersetoptionwidget.ui | 2 +- .../widgets/compileargumentswidget.cpp | 113 +++++++++ RedPandaIDE/widgets/compileargumentswidget.h | 29 +++ RedPandaIDE/widgets/compileargumentswidget.ui | 35 +++ 13 files changed, 665 insertions(+), 300 deletions(-) create mode 100644 RedPandaIDE/compiler/compilerinfo.cpp create mode 100644 RedPandaIDE/compiler/compilerinfo.h create mode 100644 RedPandaIDE/widgets/compileargumentswidget.cpp create mode 100644 RedPandaIDE/widgets/compileargumentswidget.h create mode 100644 RedPandaIDE/widgets/compileargumentswidget.ui diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 7234b330..088125ea 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -46,6 +46,7 @@ SOURCES += \ codeformatter.cpp \ codesnippetsmanager.cpp \ colorscheme.cpp \ + compiler/compilerinfo.cpp \ compiler/ojproblemcasesrunner.cpp \ compiler/projectcompiler.cpp \ compiler/runner.cpp \ @@ -157,6 +158,7 @@ SOURCES += \ systemconsts.cpp \ utils.cpp \ widgets/coloredit.cpp \ + widgets/compileargumentswidget.cpp \ widgets/consolewidget.cpp \ widgets/customdisablediconengine.cpp \ widgets/customfilesystemmodel.cpp \ @@ -194,6 +196,7 @@ HEADERS += \ codesnippetsmanager.h \ colorscheme.h \ compiler/compiler.h \ + compiler/compilerinfo.h \ compiler/compilermanager.h \ compiler/executablerunner.h \ compiler/filecompiler.h \ @@ -304,6 +307,7 @@ HEADERS += \ utils.h \ common.h \ widgets/coloredit.h \ + widgets/compileargumentswidget.h \ widgets/consolewidget.h \ widgets/customdisablediconengine.h \ widgets/customfilesystemmodel.h \ @@ -381,6 +385,7 @@ FORMS += \ settingsdialog/executorgeneralwidget.ui \ settingsdialog/settingsdialog.ui \ widgets/custommakefileinfodialog.ui \ + widgets/compileargumentswidget.ui \ widgets/filepropertiesdialog.ui \ widgets/infomessagebox.ui \ widgets/newclassdialog.ui \ @@ -393,13 +398,13 @@ FORMS += \ win32: { FORMS += \ - settingsdialog/projectversioninfowidget.ui \ + settingsdialog/projectversioninfowidget.ui \ settingsdialog/environmentfileassociationwidget.ui HEADERS += \ settingsdialog/projectversioninfowidget.h \ - settingsdialog/environmentfileassociationwidget.h - + settingsdialog/environmentfileassociationwidget.h + SOURCES += \ settingsdialog/environmentfileassociationwidget.cpp \ settingsdialog/projectversioninfowidget.cpp @@ -451,40 +456,40 @@ RESOURCES += \ RC_ICONS = images/devcpp.ico images/associations/c.ico images/associations/cpp.ico images/associations/dev.ico images/associations/c.ico images/associations/cpp.ico images/associations/h.ico images/associations/hpp.ico # fixed lrelease.prf -qtPrepareTool(QMAKE_LRELEASE, lrelease) +#qtPrepareTool(QMAKE_LRELEASE, lrelease) -isEmpty(LRELEASE_DIR): LRELEASE_DIR = .qm -isEmpty(QM_FILES_RESOURCE_PREFIX): QM_FILES_RESOURCE_PREFIX = i18n +#isEmpty(LRELEASE_DIR): LRELEASE_DIR = .qm +#isEmpty(QM_FILES_RESOURCE_PREFIX): QM_FILES_RESOURCE_PREFIX = i18n -lrelease.name = lrelease -lrelease.input = TRANSLATIONS EXTRA_TRANSLATIONS -lrelease.output = $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm -lrelease.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} $$QMAKE_LRELEASE_FLAGS -qm ${QMAKE_FILE_OUT} -silent: lrelease.commands = @echo lrelease ${QMAKE_FILE_IN} && $$lrelease.commands -lrelease.CONFIG = no_link target_predeps -QMAKE_EXTRA_COMPILERS += lrelease +#lrelease.name = lrelease +#lrelease.input = TRANSLATIONS EXTRA_TRANSLATIONS +#lrelease.output = $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm +#lrelease.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} $$QMAKE_LRELEASE_FLAGS -qm ${QMAKE_FILE_OUT} +#silent: lrelease.commands = @echo lrelease ${QMAKE_FILE_IN} && $$lrelease.commands +#lrelease.CONFIG = no_link target_predeps +#QMAKE_EXTRA_COMPILERS += lrelease -all_translations = $$TRANSLATIONS $$EXTRA_TRANSLATIONS -for (translation, all_translations) { - # mirrors $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm above - translation = $$basename(translation) - QM_FILES += $$OUT_PWD/$$LRELEASE_DIR/$$replace(translation, \\..*$, .qm) -} +#all_translations = $$TRANSLATIONS $$EXTRA_TRANSLATIONS +#for (translation, all_translations) { +# # mirrors $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm above +# translation = $$basename(translation) +# QM_FILES += $$OUT_PWD/$$LRELEASE_DIR/$$replace(translation, \\..*$, .qm) +#} -qmake_qm_files.files = $$QM_FILES -qmake_qm_files.base = $$OUT_PWD/$$LRELEASE_DIR -qmake_qm_files.prefix = $$QM_FILES_RESOURCE_PREFIX +#qmake_qm_files.files = $$QM_FILES +#qmake_qm_files.base = $$OUT_PWD/$$LRELEASE_DIR +#qmake_qm_files.prefix = $$QM_FILES_RESOURCE_PREFIX -iconsets_files.files += $$files(resources/iconsets/*.svg, true) -iconsets_files.files += $$files(resources/iconsets/*.json, true) +#iconsets_files.files += $$files(resources/iconsets/*.svg, true) +#iconsets_files.files += $$files(resources/iconsets/*.json, true) -theme_files.files += $$files(themes/*.json, false) -theme_files.files += $$files(themes/*.png, false) +#theme_files.files += $$files(themes/*.json, false) +#theme_files.files += $$files(themes/*.png, false) -colorscheme_files.files += $$files(colorschemes/*.scheme, false) -colorscheme_files.prefix = /colorschemes +#colorscheme_files.files += $$files(colorschemes/*.scheme, false) +#colorscheme_files.prefix = /colorschemes -RESOURCES += qmake_qm_files -RESOURCES += iconsets_files -RESOURCES += theme_files -RESOURCES += colorscheme_files +#RESOURCES += qmake_qm_files +#RESOURCES += iconsets_files +#RESOURCES += theme_files +#RESOURCES += colorscheme_files diff --git a/RedPandaIDE/compiler/compiler.cpp b/RedPandaIDE/compiler/compiler.cpp index 18d387b2..0d0d49c5 100644 --- a/RedPandaIDE/compiler/compiler.cpp +++ b/RedPandaIDE/compiler/compiler.cpp @@ -347,7 +347,7 @@ QString Compiler::getCCompileArguments(bool checkSyntax) compileOptions = compilerSet()->compileOptions(); } foreach (const QString& key, compilerSet()->compileOptions()) { - PCompilerOption pOption = pSettings->compilerSets().getCompilerOption(key); + PCompilerOption pOption = CompilerInfoManager::getCompilerOption(compilerSet()->CCompiler(), key); if (pOption && pOption->isC && !pOption->isLinker) { result += " " + pOption->setting + compilerSet()->getCompileOptionValue(key); } @@ -380,7 +380,7 @@ QString Compiler::getCppCompileArguments(bool checkSyntax) compileOptions = compilerSet()->compileOptions(); } foreach (const QString& key, compilerSet()->compileOptions()) { - PCompilerOption pOption = pSettings->compilerSets().getCompilerOption(key); + PCompilerOption pOption = CompilerInfoManager::getCompilerOption(compilerSet()->CCompiler(), key); if (pOption && pOption->isCpp && !pOption->isLinker) { result += " " + pOption->setting + compilerSet()->getCompileOptionValue(key); } @@ -484,7 +484,7 @@ QString Compiler::getLibraryArguments(FileType fileType) compileOptions = compilerSet()->compileOptions(); } foreach (const QString& key, compilerSet()->compileOptions()) { - PCompilerOption pOption = pSettings->compilerSets().getCompilerOption(key); + PCompilerOption pOption = CompilerInfoManager::getCompilerOption(compilerSet()->CCompiler(), key); if (pOption->isLinker) { result += " " + pOption->setting + compilerSet()->getCompileOptionValue(key); } diff --git a/RedPandaIDE/compiler/compilerinfo.cpp b/RedPandaIDE/compiler/compilerinfo.cpp new file mode 100644 index 00000000..5fb0d524 --- /dev/null +++ b/RedPandaIDE/compiler/compilerinfo.cpp @@ -0,0 +1,234 @@ +#include "compilerinfo.h" +#include + +CompilerInfo::CompilerInfo(const QString &name): + mName(name) +{ + prepareCompilerOptions(); +} + +const CompilerOptionMap &CompilerInfo::compilerOptions() const +{ + return mCompilerOptions; +} + +const QString &CompilerInfo::name() const +{ + return mName; +} + +PCompilerOption CompilerInfo::getCompilerOption(const QString &key) const +{ + return mCompilerOptions.value(key,PCompilerOption()); +} + +void CompilerInfo::addOption(const QString &key, const QString &name, const QString section, bool isC, bool isCpp, bool isLinker, const QString &setting, const CompileOptionChoiceList &choices) +{ + PCompilerOption pOption = std::make_shared(); + pOption->key = key; + pOption->name = name; + pOption->section = section; + pOption->isC = isC; + pOption->isCpp = isCpp; + pOption->isLinker = isLinker; + pOption->setting= setting; + pOption->choices = choices; + mCompilerOptions.insert(key,pOption); +} + +void CompilerInfo::prepareCompilerOptions() +{ + // C options + QString groupName = QObject::tr("C options"); + addOption(CC_CMD_OPT_ANSI, QObject::tr("Support all ANSI standard C programs (-ansi)"), groupName, true, true, false, "-ansi"); + 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"); + addOption(CC_CMD_OPT_TRADITIONAL_CPP, QObject::tr("Imitate traditional C preprocessors (-traditional-cpp)"), groupName, true, true, false, "-traditional-cpp"); + + // Optimization for cpu type + groupName = QObject::tr("Code Generation"); + QList> sl; + sl.append(QPair(QObject::tr("This CPU"),"native")); + sl.append(QPair("i386","i386")); + sl.append(QPair("i486","i486")); + sl.append(QPair("i586","i586")); + sl.append(QPair("i686","i686")); + sl.append(QPair("Pentium","pentium")); + sl.append(QPair("Pentium MMX","pentium-mmx")); + sl.append(QPair("Pentium Pro","pentiumpro")); + sl.append(QPair("Pentium 2","pentium2")); + sl.append(QPair("Pentium 3","pentium3")); + sl.append(QPair("Pentium 4","pentium4")); + sl.append(QPair("Conroe","core2")); + sl.append(QPair("Nehalem","corei7")); + sl.append(QPair("Sandy","corei7-avx")); + sl.append(QPair("K6","k6")); + sl.append(QPair("K6-2","k6-2")); + sl.append(QPair("K6-3","k6-3")); + sl.append(QPair("Athlon","athlon")); + sl.append(QPair("Athlon Tbird","athlon-tbird")); + sl.append(QPair("Athlon 4","athlon-4")); + sl.append(QPair("Athlon XP","athlon-xp")); + sl.append(QPair("Athlon MP","athlon-mp")); + sl.append(QPair("K8","k8")); + sl.append(QPair("K8 Rev.E","k8-sse3")); + sl.append(QPair("K10","barcelona")); + sl.append(QPair("Bulldozer","bdver1")); + addOption("gcc_cmd_opt_arch", QObject::tr("Optimize for the following machine (-march)"), groupName, true, true, false, "-march=", sl); + addOption("gcc_cmd_opt_tune", QObject::tr("Optimize less, while maintaining full compatibility (-tune)"), groupName, true, true, false, "-mtune=", sl); + + // Enable use of the specific instructions + sl.clear(); + sl.append(QPair("MMX","mmx")); + sl.append(QPair("3D Now","3dnow")); + sl.append(QPair("SSE","sse")); + sl.append(QPair("SSE2","sse2")); + sl.append(QPair("SSE3","sse3")); + sl.append(QPair("SSSE3","ssse3")); + sl.append(QPair("SSE4","sse4")); + sl.append(QPair("SSE4A","sse4a")); + sl.append(QPair("SSE4.1","sse4.1")); + sl.append(QPair("SSE4.2","sse4.2")); + sl.append(QPair("AVX","avx")); + sl.append(QPair("AVX2","avx2")); + sl.append(QPair("FMA4","fma4")); + sl.append(QPair("XOP","xop")); + sl.append(QPair("AES","aes")); + addOption("gcc_cmd_opt_instruction",QObject::tr("Enable use of specific instructions (-mx)"), groupName, true, true, false, "-m", sl); + + // Optimization + sl.clear(); + sl.append(QPair("Low","1")); + sl.append(QPair("Med","2")); + sl.append(QPair("High","3")); + sl.append(QPair("Highest (fast)","fast")); + sl.append(QPair("Size (s)","s")); + sl.append(QPair("Debug (g)","g")); + addOption("gcc_cmd_opt_optimize", QObject::tr("Optimization level (-Ox)"), groupName, true, true, false, "-O", sl); + + // 32bit/64bit + sl.clear(); + sl.append(QPair("32bit","32")); + sl.append(QPair("64bit","64")); + addOption("gcc_cmd_opt_pointer_size", QObject::tr("Compile with the following pointer size (-mx)"), groupName, true, true, true, "-m", sl); + + // Language Standards + sl.clear(); + sl.append(QPair("ISO C90","c90")); + sl.append(QPair("ISO C99","c99")); + sl.append(QPair("ISO C11","c11")); + sl.append(QPair("ISO C17","c17")); + sl.append(QPair("ISO C++","c++98")); + sl.append(QPair("ISO C++11","c++11")); + sl.append(QPair("ISO C++14","c++14")); + sl.append(QPair("ISO C++17","c++17")); + sl.append(QPair("ISO C++20","c++2a")); + sl.append(QPair("GNU C90","gnu90")); + sl.append(QPair("GNU C99","gnu99")); + sl.append(QPair("GNU C11","gnu11")); + sl.append(QPair("GNU C17","gnu17")); + sl.append(QPair("GNU C++","gnu++98")); + sl.append(QPair("GNU C++11","gnu++11")); + sl.append(QPair("GNU C++14","gnu++14")); + sl.append(QPair("GNU C++17","gnu++17")); + sl.append(QPair("GNU C++20","gnu++2a")); + addOption("gcc_cmd_opt_std", QObject::tr("Language standard (-std)"), groupName, true, true, false, "-std=", sl); + + // Warnings + groupName = QObject::tr("Warnings"); + addOption("gcc_cmd_opt_inhibit_all_warning", QObject::tr("Inhibit all warning messages (-w)"), groupName, true, true, false, "-w"); + addOption("gcc_cmd_opt_warning_all",QObject::tr("Show most warnings (-Wall)"), groupName, true, true, false, "-Wall"); + addOption("gcc_cmd_opt_warning_extra",QObject::tr("Show some more warnings (-Wextra)"), groupName, true, true, false, "-Wextra"); + addOption("gcc_cmd_opt_check_iso_conformance", QObject::tr("Check ISO C/C++/C++0x conformance (-pedantic)"), groupName, true, true, false, "-pedantic"); + addOption("gcc_cmd_opt_syntax_only", QObject::tr("Only check the code for syntax errors (-fsyntax-only)"), groupName, true, true, false, "-fsyntax-only"); + addOption("gcc_cmd_opt_warning_as_error", QObject::tr("Make all warnings into errors (-Werror)"), groupName, true, true, false, "-Werror"); + addOption("gcc_cmd_opt_abort_on_error", QObject::tr("Abort compilation on first error (-Wfatal-errors)"), groupName, true, true, false, "-Wfatal-errors"); + + // Profile + groupName = QObject::tr("Profile"); + addOption("gcc_cmd_opt_profile_info",QObject::tr("Generate profiling info for analysis (-pg)"), groupName, true, true, true, "-pg"); + + // Linker + groupName = QObject::tr("Linker"); + addOption("linker_cmd_opt_link_objc", QObject::tr("Link an Objective C program (-lobjc)"), groupName, false, false, true, "-lobjc"); + addOption("linker_cmd_opt_no_link_stdlib",QObject::tr("Do not use standard system libraries (-nostdlib)"), groupName, false, false, true, "-nostdlib"); + addOption("linker_cmd_opt_no_console", QObject::tr("Do not create a console window (-mwindows)"), groupName,false, false, true, "-mwindows"); + addOption("linker_cmd_opt_strip_exe", QObject::tr("Strip executable (-s)"), groupName, false, false, true, "-s"); + addOption("cc_cmd_opt_debug_info", QObject::tr("Generate debugging information (-g3)"), groupName, true, true, false, "-g3"); + + // Output + groupName = QObject::tr("Output"); + addOption("cc_cmd_opt_verbose_asm", QObject::tr("Put comments in generated assembly code (-fverbose-asm)"), groupName, true, true, false, "-fverbose-asm"); + 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"); + addOption("cc_cmd_opt_use_pipe", QObject::tr("Use pipes instead of temporary files during compilation (-pipe)"), groupName, true, true, false, "-pipe"); + +} + +PCompilerInfo CompilerInfoManager::getInfo(const QString &compilerType) +{ + return getInstance()->mInfos.value(compilerType,PCompilerInfo()); +} + +bool CompilerInfoManager::hasCompilerOption(const QString &compilerType, const QString &optKey) +{ + PCompilerInfo pInfo = getInfo(compilerType); + if (!pInfo) + return false; + return pInfo->compilerOptions().contains(optKey); +} + +PCompilerOption CompilerInfoManager::getCompilerOption(const QString &compilerType, const QString &optKey) +{ + PCompilerInfo pInfo = getInfo(compilerType); + if (!pInfo) + return PCompilerOption(); + return pInfo->compilerOptions().value(optKey,PCompilerOption()); +} + +CompilerOptionMap CompilerInfoManager::getCompilerOptions(const QString &compilerType) +{ + PCompilerInfo pInfo = getInfo(compilerType); + if (!pInfo) + return CompilerOptionMap(); + return pInfo->compilerOptions(); +} + +bool CompilerInfoManager::supportCovertingCharset(const QString &compilerType) +{ + PCompilerInfo pInfo = getInfo(compilerType); + if (!pInfo) + return false; + return pInfo->supportConvertingCharset(); +} + +PCompilerInfoManager CompilerInfoManager::getInstance() +{ + if (!instance) { + instance = std::make_shared(); + } + return instance; +} + +void CompilerInfoManager::addInfo(const QString &name, PCompilerInfo info) +{ + getInstance()->mInfos.insert(name,info); +} + +ClangCompilerInfo::ClangCompilerInfo():CompilerInfo(COMPILER_CLANG) +{ + +} + +bool ClangCompilerInfo::supportConvertingCharset() +{ + return false; +} + +GCCCompilerInfo::GCCCompilerInfo():CompilerInfo(COMPILER_GCC) +{ + +} + +bool GCCCompilerInfo::supportConvertingCharset() +{ + return true; +} diff --git a/RedPandaIDE/compiler/compilerinfo.h b/RedPandaIDE/compiler/compilerinfo.h new file mode 100644 index 00000000..ec9366ef --- /dev/null +++ b/RedPandaIDE/compiler/compilerinfo.h @@ -0,0 +1,130 @@ +#ifndef COMPILERINFO_H +#define COMPILERINFO_H + +#include +#include +#include +#include +#define COMPILER_CLANG "Clang" +#define COMPILER_GCC "GCC" + +#define CC_CMD_OPT_ANSI "cc_cmd_opt_ansi" +#define CC_CMD_OPT_NO_ASM "cc_cmd_opt_no_asm" +#define CC_CMD_OPT_TRADITIONAL_CPP "cc_cmd_opt_traditional_cpp" + +#define CC_CMD_OPT_ARCH "cc_cmd_opt_arch" +#define CC_CMD_OPT_TUNE "cc_cmd_opt_tune" +#define CC_CMD_OPT_INSTRUCTION "cc_cmd_opt_instruction" +#define CC_CMD_OPT_OPTIMIZE "cc_cmd_opt_optimize" +#define CC_CMD_OPT_POINTER_SIZE "cc_cmd_opt_pointer_size" +#define CC_CMD_OPT_STD "cc_cmd_opt_std" + +#define CC_CMD_OPT_INHIBIT_ALL_WARNING "cc_cmd_opt_inhibit_all_warning" +#define CC_CMD_OPT_WARNING_ALL "cc_cmd_opt_warning_all" +#define CC_CMD_OPT_WARNING_EXTRA "cc_cmd_opt_warning_extra" +#define CC_CMD_OPT_CHECK_ISO_CONFORMANCE "cc_cmd_opt_check_iso_conformance" +#define CC_CMD_OPT_SYNTAX_ONLY "cc_cmd_opt_syntax_only" +#define CC_CMD_OPT_WARNING_AS_ERROR "cc_cmd_opt_warning_as_error" +#define CC_CMD_OPT_ABORT_ON_ERROR "cc_cmd_opt_abort_on_error" + +#define CC_CMD_OPT_PROFILE_INFO "cc_cmd_opt_profile_info" + +#define LINK_CMD_OPT_LINK_OBJC "link_cmd_opt_link_objc" +#define LINK_CMD_OPT_NO_LINK_STDLIB "link_cmd_opt_no_link_stdlib" +#define LINK_CMD_OPT_NO_CONSOLE "link_cmd_opt_no_console" +#define LINK_CMD_OPT_STRIP_EXE "link_cmd_opt_strip_exe" +#define CC_CMD_OPT_DEBUG_INFO "cc_cmd_opt_debug_info" + +#define CC_CMD_OPT_VERBOSE_ASM "cc_cmd_opt_verbose_asm" +#define CC_CMD_OPT_ONLY_GEN_ASM_CODE "cc_cmd_opt_only_gen_asm_code" +#define CC_CMD_OPT_USE_PIPE "cc_cmd_opt_use_pipe" + +#define COMPILER_OPTION_ON "on" + +using CompileOptionChoiceList = QList>; + +typedef struct { + QString key; + QString name; // "Generate debugging info" + QString section; // "C options" + bool isC; + bool isCpp; // True (C++ option?) - can be both C and C++ option... + bool isLinker; // Is it a linker param + QString setting; // "-g3" + CompileOptionChoiceList choices; // replaces "Yes/No" standard choices (max 30 different choices) +} CompilerOption; + +using PCompilerOption = std::shared_ptr; + +using CompilerOptionMap=QMap>; + +class CompilerInfo +{ +public: + CompilerInfo(const QString& name); + const CompilerOptionMap &compilerOptions() const; + const QString &name() const; + PCompilerOption getCompilerOption(const QString& key) const; + + virtual bool supportConvertingCharset()=0; +protected: + void addOption(const QString& key, + const QString& name, + const QString section, + bool isC, + bool isCpp, + bool isLinker, + const QString& setting, + const CompileOptionChoiceList& choices = CompileOptionChoiceList()); + + virtual void prepareCompilerOptions(); +protected: + CompilerOptionMap mCompilerOptions; + QString mName; +}; + +using PCompilerInfo = std::shared_ptr; + +class CompilerInfoManager; +using PCompilerInfoManager = std::shared_ptr; + +class CompilerInfoManager { +public: + static PCompilerInfo getInfo(const QString& compilerType); + static bool hasCompilerOption(const QString& compilerType, const QString& optKey); + static PCompilerOption getCompilerOption(const QString& compilerType, const QString& optKey); + static CompilerOptionMap getCompilerOptions(const QString& compilerType); + static bool supportCovertingCharset(const QString& compilerType); + static PCompilerInfoManager getInstance(); + static void addInfo(const QString& name, PCompilerInfo info); +private: + CompilerInfoManager(); + static PCompilerInfoManager instance; + QMap mInfos; +}; + +extern PCompilerInfoManager pCompilerInfoManager; + +class ClangCompilerInfo: public CompilerInfo{ +public: + ClangCompilerInfo(); + + // CompilerInfo interface +protected: + void prepareCompilerOptions() Q_DECL_OVERRIDE; + bool supportConvertingCharset() Q_DECL_OVERRIDE; +}; + +class GCCCompilerInfo: public CompilerInfo{ +public: + GCCCompilerInfo(); + + // CompilerInfo interface +protected: + void prepareCompilerOptions() Q_DECL_OVERRIDE; + bool supportConvertingCharset() Q_DECL_OVERRIDE; +}; + + + +#endif // COMPILERINFO_H diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 3c7bd1c9..5fc9876c 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -689,19 +689,37 @@ void Project::associateEditorToUnit(Editor *editor, PProjectUnit unit) } } -bool Project::setCompileOption(const QString &key, int valIndex) -{ - PCompilerOption op = pSettings->compilerSets().getCompilerOption(key); - if (op && valIndex>=0 && valIndex < op->choices.length()) { - mOptions.compilerOptions.insert(key,op->choices[valIndex].second); - return true; - } - return false; -} +//bool Project::setCompileOption(const QString &key, int valIndex) +//{ +// Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(mOptions.compilerSet); +// if (!pSet) +// return false; +// PCompilerOption op = CompilerInfoManager::getCompilerOption( +// pSet->compilerType(), key); +// if (!op) +// return false; +// if (op->choices.isEmpty()) { +// if (valIndex>0) +// mOptions.compilerOptions.insert(key,COMPILER_OPTION_ON); +// else +// mOptions.compilerOptions.insert(key,""); +// } else { +// if (valIndex>0 && valIndex <= op->choices.length()) { +// mOptions.compilerOptions.insert(key,op->choices[valIndex-1].second); +// } else { +// mOptions.compilerOptions.insert(key,""); +// } +// } +// return true; +//} bool Project::setCompileOption(const QString &key, const QString &value) { - PCompilerOption op = pSettings->compilerSets().getCompilerOption(key); + Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(mOptions.compilerSet); + if (!pSet) + return false; + PCompilerOption op = CompilerInfoManager::getCompilerOption( + pSet->compilerType(), key); if (!op) return false; mOptions.compilerOptions.insert(key,value); @@ -1533,8 +1551,8 @@ void Project::loadOptions(SimpleIni& ini) } mOptions.version = ini.GetLongValue("Project", "Ver", 0); if (mOptions.version > 0) { // ver > 0 is at least a v5 project - if (mOptions.version < 2) { - mOptions.version = 2; + if (mOptions.version < 3) { + mOptions.version = 3; QMessageBox::information(nullptr, tr("Settings need update"), tr("The compiler settings format of Red Panda C++ has changed.") @@ -1585,32 +1603,39 @@ void Project::loadOptions(SimpleIni& ini) setCompilerSet(pSettings->compilerSets().defaultIndex()); } - QByteArray oldCompilerOptions = ini.GetValue("Project", "CompilerSettings", ""); - if (!oldCompilerOptions.isEmpty()) { - for (int i=0;icompilerSets().getKeyFromCompilerCompatibleIndex(i); - PCompilerOption pOption = pSettings->compilerSets().getCompilerOption(key); - if (pOption) { - int val = Settings::CompilerSet::charToValue(oldCompilerOptions[i]); - if (pOption->choices.isEmpty()) { - if (val>0) - mOptions.compilerOptions.insert(key,""); - } else { - if (val>0 && val <= pOption->choices.length()) - mOptions.compilerOptions.insert(key,pOption->choices[val-1].second); + Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(mOptions.compilerSet); + if (pSet) { + QByteArray oldCompilerOptions = ini.GetValue("Project", "CompilerSettings", ""); + if (!oldCompilerOptions.isEmpty()) { + //version 2 compatibility + for (int i=0;icompilerSets().getKeyFromCompilerCompatibleIndex(i); + PCompilerOption pOption = CompilerInfoManager::getCompilerOption( + pSet->compilerType(), key); + if (pOption) { + int val = Settings::CompilerSet::charToValue(oldCompilerOptions[i]); + if (pOption->choices.isEmpty()) { + if (val>0) + mOptions.compilerOptions.insert(key,COMPILER_OPTION_ON); + else + mOptions.compilerOptions.insert(key,""); + } else { + if (val>0 && val <= pOption->choices.length()) + mOptions.compilerOptions.insert(key,pOption->choices[val-1].second); + else + mOptions.compilerOptions.insert(key,""); + } } } - } - } else { - SimpleIni::TNamesDepend oKeys; - ini.GetAllKeys("CompilerSettings", oKeys); - for(const SimpleIni::Entry& entry:oKeys) { - QString key(entry.pItem); - PCompilerOption pOption = pSettings->compilerSets().getCompilerOption(key); - if (pOption) { + } else { + //version 3 + SimpleIni::TNamesDepend oKeys; + ini.GetAllKeys("CompilerSettings", oKeys); + for(const SimpleIni::Entry& entry:oKeys) { + QString key(entry.pItem); mOptions.compilerOptions.insert( - key, - ini.GetValue("CompilerSettings", entry.pItem, "")); + key, + ini.GetValue("CompilerSettings", entry.pItem, "")); } } } @@ -1649,7 +1674,7 @@ void Project::loadOptions(SimpleIni& ini) mOptions.versionInfo.syncProduct = ini.GetBoolValue("VersionInfo", "SyncProduct", false); } else { // dev-c < 4 - mOptions.version = 2; + mOptions.version = 3; if (!ini.GetBoolValue("VersionInfo", "NoConsole", true)) mOptions.type = ProjectType::Console; else if (ini.GetBoolValue("VersionInfo", "IsDLL", false)) diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index 44949751..1ef7b1d0 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -210,8 +210,7 @@ public: PProjectUnit findUnitByFilename(const QString& filename); void associateEditor(Editor* editor); void associateEditorToUnit(Editor* editor, PProjectUnit unit); - void setCompilerOption(const QString& optionString, char value); - bool setCompileOption(const QString &key, int valIndex); +// bool setCompileOption(const QString &key, int valIndex); bool setCompileOption(const QString &key, const QString &value); void updateFolders(); diff --git a/RedPandaIDE/projectoptions.cpp b/RedPandaIDE/projectoptions.cpp index 67eeac8a..0dd6a5a0 100644 --- a/RedPandaIDE/projectoptions.cpp +++ b/RedPandaIDE/projectoptions.cpp @@ -40,7 +40,7 @@ ProjectVersionInfo::ProjectVersionInfo() ProjectOptions::ProjectOptions() { type = ProjectType::GUI; - version = 2; + version = 3; isCpp = false; logOutputEnabled = false; useCustomMakefile = false; diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index b086ac0a..574822cf 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -1494,15 +1494,20 @@ Settings::CompilerSet::CompilerSet(const Settings::CompilerSet &set): bool Settings::CompilerSet::setCompileOption(const QString &key, int valIndex) { - PCompilerOption op = pSettings->compilerSets().getCompilerOption(key); + PCompilerOption op = CompilerInfoManager::getCompilerOption(mCompilerType, key); if (!op) return false; if (op->choices.isEmpty()) { if (valIndex==1) - mCompileOptions.insert(key,""); + mCompileOptions.insert(key,COMPILER_OPTION_ON); + else + mCompileOptions.remove(key); return true; } else if (valIndex>0 && valIndex <= op->choices.length()) { - mCompileOptions.insert(key,op->choices[valIndex].second); + mCompileOptions.insert(key,op->choices[valIndex-1].second); + return true; + } else { + mCompileOptions.remove(key); return true; } return false; @@ -1510,7 +1515,7 @@ bool Settings::CompilerSet::setCompileOption(const QString &key, int valIndex) bool Settings::CompilerSet::setCompileOption(const QString &key, const QString &value) { - PCompilerOption op = pSettings->compilerSets().getCompilerOption(key); + PCompilerOption op = CompilerInfoManager::getCompilerOption(mCompilerType,key); if (!op) return false; mCompileOptions.insert(key,value); @@ -2306,7 +2311,7 @@ Settings::CompilerSets::CompilerSets(Settings *settings): mDefaultIndex(-1), mSettings(settings) { - initOptions(); + prepareCompatibleIndex(); } Settings::PCompilerSet Settings::CompilerSets::addSet(const Settings::CompilerSet& set) @@ -2329,16 +2334,16 @@ static void set64_32Options(Settings::PCompilerSet pSet) { static void setReleaseOptions(Settings::PCompilerSet pSet) { pSet->setCompileOption(CC_CMD_OPT_OPTIMIZE,"2"); - pSet->setCompileOption(LINK_CMD_OPT_STRIP_EXE,""); - pSet->setCompileOption(CC_CMD_OPT_USE_PIPE, ""); + pSet->setCompileOption(LINK_CMD_OPT_STRIP_EXE, COMPILER_OPTION_ON); + pSet->setCompileOption(CC_CMD_OPT_USE_PIPE, COMPILER_OPTION_ON); pSet->setStaticLink(true); } static void setDebugOptions(Settings::PCompilerSet pSet) { - pSet->setCompileOption(CC_CMD_OPT_DEBUG_INFO,""); - pSet->setCompileOption(CC_CMD_OPT_WARNING_ALL,""); - pSet->setCompileOption(CC_CMD_OPT_WARNING_EXTRA,""); - pSet->setCompileOption(CC_CMD_OPT_USE_PIPE,""); + pSet->setCompileOption(CC_CMD_OPT_DEBUG_INFO, COMPILER_OPTION_ON); + pSet->setCompileOption(CC_CMD_OPT_WARNING_ALL, COMPILER_OPTION_ON); + pSet->setCompileOption(CC_CMD_OPT_WARNING_EXTRA, COMPILER_OPTION_ON); + pSet->setCompileOption(CC_CMD_OPT_USE_PIPE, COMPILER_OPTION_ON); #ifdef Q_OS_LINUX pSet->setCustomCompileParams("-fsanitize=address"); @@ -2722,7 +2727,7 @@ Settings::PCompilerSet Settings::CompilerSets::loadSet(int index) pSet->setIniOptions(iniOptions); else { foreach (const QString &optionKey, mSettings->mSettings.allKeys()) { - if (mCompilerOptions.contains(optionKey)) { + if (CompilerInfoManager::hasCompilerOption(pSet->compilerType(),optionKey)) { pSet->setCompileOption(optionKey, mSettings->mSettings.value(optionKey).toString()); } } @@ -2764,131 +2769,8 @@ Settings::PCompilerSet Settings::CompilerSets::loadSet(int index) return pSet; } -void Settings::CompilerSets::initOptions() +void Settings::CompilerSets::prepareCompatibleIndex() { - // C options - QString groupName = QObject::tr("C options"); - addOption(CC_CMD_OPT_ANSI, QObject::tr("Support all ANSI standard C programs (-ansi)"), groupName, true, true, false, "-ansi"); - 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"); - addOption(CC_CMD_OPT_TRADITIONAL_CPP, QObject::tr("Imitate traditional C preprocessors (-traditional-cpp)"), groupName, true, true, false, "-traditional-cpp"); - - // Optimization for cpu type - groupName = QObject::tr("Code Generation"); - QList> sl; - sl.append(QPair(QObject::tr("This CPU"),"native")); - sl.append(QPair("i386","i386")); - sl.append(QPair("i486","i486")); - sl.append(QPair("i586","i586")); - sl.append(QPair("i686","i686")); - sl.append(QPair("Pentium","pentium")); - sl.append(QPair("Pentium MMX","pentium-mmx")); - sl.append(QPair("Pentium Pro","pentiumpro")); - sl.append(QPair("Pentium 2","pentium2")); - sl.append(QPair("Pentium 3","pentium3")); - sl.append(QPair("Pentium 4","pentium4")); - sl.append(QPair("Conroe","core2")); - sl.append(QPair("Nehalem","corei7")); - sl.append(QPair("Sandy","corei7-avx")); - sl.append(QPair("K6","k6")); - sl.append(QPair("K6-2","k6-2")); - sl.append(QPair("K6-3","k6-3")); - sl.append(QPair("Athlon","athlon")); - sl.append(QPair("Athlon Tbird","athlon-tbird")); - sl.append(QPair("Athlon 4","athlon-4")); - sl.append(QPair("Athlon XP","athlon-xp")); - sl.append(QPair("Athlon MP","athlon-mp")); - sl.append(QPair("K8","k8")); - sl.append(QPair("K8 Rev.E","k8-sse3")); - sl.append(QPair("K10","barcelona")); - sl.append(QPair("Bulldozer","bdver1")); - addOption("gcc_cmd_opt_arch", QObject::tr("Optimize for the following machine (-march)"), groupName, true, true, false, "-march=", sl); - addOption("gcc_cmd_opt_tune", QObject::tr("Optimize less, while maintaining full compatibility (-tune)"), groupName, true, true, false, "-mtune=", sl); - - // Enable use of the specific instructions - sl.clear(); - sl.append(QPair("MMX","mmx")); - sl.append(QPair("3D Now","3dnow")); - sl.append(QPair("SSE","sse")); - sl.append(QPair("SSE2","sse2")); - sl.append(QPair("SSE3","sse3")); - sl.append(QPair("SSSE3","ssse3")); - sl.append(QPair("SSE4","sse4")); - sl.append(QPair("SSE4A","sse4a")); - sl.append(QPair("SSE4.1","sse4.1")); - sl.append(QPair("SSE4.2","sse4.2")); - sl.append(QPair("AVX","avx")); - sl.append(QPair("AVX2","avx2")); - sl.append(QPair("FMA4","fma4")); - sl.append(QPair("XOP","xop")); - sl.append(QPair("AES","aes")); - addOption("gcc_cmd_opt_instruction",QObject::tr("Enable use of specific instructions (-mx)"), groupName, true, true, false, "-m", sl); - - // Optimization - sl.clear(); - sl.append(QPair("Low","1")); - sl.append(QPair("Med","2")); - sl.append(QPair("High","3")); - sl.append(QPair("Highest (fast)","fast")); - sl.append(QPair("Size (s)","s")); - sl.append(QPair("Debug (g)","g")); - addOption("gcc_cmd_opt_optimize", QObject::tr("Optimization level (-Ox)"), groupName, true, true, false, "-O", sl); - - // 32bit/64bit - sl.clear(); - sl.append(QPair("32bit","32")); - sl.append(QPair("64bit","64")); - addOption("gcc_cmd_opt_pointer_size", QObject::tr("Compile with the following pointer size (-mx)"), groupName, true, true, true, "-m", sl); - - // Language Standards - sl.clear(); - sl.append(QPair("ISO C90","c90")); - sl.append(QPair("ISO C99","c99")); - sl.append(QPair("ISO C11","c11")); - sl.append(QPair("ISO C17","c17")); - sl.append(QPair("ISO C++","c++98")); - sl.append(QPair("ISO C++11","c++11")); - sl.append(QPair("ISO C++14","c++14")); - sl.append(QPair("ISO C++17","c++17")); - sl.append(QPair("ISO C++20","c++2a")); - sl.append(QPair("GNU C90","gnu90")); - sl.append(QPair("GNU C99","gnu99")); - sl.append(QPair("GNU C11","gnu11")); - sl.append(QPair("GNU C17","gnu17")); - sl.append(QPair("GNU C++","gnu++98")); - sl.append(QPair("GNU C++11","gnu++11")); - sl.append(QPair("GNU C++14","gnu++14")); - sl.append(QPair("GNU C++17","gnu++17")); - sl.append(QPair("GNU C++20","gnu++2a")); - addOption("gcc_cmd_opt_std", QObject::tr("Language standard (-std)"), groupName, true, true, false, "-std=", sl); - - // Warnings - groupName = QObject::tr("Warnings"); - addOption("gcc_cmd_opt_inhibit_all_warning", QObject::tr("Inhibit all warning messages (-w)"), groupName, true, true, false, "-w"); - addOption("gcc_cmd_opt_warning_all",QObject::tr("Show most warnings (-Wall)"), groupName, true, true, false, "-Wall"); - addOption("gcc_cmd_opt_warning_extra",QObject::tr("Show some more warnings (-Wextra)"), groupName, true, true, false, "-Wextra"); - addOption("gcc_cmd_opt_check_iso_conformance", QObject::tr("Check ISO C/C++/C++0x conformance (-pedantic)"), groupName, true, true, false, "-pedantic"); - addOption("gcc_cmd_opt_syntax_only", QObject::tr("Only check the code for syntax errors (-fsyntax-only)"), groupName, true, true, false, "-fsyntax-only"); - addOption("gcc_cmd_opt_warning_as_error", QObject::tr("Make all warnings into errors (-Werror)"), groupName, true, true, false, "-Werror"); - addOption("gcc_cmd_opt_abort_on_error", QObject::tr("Abort compilation on first error (-Wfatal-errors)"), groupName, true, true, false, "-Wfatal-errors"); - - // Profile - groupName = QObject::tr("Profile"); - addOption("gcc_cmd_opt_profile_info",QObject::tr("Generate profiling info for analysis (-pg)"), groupName, true, true, true, "-pg"); - - // Linker - groupName = QObject::tr("Linker"); - addOption("linker_cmd_opt_link_objc", QObject::tr("Link an Objective C program (-lobjc)"), groupName, false, false, true, "-lobjc"); - addOption("linker_cmd_opt_no_link_stdlib",QObject::tr("Do not use standard system libraries (-nostdlib)"), groupName, false, false, true, "-nostdlib"); - addOption("linker_cmd_opt_no_console", QObject::tr("Do not create a console window (-mwindows)"), groupName,false, false, true, "-mwindows"); - addOption("linker_cmd_opt_strip_exe", QObject::tr("Strip executable (-s)"), groupName, false, false, true, "-s"); - addOption("cc_cmd_opt_debug_info", QObject::tr("Generate debugging information (-g3)"), groupName, true, true, false, "-g3"); - - // Output - groupName = QObject::tr("Output"); - addOption("cc_cmd_opt_verbose_asm", QObject::tr("Put comments in generated assembly code (-fverbose-asm)"), groupName, true, true, false, "-fverbose-asm"); - 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"); - addOption("cc_cmd_opt_use_pipe", QObject::tr("Use pipes instead of temporary files during compilation (-pipe)"), groupName, true, true, false, "-pipe"); - //old settings compatibility, don't reorder, add or remove items mCompilerCompatibleIndex.append("gcc_cmd_opt_ansi"); @@ -2924,25 +2806,6 @@ void Settings::CompilerSets::initOptions() } -void Settings::CompilerSets::addOption(const QString &key, const QString &name, const QString section, bool isC, bool isCpp, bool isLinker, const QString &setting, const CompileOptionChoiceList &choices) -{ - PCompilerOption pOption = std::make_shared(); - pOption->key = key; - pOption->name = name; - pOption->section = section; - pOption->isC = isC; - pOption->isCpp = isCpp; - pOption->isLinker = isLinker; - pOption->setting= setting; - pOption->choices = choices; - mCompilerOptions.insert(key,pOption); -} - -const CompilerOptionMap &Settings::CompilerSets::compilerOptions() const -{ - return mCompilerOptions; -} - QString Settings::CompilerSets::getKeyFromCompilerCompatibleIndex(int idx) const { if (idx<0 || idx >= mCompilerCompatibleIndex.length()) @@ -2950,11 +2813,6 @@ QString Settings::CompilerSets::getKeyFromCompilerCompatibleIndex(int idx) const return mCompilerCompatibleIndex[idx]; } -PCompilerOption Settings::CompilerSets::getCompilerOption(const QString &key) const -{ - return mCompilerOptions.value(key,PCompilerOption()); -} - Settings::Environment::Environment(Settings *settings):_Base(settings, SETTING_ENVIRONMENT) { diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index 1ffb14af..2bdbebc8 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -24,6 +24,7 @@ #include #include #include "qsynedit/SynEdit.h" +#include "compiler/compilerinfo.h" /** * use the following command to get gcc's default bin/library folders: @@ -47,42 +48,6 @@ #define SETTING_EDITOR_DEFAULT_ENCODING "default_encoding" #define SETTING_EDITOR_AUTO_INDENT "default_auto_indent" - -#define COMPILER_CLANG "Clang" -#define COMPILER_GCC "GCC" - -#define CC_CMD_OPT_ANSI "cc_cmd_opt_ansi" -#define CC_CMD_OPT_NO_ASM "cc_cmd_opt_no_asm" -#define CC_CMD_OPT_TRADITIONAL_CPP "cc_cmd_opt_traditional_cpp" - -#define CC_CMD_OPT_ARCH "cc_cmd_opt_arch" -#define CC_CMD_OPT_TUNE "cc_cmd_opt_tune" -#define CC_CMD_OPT_INSTRUCTION "cc_cmd_opt_instruction" -#define CC_CMD_OPT_OPTIMIZE "cc_cmd_opt_optimize" -#define CC_CMD_OPT_POINTER_SIZE "cc_cmd_opt_pointer_size" -#define CC_CMD_OPT_STD "cc_cmd_opt_std" - -#define CC_CMD_OPT_INHIBIT_ALL_WARNING "cc_cmd_opt_inhibit_all_warning" -#define CC_CMD_OPT_WARNING_ALL "cc_cmd_opt_warning_all" -#define CC_CMD_OPT_WARNING_EXTRA "cc_cmd_opt_warning_extra" -#define CC_CMD_OPT_CHECK_ISO_CONFORMANCE "cc_cmd_opt_check_iso_conformance" -#define CC_CMD_OPT_SYNTAX_ONLY "cc_cmd_opt_syntax_only" -#define CC_CMD_OPT_WARNING_AS_ERROR "cc_cmd_opt_warning_as_error" -#define CC_CMD_OPT_ABORT_ON_ERROR "cc_cmd_opt_abort_on_error" - -#define CC_CMD_OPT_PROFILE_INFO "cc_cmd_opt_profile_info" - -#define LINK_CMD_OPT_LINK_OBJC "link_cmd_opt_link_objc" -#define LINK_CMD_OPT_NO_LINK_STDLIB "link_cmd_opt_no_link_stdlib" -#define LINK_CMD_OPT_NO_CONSOLE "link_cmd_opt_no_console" -#define LINK_CMD_OPT_STRIP_EXE "link_cmd_opt_strip_exe" -#define CC_CMD_OPT_DEBUG_INFO "cc_cmd_opt_debug_info" - -#define CC_CMD_OPT_VERBOSE_ASM "cc_cmd_opt_verbose_asm" -#define CC_CMD_OPT_ONLY_GEN_ASM_CODE "cc_cmd_opt_only_gen_asm_code" -#define CC_CMD_OPT_USE_PIPE "cc_cmd_opt_use_pipe" - - extern const char ValueToChar[28]; class Settings; @@ -93,23 +58,6 @@ enum CompilerSetType { CST_PROFILING }; -using CompileOptionChoiceList = QList>; - -typedef struct { - QString key; - QString name; // "Generate debugging info" - QString section; // "C options" - bool isC; - bool isCpp; // True (C++ option?) - can be both C and C++ option... - bool isLinker; // Is it a linker param - QString setting; // "-g3" - CompileOptionChoiceList choices; // replaces "Yes/No" standard choices (max 30 different choices) -} CompilerOption; - -using PCompilerOption = std::shared_ptr; - -using CompilerOptionMap=QMap>; - class Settings { private: @@ -1371,10 +1319,8 @@ public: void setDefaultIndex(int value); PCompilerSet defaultSet(); PCompilerSet getSet(int index); - const CompilerOptionMap &compilerOptions() const; QString getKeyFromCompilerCompatibleIndex(int idx) const; - PCompilerOption getCompilerOption(const QString& key) const; private: void savePath(const QString& name, const QString& path); @@ -1383,20 +1329,11 @@ public: QString loadPath(const QString& name); void loadPathList(const QString& name, QStringList& list); PCompilerSet loadSet(int index); - void initOptions(); - void addOption(const QString& key, - const QString& name, - const QString section, - bool isC, - bool isCpp, - bool isLinker, - const QString& setting, - const CompileOptionChoiceList& choices = QStringList()); + void prepareCompatibleIndex(); private: CompilerSetList mList; int mDefaultIndex; Settings* mSettings; - CompilerOptionMap mCompilerOptions; QStringList mCompilerCompatibleIndex; // index for old settings compatibility }; diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.ui b/RedPandaIDE/settingsdialog/compilersetoptionwidget.ui index 9fcb6130..ff37a9b8 100644 --- a/RedPandaIDE/settingsdialog/compilersetoptionwidget.ui +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.ui @@ -110,7 +110,7 @@ - 0 + 1 false diff --git a/RedPandaIDE/widgets/compileargumentswidget.cpp b/RedPandaIDE/widgets/compileargumentswidget.cpp new file mode 100644 index 00000000..21a0113c --- /dev/null +++ b/RedPandaIDE/widgets/compileargumentswidget.cpp @@ -0,0 +1,113 @@ +#include "compileargumentswidget.h" +#include "ui_compileargumentswidget.h" + +#include +#include +#include + +CompileArgumentsWidget::CompileArgumentsWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::CompileArgumentsWidget) +{ + ui->setupUi(this); +} + +CompileArgumentsWidget::~CompileArgumentsWidget() +{ + delete ui; +} + +QMap CompileArgumentsWidget::options() const +{ + QMap + QTabWidget* pTab = ui->tabArguments; + for (int i=0;icount();i++) { + QString section = pTab->tabText(i); + QWidget* pWidget = pTab->widget(i); + QGridLayout* pLayout = static_cast(pWidget->layout()); + if (pLayout != nullptr) { + for (int j=1;jrowCount()-1;j++) { + QString key = static_cast(pLayout->itemAtPosition(j,0)->widget())->text(); + PCompilerOption pOption = CompilerInfoManager::getCompilerOption(mCompilerType,key); + if (!pOption) + continue; + if (pOption->choices.isEmpty()) { + QCheckBox* pCheckbox = static_cast(pLayout->itemAtPosition(j,1)->widget()); + if (pCheckbox->isChecked()) { + + pSet->setCompileOption(key,""); + } else { + pSet->unsetCompileOption(key); + } + } else { + QComboBox* pCombo = static_cast(pLayout->itemAtPosition(j,2)->widget()); + if (!pCombo->currentData().toString().isEmpty()) { + pSet->setCompileOption(key,pCombo->currentData().toString()); + } else { + pSet->unsetCompileOption(key); + } + } + } + } + } +} + +void CompileArgumentsWidget::resetUI(Settings::PCompilerSet pSet, const QMap& options) +{ + QTabWidget* pTab = ui->tabArguments; + while (pTab->count()>0) { + QWidget* p=pTab->widget(0); + if (p!=nullptr) { + pTab->removeTab(0); + p->setParent(nullptr); + delete p; + } + } + if (!pSet) + return; + mCompilerType = pSet->compilerType(); + + foreach (PCompilerOption pOption, CompilerInfoManager::getCompilerOptions(mCompilerType).values()) { + QWidget* pWidget = nullptr; + for (int i=0;icount();i++) { + if (pOption->section == pTab->tabText(i)) { + pWidget = pTab->widget(i); + break; + } + } + if (pWidget == nullptr) { + pWidget = new QWidget(); + pTab->addTab(pWidget,pOption->section); + pWidget->setLayout(new QGridLayout()); + } + QGridLayout *pLayout = static_cast(pWidget->layout()); + int row = pLayout->rowCount(); + QLabel* keyLabel = new QLabel(pOption->key,pWidget); + keyLabel->setVisible(false); + pLayout->addWidget(keyLabel,row,0); + if (pOption->choices.isEmpty()) { + QCheckBox* pCheckbox = new QCheckBox(pWidget); + pCheckbox->setText(pOption->name); + pCheckbox->setChecked(options.value(pOption->key,"")==COMPILER_OPTION_ON); + pLayout->addWidget(pCheckbox,row,1); + } else { + pLayout->addWidget(new QLabel(pOption->name,pWidget),row,1); + QComboBox* pCombo = new QComboBox(pWidget); + pCombo->addItem("",""); + for (int i=0;ichoices.length();i++) { + const QPair &choice = pOption->choices[i]; + pCombo->addItem(choice.first,choice.second); + if (options.value(pOption->key,"") == choice.second) + pCombo->setCurrentIndex(i); + } + pLayout->addWidget(pCombo,row,2); + } + } + for (int i=0;icount();i++) { + QWidget* pWidget = pTab->widget(i); + QGridLayout *pLayout = static_cast(pWidget->layout()); + int row = pLayout->rowCount(); + QSpacerItem* verticalSpacer = new QSpacerItem(10, 100, QSizePolicy::Minimum, QSizePolicy::Expanding); + pLayout->addItem(verticalSpacer,row,0); + } +} diff --git a/RedPandaIDE/widgets/compileargumentswidget.h b/RedPandaIDE/widgets/compileargumentswidget.h new file mode 100644 index 00000000..01aef676 --- /dev/null +++ b/RedPandaIDE/widgets/compileargumentswidget.h @@ -0,0 +1,29 @@ +#ifndef COMPILEARGUMENTSWIDGET_H +#define COMPILEARGUMENTSWIDGET_H + +#include +#include +#include "../settings.h" + +namespace Ui { +class CompileArgumentsWidget; +} + +class CompileArgumentsWidget : public QWidget +{ + Q_OBJECT + +public: + explicit CompileArgumentsWidget(QWidget *parent = nullptr); + ~CompileArgumentsWidget(); + + QMap options() const; + + void resetUI(Settings::PCompilerSet pSet, const QMap& options); + +private: + Ui::CompileArgumentsWidget *ui; + QString mCompilerType; +}; + +#endif // COMPILEARGUMENTSWIDGET_H diff --git a/RedPandaIDE/widgets/compileargumentswidget.ui b/RedPandaIDE/widgets/compileargumentswidget.ui new file mode 100644 index 00000000..ab178613 --- /dev/null +++ b/RedPandaIDE/widgets/compileargumentswidget.ui @@ -0,0 +1,35 @@ + + + CompileArgumentsWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + Tab 1 + + + + + Tab 2 + + + + + + + + +