- fix: Makefile error when "Use precompiled header" is enabled in the project option dialog.

This commit is contained in:
Roy Qu 2022-12-22 22:01:55 +08:00
parent 7fcd73abfc
commit dde47e0226
8 changed files with 123 additions and 83 deletions

View File

@ -23,6 +23,7 @@ Red Panda C++ Version 2.7
- enhancement: "Line Spacing" in options / editor / font
- enhancement: "Show whitespaces" in options / editor / font
- enhancement: Auto add "lib" to the output of static/dynamic library projects, if project name don't start with "lib".
- fix: Makefile error when "Use precompiled header" is enabled in the project option dialog.
Red Panda C++ Version 2.6

View File

@ -119,6 +119,14 @@ void ProjectCompiler::newMakeFile(QFile& file)
// Write clean command
writeMakeClean(file);
// PCH
if (mProject->options().usePrecompiledHeader
&& fileExists(mProject->options().precompiledHeader)) {
writeln(file, "$(PCH) : $(PCH_H)");
writeln(file, "\t$(CPP) -c \"$(PCH_H)\" -o \"$(PCH)\" $(CXXFLAGS)");
writeln(file);
}
}
void ProjectCompiler::writeMakeHeader(QFile &file)
@ -253,9 +261,10 @@ void ProjectCompiler::writeMakeDefines(QFile &file)
cCompileArguments.replace('\\', '/');
writeln(file,"CFLAGS = $(INCS) " + cCompileArguments);
writeln(file, QString("RM = ") + CLEAN_PROGRAM );
if (mProject->options().usePrecompiledHeader){
writeln(file,"PCH_H = " + mProject->options().precompiledHeader );
writeln(file,"PCH = " + changeFileExt(mProject->options().precompiledHeader, GCH_EXT));
if (mProject->options().usePrecompiledHeader
&& fileExists(mProject->options().precompiledHeader)){
writeln(file,"PCH_H = " + genMakePath1(extractRelativePath(mProject->makeFileName(), mProject->options().precompiledHeader )));
writeln(file,"PCH = " + genMakePath1(extractRelativePath(mProject->makeFileName(), mProject->options().precompiledHeader+"."+GCH_EXT)));
}
@ -296,11 +305,7 @@ void ProjectCompiler::writeMakeTarget(QFile &file)
writeln(file);
writeln(file, "all: all-before $(BIN) all-after");
writeln(file);
if (mProject->options().usePrecompiledHeader) {
writeln(file, "$(PCH) : $(PCH_H)");
writeln(file, " $(CPP) -x c++-header \"$(PCH_H)\" -o \"$(PCH)\" $(CXXFLAGS)");
writeln(file);
}
}
void ProjectCompiler::writeMakeIncludes(QFile &file)
@ -316,10 +321,16 @@ void ProjectCompiler::writeMakeIncludes(QFile &file)
void ProjectCompiler::writeMakeClean(QFile &file)
{
writeln(file, "clean: clean-custom");
if (mProject->options().type == ProjectType::DynamicLib)
writeln(file, QString("\t-${RM} $(CLEANOBJ) $(CLEAN_DEF) $(CLEAN_STATIC) > %1 2>&1").arg(NULL_FILE));
else
writeln(file, QString("\t-${RM} $(CLEANOBJ) > %1 2>&1").arg(NULL_FILE));
QString target="$(CLEANOBJ)";
if (mProject->options().usePrecompiledHeader
&& fileExists(mProject->options().precompiledHeader)) {
target += " $(PCH)";
}
if (mProject->options().type == ProjectType::DynamicLib) {
target +=" $(CLEAN_DEF) $(CLEAN_STATIC)";
}
writeln(file, QString("\t-$(RM) %1 > %2 2>&1").arg(target,NULL_FILE));
writeln(file);
}
@ -327,8 +338,6 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
{
PCppParser parser = mProject->cppParser();
QString precompileStr;
if (mProject->options().usePrecompiledHeader)
precompileStr = " $(PCH) ";
QList<PProjectUnit> projectUnits=mProject->unitList();
foreach(const PProjectUnit &unit, projectUnits) {
@ -344,17 +353,15 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
// if we have scanned it, use scanned info
if (parser && parser->scannedFiles().contains(unit->fileName())) {
QSet<QString> fileIncludes = parser->getFileIncludes(unit->fileName());
foreach (const QString& headerName, fileIncludes) {
if (headerName == unit->fileName())
continue;
if (!parser->isSystemHeaderFile(headerName)
&& ! parser->isProjectHeaderFile(headerName)) {
foreach(const PProjectUnit &unit2, projectUnits) {
if (unit2->fileName()==headerName) {
objStr = objStr + ' ' + genMakePath2(extractRelativePath(mProject->makeFileName(),headerName));
break;
}
}
if (unit2==unit)
continue;
if (fileIncludes.contains(unit2->fileName())) {
if (mProject->options().usePrecompiledHeader &&
unit2->fileName() == mProject->options().precompiledHeader)
precompileStr = " $(PCH) ";
else
objStr = objStr + ' ' + genMakePath2(extractRelativePath(mProject->makeFileName(),unit2->fileName()));
}
}
} else {

View File

@ -56,13 +56,13 @@ void ProjectPreCompileWidget::on_btnBrowse_clicked()
} else {
currentDir = extractFilePath(currentFile);
}
QString fileName = QFileDialog::getSaveFileName(
QString fileName = QFileDialog::getOpenFileName(
this,
tr("Precompiled header"),
tr("Select the header file to be precompiled"),
currentDir,
tr("precompiled header files (*.pch)"),
tr("Header files (*.h *.hh *.hpp)"),
nullptr,
QFileDialog::Options()|QFileDialog::DontConfirmOverwrite);
QFileDialog::Options());
if (!fileName.isEmpty()) {
ui->txtPrecompileHeader->setText(fileName);
}

View File

@ -38,6 +38,13 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Header to be precompiled:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtPrecompileHeader"/>
</item>

View File

@ -30,7 +30,7 @@ SystemConsts::SystemConsts(): mDefaultFileFilters()
addDefaultFileFilter(QObject::tr("Dev C++ Project files"),"*.dev");
addDefaultFileFilter(QObject::tr("C files"),"*.c");
addDefaultFileFilter(QObject::tr("C++ files"),"*.cpp *.cc *.cxx");
addDefaultFileFilter(QObject::tr("Header files"),"*.h *.hh");
addDefaultFileFilter(QObject::tr("Header files"),"*.h *.hh *.hpp");
addFileFilter(mIconFileFilters, QObject::tr("Icon files"), "*.ico");

View File

@ -5737,14 +5737,22 @@
</message>
<message>
<source>Precompiled header</source>
<translation>Cabeçalho compilado</translation>
<translation type="vanished">Cabeçalho compilado</translation>
</message>
<message>
<source>header files (*.h)</source>
<translation type="vanished">arquivos de cabeçalhos (*h)</translation>
</message>
<message>
<source>precompiled header files (*.pch)</source>
<source>Select the header file to be precompiled</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Header files (*.h *.hh *.hpp)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Header to be precompiled:</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -7036,105 +7036,105 @@ Are you really want to continue?</oldsource>
<translation type="vanished">&apos;%1&apos;.</translation>
</message>
<message>
<location filename="../project.cpp" line="944"/>
<location filename="../project.cpp" line="948"/>
<source>Error Load File</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="968"/>
<location filename="../project.cpp" line="1065"/>
<location filename="../project.cpp" line="972"/>
<location filename="../project.cpp" line="1069"/>
<source>Error</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="969"/>
<location filename="../project.cpp" line="973"/>
<source>Can&apos;t create folder %1 </source>
<translation>%1</translation>
</message>
<message>
<location filename="../project.cpp" line="1036"/>
<location filename="../project.cpp" line="1040"/>
<source>Warning</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="1037"/>
<location filename="../project.cpp" line="1066"/>
<location filename="../project.cpp" line="1041"/>
<location filename="../project.cpp" line="1070"/>
<source>Can&apos;t save file %1</source>
<translation>%1</translation>
</message>
<message>
<location filename="../project.cpp" line="1193"/>
<location filename="../project.cpp" line="1197"/>
<source>File Exists</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="1194"/>
<location filename="../project.cpp" line="1198"/>
<source>File &apos;%1&apos; is already in the project</source>
<translation>&apos;%1&apos;</translation>
</message>
<message>
<location filename="../project.cpp" line="1576"/>
<location filename="../project.cpp" line="1580"/>
<source>Project Updated</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="1577"/>
<location filename="../project.cpp" line="1581"/>
<source>Your project was succesfully updated to a newer file format!</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="1579"/>
<location filename="../project.cpp" line="1583"/>
<source>If something has gone wrong, we kept a backup-file: &apos;%1&apos;...</source>
<translation>&apos;%1&apos;</translation>
</message>
<message>
<location filename="../project.cpp" line="1650"/>
<location filename="../project.cpp" line="1654"/>
<source>Headers</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="1658"/>
<location filename="../project.cpp" line="1662"/>
<source>Sources</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="1666"/>
<location filename="../project.cpp" line="1670"/>
<source>Others</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="1884"/>
<location filename="../project.cpp" line="1888"/>
<source>Settings need update</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="1885"/>
<location filename="../project.cpp" line="1889"/>
<source>The compiler settings format of Red Panda C++ has changed.</source>
<oldsource>The compiler settings format of Dev-C++ has changed.</oldsource>
<translation>C++</translation>
</message>
<message>
<location filename="../project.cpp" line="1887"/>
<location filename="../project.cpp" line="1891"/>
<source>Please update your settings at Project &gt;&gt; Project Options &gt;&gt; Compiler and save your project.</source>
<translation> &gt;&gt; &gt;&gt; </translation>
</message>
<message>
<location filename="../project.cpp" line="1961"/>
<location filename="../project.cpp" line="1965"/>
<source>Compiler not found</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="1962"/>
<location filename="../project.cpp" line="1966"/>
<source>The compiler set you have selected for this project, no longer exists.</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="1964"/>
<location filename="../project.cpp" line="1968"/>
<source>It will be substituted by the global compiler set.</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="2060"/>
<location filename="../project.cpp" line="2064"/>
<source>Developed using the Red Panda C++ IDE</source>
<oldsource>Developed using the Red Panda Dev-C++ IDE</oldsource>
<translation>使C++</translation>
@ -7244,47 +7244,47 @@ Are you really want to continue?</oldsource>
<translation>&apos;%1&apos;</translation>
</message>
<message>
<location filename="../compiler/projectcompiler.cpp" line="197"/>
<location filename="../compiler/projectcompiler.cpp" line="205"/>
<source>- Resource File: %1</source>
<translation>- : %1</translation>
</message>
<message>
<location filename="../compiler/projectcompiler.cpp" line="522"/>
<location filename="../compiler/projectcompiler.cpp" line="535"/>
<source>Compiling project changes...</source>
<translation>...</translation>
</message>
<message>
<location filename="../compiler/projectcompiler.cpp" line="524"/>
<location filename="../compiler/projectcompiler.cpp" line="537"/>
<source>- Project Filename: %1</source>
<translation>- : %1</translation>
</message>
<message>
<location filename="../compiler/projectcompiler.cpp" line="525"/>
<location filename="../compiler/projectcompiler.cpp" line="538"/>
<source>- Compiler Set Name: %1</source>
<translation>- : %1</translation>
</message>
<message>
<location filename="../compiler/projectcompiler.cpp" line="534"/>
<location filename="../compiler/projectcompiler.cpp" line="547"/>
<source>Make program &apos;%1&apos; doesn&apos;t exists!</source>
<translation>Make程序%1</translation>
</message>
<message>
<location filename="../compiler/projectcompiler.cpp" line="536"/>
<location filename="../compiler/projectcompiler.cpp" line="549"/>
<source>Please check the &quot;program&quot; page of compiler settings.</source>
<translation></translation>
</message>
<message>
<location filename="../compiler/projectcompiler.cpp" line="566"/>
<location filename="../compiler/projectcompiler.cpp" line="579"/>
<source>Processing makefile:</source>
<translation>makefile...</translation>
</message>
<message>
<location filename="../compiler/projectcompiler.cpp" line="568"/>
<location filename="../compiler/projectcompiler.cpp" line="581"/>
<source>- makefile processer: %1</source>
<translation>- makefile处理器: %1</translation>
</message>
<message>
<location filename="../compiler/projectcompiler.cpp" line="569"/>
<location filename="../compiler/projectcompiler.cpp" line="582"/>
<source>- Command: %1 %2</source>
<translation>- : %1 %2</translation>
</message>
@ -7622,32 +7622,32 @@ Are you really want to continue?</oldsource>
<context>
<name>ProjectModel</name>
<message>
<location filename="../project.cpp" line="2633"/>
<location filename="../project.cpp" line="2637"/>
<source>File exists</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="2634"/>
<location filename="../project.cpp" line="2638"/>
<source>File &apos;%1&apos; already exists. Delete it now?</source>
<translation>&apos;%1&apos;</translation>
</message>
<message>
<location filename="../project.cpp" line="2652"/>
<location filename="../project.cpp" line="2656"/>
<source>Remove failed</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="2653"/>
<location filename="../project.cpp" line="2657"/>
<source>Failed to remove file &apos;%1&apos;</source>
<translation>&apos;%1&apos;</translation>
</message>
<message>
<location filename="../project.cpp" line="2670"/>
<location filename="../project.cpp" line="2674"/>
<source>Rename failed</source>
<translation></translation>
</message>
<message>
<location filename="../project.cpp" line="2671"/>
<location filename="../project.cpp" line="2675"/>
<source>Failed to rename file &apos;%1&apos; to &apos;%2&apos;</source>
<translation>&apos;%1&apos;&apos;%2&apos;</translation>
</message>
@ -7720,31 +7720,44 @@ Are you really want to continue?</oldsource>
<translation>使</translation>
</message>
<message>
<location filename="../settingsdialog/projectprecompilewidget.ui" line="47"/>
<location filename="../settingsdialog/projectprecompilewidget.ui" line="50"/>
<location filename="../settingsdialog/projectprecompilewidget.ui" line="44"/>
<source>Header to be precompiled:</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/projectprecompilewidget.ui" line="54"/>
<location filename="../settingsdialog/projectprecompilewidget.ui" line="57"/>
<source>Browse</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/projectprecompilewidget.ui" line="71"/>
<location filename="../settingsdialog/projectprecompilewidget.ui" line="78"/>
<source>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;For more information about gcc precompiled header, see:&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#007af4;&quot;&gt;https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</source>
<translation>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;访gcc预定义头文件的信息:&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#007af4;&quot;&gt;https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</translation>
</message>
<message>
<location filename="../settingsdialog/projectprecompilewidget.cpp" line="61"/>
<source>Precompiled header</source>
<translation></translation>
<translation type="vanished"></translation>
</message>
<message>
<location filename="../settingsdialog/projectprecompilewidget.cpp" line="63"/>
<source>precompiled header files (*.pch)</source>
<translation> (*.pch)</translation>
<translation type="vanished"> (*.pch)</translation>
</message>
<message>
<source>header files (*.h)</source>
<oldsource>header files (*.h</oldsource>
<translation type="vanished"> (*.h)</translation>
</message>
<message>
<location filename="../settingsdialog/projectprecompilewidget.cpp" line="61"/>
<source>Select the header file to be precompiled</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/projectprecompilewidget.cpp" line="63"/>
<source>Header files (*.h *.hh *.hpp)</source>
<translation> (*.h *.hh *.hpp)</translation>
</message>
</context>
<context>
<name>ProjectTemplate</name>
@ -8059,7 +8072,7 @@ Are you really want to continue?</oldsource>
<translation>(-g3)</translation>
</message>
<message>
<location filename="../settings.cpp" line="2956"/>
<location filename="../settings.cpp" line="2971"/>
<source>Would you like Red Panda C++ to search for compilers in PATH?</source>
<translation>C++PATH路径中寻找gcc编译器吗</translation>
</message>
@ -8172,7 +8185,7 @@ Are you really want to continue?</oldsource>
<translation type="vanished">(-S)</translation>
</message>
<message>
<location filename="../settings.cpp" line="2958"/>
<location filename="../settings.cpp" line="2973"/>
<source>Confirm</source>
<translation></translation>
</message>
@ -8193,13 +8206,13 @@ Are you really want to continue?</oldsource>
<translation type="vanished">&lt;br /&gt;&lt;br /&gt;</translation>
</message>
<message>
<location filename="../settings.cpp" line="2948"/>
<location filename="../settings.cpp" line="2954"/>
<location filename="../settings.cpp" line="2963"/>
<location filename="../settings.cpp" line="2969"/>
<source>Compiler set not configuared.</source>
<translation></translation>
</message>
<message>
<location filename="../settings.cpp" line="2950"/>
<location filename="../settings.cpp" line="2965"/>
<source>Would you like Red Panda C++ to search for compilers in the following locations: &lt;BR /&gt;&apos;%1&apos;&lt;BR /&gt;&apos;%2&apos;? </source>
<translation>C++&lt;br /&gt;%1&lt;br /&gt;%2</translation>
</message>
@ -8569,7 +8582,7 @@ Are you really want to continue?</oldsource>
<location filename="../autolinkmanager.cpp" line="60"/>
<location filename="../autolinkmanager.cpp" line="74"/>
<location filename="../autolinkmanager.cpp" line="105"/>
<location filename="../project.cpp" line="662"/>
<location filename="../project.cpp" line="666"/>
<source>Can&apos;t open file &apos;%1&apos; for write.</source>
<translation>&apos;%1&apos;.</translation>
</message>

View File

@ -5517,11 +5517,15 @@
<translation type="unfinished"></translation>
</message>
<message>
<source>Precompiled header</source>
<source>Select the header file to be precompiled</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>precompiled header files (*.pch)</source>
<source>Header files (*.h *.hh *.hpp)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Header to be precompiled:</source>
<translation type="unfinished"></translation>
</message>
</context>