- enhancement: add the option "Set Encoding for the Executable" to project's compiler options

- fix: can't correctly compile when link params are seperated by line breaks
This commit is contained in:
Roy Qu 2022-06-22 17:08:35 +08:00
parent 85c18d1f66
commit 20690b7e51
12 changed files with 766 additions and 600 deletions

View File

@ -1,6 +1,8 @@
Red Panda C++ Version 1.1.2 Red Panda C++ Version 1.1.2
- enhancement: use different color to differenciate folder and headers in completion popup window - enhancement: use different color to differenciate folder and headers in completion popup window
- enhancement: auto add "/" to folder when completing #include headers - enhancement: auto add "/" to folder when completing #include headers
- enhancement: add the option "Set Encoding for the Executable" to project's compiler options
- fix: can't correctly compile when link params are seperated by line breaks
Red Panda C++ Version 1.1.1 Red Panda C++ Version 1.1.1
- enhancement: adjust the appearance of problem case's input/output/expected control - enhancement: adjust the appearance of problem case's input/output/expected control

View File

@ -4882,7 +4882,15 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Add encoding options to compiler</source> <source>ANSI</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>UTF-8</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Set Encoding for the executable:</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>

File diff suppressed because it is too large Load Diff

View File

@ -4882,7 +4882,15 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Add encoding options to compiler</source> <source>ANSI</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>UTF-8</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Set Encoding for the executable:</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>

View File

@ -359,14 +359,18 @@ QString Compiler::getCCompileArguments(bool checkSyntax)
} }
if (compilerSet()->useCustomCompileParams() && !compilerSet()->customCompileParams().isEmpty()) { if (compilerSet()->useCustomCompileParams() && !compilerSet()->customCompileParams().isEmpty()) {
result += " "+ parseMacros(compilerSet()->customCompileParams()); QStringList params = textToLines(compilerSet()->customCompileParams());
foreach(const QString& param, params)
result += " "+ parseMacros(param);
} }
if (mProject) { if (mProject) {
QString s = mProject->options().compilerCmd; QString s = mProject->options().compilerCmd;
if (!s.isEmpty()) { if (!s.isEmpty()) {
s.replace("_@@_", " "); s.replace("_@@_", " ");
result += " "+parseMacros(s); QStringList params = textToLines(s);
foreach(const QString& param, params)
result += " "+ parseMacros(param);
} }
} }
return result; return result;
@ -396,13 +400,17 @@ QString Compiler::getCppCompileArguments(bool checkSyntax)
} }
} }
if (compilerSet()->useCustomCompileParams() && !compilerSet()->customCompileParams().isEmpty()) { if (compilerSet()->useCustomCompileParams() && !compilerSet()->customCompileParams().isEmpty()) {
result += " "+ parseMacros(compilerSet()->customCompileParams()); QStringList params = textToLines(compilerSet()->customCompileParams());
foreach(const QString& param, params)
result += " "+ parseMacros(param);
} }
if (mProject) { if (mProject) {
QString s = mProject->options().cppCompilerCmd; QString s = mProject->options().cppCompilerCmd;
if (!s.isEmpty()) { if (!s.isEmpty()) {
s.replace("_@@_", " "); s.replace("_@@_", " ");
result += " "+parseMacros(s); QStringList params = textToLines(s);
foreach(const QString& param, params)
result += " "+ parseMacros(param);
} }
} }
return result; return result;
@ -507,7 +515,11 @@ QString Compiler::getLibraryArguments(FileType fileType)
// Add global compiler linker extras // Add global compiler linker extras
if (compilerSet()->useCustomLinkParams() && !compilerSet()->customLinkParams().isEmpty()) { if (compilerSet()->useCustomLinkParams() && !compilerSet()->customLinkParams().isEmpty()) {
result += " "+compilerSet()->customLinkParams(); QStringList params = textToLines(compilerSet()->customLinkParams());
if (!params.isEmpty()) {
foreach(const QString& param, params)
result += " " + param;
}
} }
if (mProject) { if (mProject) {
@ -519,7 +531,11 @@ QString Compiler::getLibraryArguments(FileType fileType)
QString s = mProject->options().linkerCmd; QString s = mProject->options().linkerCmd;
if (!s.isEmpty()) { if (!s.isEmpty()) {
s.replace("_@@_", " "); s.replace("_@@_", " ");
result += " "+s; QStringList params = textToLines(s);
if (!params.isEmpty()) {
foreach(const QString& param, params)
result += " " + param;
}
} }
} }
if (mProject->options().staticLink) if (mProject->options().staticLink)

View File

@ -387,23 +387,37 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
} else { } else {
QString encodingStr; QString encodingStr;
if (compilerSet()->compilerType() != COMPILER_CLANG && mProject->options().addCharset) { if (compilerSet()->compilerType() != COMPILER_CLANG && mProject->options().addCharset) {
QByteArray defaultSystemEncoding = pCharsetInfoManager->getDefaultSystemEncoding(); QByteArray defaultSystemEncoding=pCharsetInfoManager->getDefaultSystemEncoding();
QByteArray encoding = mProject->options().execEncoding;
QByteArray targetEncoding;
QByteArray sourceEncoding;
if ( encoding == ENCODING_SYSTEM_DEFAULT || encoding.isEmpty()) {
targetEncoding = defaultSystemEncoding;
} else if (encoding == ENCODING_UTF8_BOM) {
targetEncoding = "UTF-8";
} else {
targetEncoding = encoding;
}
if (unit->encoding() == ENCODING_AUTO_DETECT) { if (unit->encoding() == ENCODING_AUTO_DETECT) {
Editor* editor = mProject->unitEditor(unit); Editor* editor = mProject->unitEditor(unit);
if (editor && editor->fileEncoding()!=ENCODING_ASCII if (editor && editor->fileEncoding()!=ENCODING_ASCII
&& editor->fileEncoding()!=defaultSystemEncoding) && editor->fileEncoding()!=targetEncoding) {
encodingStr = QString(" -finput-charset=%1 -fexec-charset=%2") sourceEncoding = editor->fileEncoding();
.arg(QString(editor->fileEncoding()), } else {
QString(defaultSystemEncoding)); sourceEncoding = targetEncoding;
}
} else if (unit->encoding()==ENCODING_SYSTEM_DEFAULT) { } else if (unit->encoding()==ENCODING_SYSTEM_DEFAULT) {
// encodingStr = QString(" -finput-charset=%1 -fexec-charset=%2") sourceEncoding = defaultSystemEncoding;
// .arg(QString(defaultSystemEncoding),
// QString(defaultSystemEncoding));
} else if (unit->encoding()!=ENCODING_ASCII && !unit->encoding().isEmpty() } else if (unit->encoding()!=ENCODING_ASCII && !unit->encoding().isEmpty()
&& unit->encoding()!=defaultSystemEncoding) { && unit->encoding()!=targetEncoding) {
sourceEncoding = unit->encoding();
}
if (sourceEncoding!=targetEncoding) {
encodingStr = QString(" -finput-charset=%1 -fexec-charset=%2") encodingStr = QString(" -finput-charset=%1 -fexec-charset=%2")
.arg(QString(unit->encoding()), .arg(QString(sourceEncoding),
QString(defaultSystemEncoding)); QString(targetEncoding));
} }
} }

View File

@ -911,6 +911,7 @@ void Project::saveOptions()
} }
ini.SetLongValue("Project","StaticLink", mOptions.staticLink); ini.SetLongValue("Project","StaticLink", mOptions.staticLink);
ini.SetLongValue("Project","AddCharset", mOptions.addCharset); ini.SetLongValue("Project","AddCharset", mOptions.addCharset);
ini.SetValue("Project","ExecEncoding", mOptions.execEncoding);
ini.SetValue("Project","Encoding",toByteArray(mOptions.encoding)); ini.SetValue("Project","Encoding",toByteArray(mOptions.encoding));
ini.SetLongValue("Project","ModelType", (int)mOptions.modelType); ini.SetLongValue("Project","ModelType", (int)mOptions.modelType);
//for Red Panda Dev C++ 6 compatibility //for Red Panda Dev C++ 6 compatibility
@ -1666,6 +1667,7 @@ void Project::loadOptions(SimpleIni& ini)
} }
mOptions.staticLink = ini.GetBoolValue("Project", "StaticLink", true); mOptions.staticLink = ini.GetBoolValue("Project", "StaticLink", true);
mOptions.execEncoding = ini.GetValue("Project","ExecEncoding", ENCODING_SYSTEM_DEFAULT);
mOptions.addCharset = ini.GetBoolValue("Project", "AddCharset", true); mOptions.addCharset = ini.GetBoolValue("Project", "AddCharset", true);
if (mOptions.compilerSetType<0) { if (mOptions.compilerSetType<0) {

View File

@ -15,6 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include "projectoptions.h" #include "projectoptions.h"
#include "utils.h"
ProjectVersionInfo::ProjectVersionInfo() ProjectVersionInfo::ProjectVersionInfo()
{ {
@ -53,4 +54,5 @@ ProjectOptions::ProjectOptions()
staticLink = true; staticLink = true;
addCharset = true; addCharset = true;
modelType = ProjectModelType::FileSystem; modelType = ProjectModelType::FileSystem;
execEncoding = ENCODING_SYSTEM_DEFAULT;
} }

View File

@ -89,6 +89,7 @@ struct ProjectOptions{
QString cmdLineArgs; QString cmdLineArgs;
bool staticLink; bool staticLink;
bool addCharset; bool addCharset;
QByteArray execEncoding;
QString encoding; QString encoding;
ProjectModelType modelType; ProjectModelType modelType;
}; };

View File

@ -19,6 +19,7 @@
#include "../settings.h" #include "../settings.h"
#include "../project.h" #include "../project.h"
#include "../mainwindow.h" #include "../mainwindow.h"
#include "../platform.h"
ProjectCompilerWidget::ProjectCompilerWidget(const QString &name, const QString &group, QWidget *parent) : ProjectCompilerWidget::ProjectCompilerWidget(const QString &name, const QString &group, QWidget *parent) :
SettingsWidget(name,group,parent), SettingsWidget(name,group,parent),
@ -37,8 +38,8 @@ void ProjectCompilerWidget::refreshOptions()
Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(ui->cbCompilerSet->currentIndex()); Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(ui->cbCompilerSet->currentIndex());
if (!pSet) if (!pSet)
return; return;
ui->chkAddCharset->setVisible(pSet->compilerType()!=COMPILER_CLANG); ui->panelAddCharset->setVisible(pSet->compilerType()!=COMPILER_CLANG);
ui->chkAddCharset->setEnabled(pSet->compilerType()!=COMPILER_CLANG); //ui->chkAddCharset->setEnabled(pSet->compilerType()!=COMPILER_CLANG);
mOptions = pMainWindow->project()->options().compilerOptions; mOptions = pMainWindow->project()->options().compilerOptions;
if (mOptions.isEmpty()) if (mOptions.isEmpty())
mOptions = pSet->compileOptions(); mOptions = pSet->compileOptions();
@ -46,6 +47,27 @@ void ProjectCompilerWidget::refreshOptions()
ui->tabOptions->resetUI(pSet,mOptions); ui->tabOptions->resetUI(pSet,mOptions);
ui->chkStaticLink->setChecked(pSet->staticLink()); ui->chkStaticLink->setChecked(pSet->staticLink());
QByteArray execEncoding = pMainWindow->project()->options().execEncoding;
if (execEncoding == ENCODING_AUTO_DETECT
|| execEncoding == ENCODING_SYSTEM_DEFAULT
|| execEncoding == ENCODING_UTF8) {
int index =ui->cbEncoding->findData(execEncoding);
ui->cbEncoding->setCurrentIndex(index);
ui->cbEncodingDetails->clear();
ui->cbEncodingDetails->setVisible(false);
} else {
QString encoding = execEncoding;
QString language = pCharsetInfoManager->findLanguageByCharsetName(encoding);
ui->cbEncoding->setCurrentText(language);
ui->cbEncodingDetails->setVisible(true);
ui->cbEncodingDetails->clear();
QList<PCharsetInfo> infos = pCharsetInfoManager->findCharsetsByLanguageName(language);
foreach (const PCharsetInfo& info, infos) {
ui->cbEncodingDetails->addItem(info->name);
}
ui->cbEncodingDetails->setCurrentText(encoding);
}
} }
void ProjectCompilerWidget::doLoad() void ProjectCompilerWidget::doLoad()
@ -68,6 +90,12 @@ void ProjectCompilerWidget::doSave()
if (pSet->compilerType()!=COMPILER_CLANG) if (pSet->compilerType()!=COMPILER_CLANG)
pMainWindow->project()->options().addCharset = ui->chkAddCharset->isChecked(); pMainWindow->project()->options().addCharset = ui->chkAddCharset->isChecked();
pMainWindow->project()->options().staticLink = ui->chkStaticLink->isChecked(); pMainWindow->project()->options().staticLink = ui->chkStaticLink->isChecked();
if (ui->cbEncodingDetails->isVisible()) {
pMainWindow->project()->options().execEncoding = ui->cbEncodingDetails->currentText().toLocal8Bit();
} else {
pMainWindow->project()->options().execEncoding = ui->cbEncoding->currentData().toString().toLocal8Bit();
}
pMainWindow->project()->saveOptions(); pMainWindow->project()->saveOptions();
} }
@ -77,6 +105,13 @@ void ProjectCompilerWidget::init()
for (size_t i=0;i<pSettings->compilerSets().size();i++) { for (size_t i=0;i<pSettings->compilerSets().size();i++) {
ui->cbCompilerSet->addItem(pSettings->compilerSets().getSet(i)->name()); ui->cbCompilerSet->addItem(pSettings->compilerSets().getSet(i)->name());
} }
ui->cbEncodingDetails->setVisible(false);
ui->cbEncoding->clear();
ui->cbEncoding->addItem(tr("ANSI"),ENCODING_SYSTEM_DEFAULT);
ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8);
foreach (const QString& langName, pCharsetInfoManager->languageNames()) {
ui->cbEncoding->addItem(langName,langName);
}
SettingsWidget::init(); SettingsWidget::init();
} }
@ -85,3 +120,27 @@ void ProjectCompilerWidget::on_cbCompilerSet_currentIndexChanged(int)
refreshOptions(); refreshOptions();
} }
void ProjectCompilerWidget::on_cbEncoding_currentTextChanged(const QString &arg1)
{
QString userData = ui->cbEncoding->currentData().toString();
if (userData == ENCODING_AUTO_DETECT
|| userData == ENCODING_SYSTEM_DEFAULT
|| userData == ENCODING_UTF8) {
ui->cbEncodingDetails->setVisible(false);
ui->cbEncodingDetails->clear();
} else {
ui->cbEncodingDetails->setVisible(true);
ui->cbEncodingDetails->clear();
QList<PCharsetInfo> infos = pCharsetInfoManager->findCharsetsByLanguageName(userData);
foreach (const PCharsetInfo& info, infos) {
ui->cbEncodingDetails->addItem(info->name);
}
}
}
void ProjectCompilerWidget::on_cbEncodingDetails_currentTextChanged(const QString &arg1)
{
}

View File

@ -48,6 +48,8 @@ public:
void init() override; void init() override;
private slots: private slots:
void on_cbCompilerSet_currentIndexChanged(int index); void on_cbCompilerSet_currentIndexChanged(int index);
void on_cbEncoding_currentTextChanged(const QString &arg1);
void on_cbEncodingDetails_currentTextChanged(const QString &arg1);
}; };
#endif // PROJECTCOMPILERWIDGET_H #endif // PROJECTCOMPILERWIDGET_H

View File

@ -14,6 +14,16 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="6" column="0" colspan="3">
<widget class="QWidget" name="widget" native="true"/>
</item>
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="chkStaticLink">
<property name="text">
<string>Statically link libraries</string>
</property>
</widget>
</item>
<item row="0" column="2"> <item row="0" column="2">
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
@ -27,19 +37,9 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="6" column="0" colspan="3">
<widget class="QWidget" name="widget" native="true"/>
</item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="cbCompilerSet"/> <widget class="QComboBox" name="cbCompilerSet"/>
</item> </item>
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="chkStaticLink">
<property name="text">
<string>Statically link libraries</string>
</property>
</widget>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
@ -47,13 +47,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0">
<widget class="QCheckBox" name="chkAddCharset">
<property name="text">
<string>Add encoding options to compiler</string>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
@ -68,6 +61,50 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="3">
<widget class="QWidget" name="panelAddCharset" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="chkAddCharset">
<property name="text">
<string>Set Encoding for the executable:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbEncoding"/>
</item>
<item>
<widget class="QComboBox" name="cbEncodingDetails"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>