From dde47e02266545cf2ebdd340fa2511418b08c466 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 22 Dec 2022 22:01:55 +0800 Subject: [PATCH] - fix: Makefile error when "Use precompiled header" is enabled in the project option dialog. --- NEWS.md | 1 + RedPandaIDE/compiler/projectcompiler.cpp | 55 +++++---- .../projectprecompilewidget.cpp | 8 +- .../settingsdialog/projectprecompilewidget.ui | 7 ++ RedPandaIDE/systemconsts.cpp | 2 +- RedPandaIDE/translations/RedPandaIDE_pt_BR.ts | 12 +- RedPandaIDE/translations/RedPandaIDE_zh_CN.ts | 113 ++++++++++-------- RedPandaIDE/translations/RedPandaIDE_zh_TW.ts | 8 +- 8 files changed, 123 insertions(+), 83 deletions(-) diff --git a/NEWS.md b/NEWS.md index 909a0b08..4a5b9601 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/RedPandaIDE/compiler/projectcompiler.cpp b/RedPandaIDE/compiler/projectcompiler.cpp index 550bfb0e..34279296 100644 --- a/RedPandaIDE/compiler/projectcompiler.cpp +++ b/RedPandaIDE/compiler/projectcompiler.cpp @@ -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 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 fileIncludes = parser->getFileIncludes(unit->fileName()); - foreach (const QString& headerName, fileIncludes) { - if (headerName == unit->fileName()) + foreach(const PProjectUnit &unit2, projectUnits) { + if (unit2==unit) 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 (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 { diff --git a/RedPandaIDE/settingsdialog/projectprecompilewidget.cpp b/RedPandaIDE/settingsdialog/projectprecompilewidget.cpp index a2f34002..43ed5c43 100644 --- a/RedPandaIDE/settingsdialog/projectprecompilewidget.cpp +++ b/RedPandaIDE/settingsdialog/projectprecompilewidget.cpp @@ -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); } diff --git a/RedPandaIDE/settingsdialog/projectprecompilewidget.ui b/RedPandaIDE/settingsdialog/projectprecompilewidget.ui index 8a2421f0..e87d2197 100644 --- a/RedPandaIDE/settingsdialog/projectprecompilewidget.ui +++ b/RedPandaIDE/settingsdialog/projectprecompilewidget.ui @@ -38,6 +38,13 @@ 0 + + + + Header to be precompiled: + + + diff --git a/RedPandaIDE/systemconsts.cpp b/RedPandaIDE/systemconsts.cpp index c5ae56c7..ce8ff50c 100644 --- a/RedPandaIDE/systemconsts.cpp +++ b/RedPandaIDE/systemconsts.cpp @@ -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"); diff --git a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts index 0d7062d1..bb5953e2 100644 --- a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts +++ b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts @@ -5737,14 +5737,22 @@ Precompiled header - Cabeçalho já compilado + Cabeçalho já compilado header files (*.h) arquivos de cabeçalhos (*h) - precompiled header files (*.pch) + Select the header file to be precompiled + + + + Header files (*.h *.hh *.hpp) + + + + Header to be precompiled: diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts index af6f5c0a..e720611c 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts @@ -7036,105 +7036,105 @@ Are you really want to continue? 无法保存文件'%1'. - + Error Load File 载入文件错误 - - + + Error 错误 - + Can't create folder %1 无法创建文件夹%1 - + Warning 警告 - - + + Can't save file %1 无法保存文件%1 - + File Exists 文件已存在 - + File '%1' is already in the project 文件'%1'已在项目中 - + Project Updated 项目已升级 - + Your project was succesfully updated to a newer file format! 已成功将项目升级到新的格式 - + If something has gone wrong, we kept a backup-file: '%1'... 旧项目文件备份在'%1'。 - + Headers 头文件 - + Sources 源文件 - + Others 其他文件 - + Settings need update 设置需要更新 - + The compiler settings format of Red Panda C++ has changed. The compiler settings format of Dev-C++ has changed. 小熊猫C++的编译器设置格式已发生改变。 - + Please update your settings at Project >> Project Options >> Compiler and save your project. 请在项目 >> 项目属性 >> 编译器设置中修改您的设置并保存您的项目 - + Compiler not found 未找到编译器 - + The compiler set you have selected for this project, no longer exists. 您为该项目设置的编译器不存在。 - + It will be substituted by the global compiler set. 它将会被全局编译器设置代替。 - + Developed using the Red Panda C++ IDE Developed using the Red Panda Dev-C++ IDE 使用小熊猫C++编辑器开发 @@ -7244,47 +7244,47 @@ Are you really want to continue? 无法写入文件'%1'! - + - Resource File: %1 - 资源文件: %1 - + Compiling project changes... 正在编译项目修改... - + - Project Filename: %1 - 项目文件名: %1 - + - Compiler Set Name: %1 - 编译器配置: %1 - + Make program '%1' doesn't exists! Make程序“%1”不存在! - + Please check the "program" page of compiler settings. 请检查编译器配置中的“程序”页。 - + Processing makefile: 正在处理makefile... - + - makefile processer: %1 - makefile处理器: %1 - + - Command: %1 %2 - 命令: %1 %2 @@ -7622,32 +7622,32 @@ Are you really want to continue? ProjectModel - + File exists 文件已存在 - + File '%1' already exists. Delete it now? 文件'%1'已存在。是否删除? - + Remove failed 删除失败 - + Failed to remove file '%1' 无法删除文件'%1' - + Rename failed 改名失败 - + Failed to rename file '%1' to '%2' 无法将文件'%1'改名为'%2' @@ -7720,31 +7720,44 @@ Are you really want to continue? 使用预编译头文件 - - + + Header to be precompiled: + 要预编译的头文件: + + + + Browse 浏览 - + <html><head/><body><p>For more information about gcc precompiled header, see:</p><p><a href="https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html"><span style=" text-decoration: underline; color:#007af4;">https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html</span></a></p></body></html> <html><head/><body><p>请问访问下面网站以了解有关gcc预定义头文件的信息:</p><p><a href="https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html"><span style=" text-decoration: underline; color:#007af4;">https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html</span></a></p></body></html> - Precompiled header - 预定义头文件 + 预定义头文件 - precompiled header files (*.pch) - 预定义头文件 (*.pch) + 预定义头文件 (*.pch) header files (*.h) header files (*.h 文件夹 (*.h) + + + Select the header file to be precompiled + 选择要预编译的头文件 + + + + Header files (*.h *.hh *.hpp) + 头文件 (*.h *.hh *.hpp) + ProjectTemplate @@ -8059,7 +8072,7 @@ Are you really want to continue? 生成调试信息(-g3) - + Would you like Red Panda C++ to search for compilers in PATH? 您同意小熊猫C++在PATH路径中寻找gcc编译器吗? @@ -8172,7 +8185,7 @@ Are you really want to continue? 只生成汇编代码(-S) - + Confirm 确认 @@ -8193,13 +8206,13 @@ Are you really want to continue? 如果仍然保留这些设置,可能会导致编译错误。<br /><br />请选择“是”,除非您清楚的知道选择“否”的后果, - - + + Compiler set not configuared. 未配置编译器设置。 - + Would you like Red Panda C++ to search for compilers in the following locations: <BR />'%1'<BR />'%2'? 您需要小熊猫C++在下列位置搜索编译器吗:<br />%1<br />%2 @@ -8569,7 +8582,7 @@ Are you really want to continue? - + Can't open file '%1' for write. 无法写入文件'%1'. diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts index 0a771efd..4e9558c8 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts @@ -5517,11 +5517,15 @@ - Precompiled header + Select the header file to be precompiled - precompiled header files (*.pch) + Header files (*.h *.hh *.hpp) + + + + Header to be precompiled: