2021-04-20 22:24:33 +08:00
|
|
|
#include "filecompiler.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "../mainwindow.h"
|
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
|
|
|
|
FileCompiler::FileCompiler(const QString &filename, const QByteArray &encoding,bool silent,bool onlyCheckSyntax):
|
|
|
|
Compiler(silent,onlyCheckSyntax),
|
|
|
|
mFileName(filename),
|
|
|
|
mEncoding(encoding)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings::PCompilerSet FileCompiler::compilerSet()
|
|
|
|
{
|
|
|
|
return pSettings->compilerSets().defaultSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileCompiler::prepareForCompile()
|
|
|
|
{
|
|
|
|
log(tr("Compiling single file..."));
|
|
|
|
log("------------------");
|
|
|
|
log(tr("- Filename: %1").arg(mFileName));
|
|
|
|
log(tr("- Compiler Set Name: %1").arg(compilerSet()->name()));
|
|
|
|
log("");
|
|
|
|
FileType fileType = getFileType(mFileName);
|
|
|
|
mArguments= QString(" \"%1\"").arg(mFileName);
|
|
|
|
if (!mOnlyCheckSyntax) {
|
2021-04-21 23:06:55 +08:00
|
|
|
mOutputFile = getCompiledExecutableName(mFileName);
|
|
|
|
mArguments+=QString(" -o \"%1\"").arg(mOutputFile);
|
2021-04-20 22:24:33 +08:00
|
|
|
|
|
|
|
//remove the old file it exists
|
2021-04-21 23:06:55 +08:00
|
|
|
QFile outputFile(mOutputFile);
|
2021-04-20 22:24:33 +08:00
|
|
|
if (outputFile.exists()) {
|
|
|
|
if (!outputFile.remove()) {
|
2021-04-21 23:06:55 +08:00
|
|
|
error(tr("Can't delete the old executable file \"%1\".\n").arg(mOutputFile));
|
2021-04-20 22:24:33 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mArguments += getCharsetArgument(mEncoding);
|
|
|
|
QString strFileType;
|
|
|
|
switch(fileType) {
|
|
|
|
case FileType::CSource:
|
|
|
|
mArguments += getCCompileArguments(mOnlyCheckSyntax);
|
|
|
|
mArguments += getCIncludeArguments();
|
|
|
|
strFileType = "C";
|
|
|
|
mCompiler = compilerSet()->CCompiler();
|
|
|
|
break;
|
|
|
|
case FileType::CppSource:
|
|
|
|
mArguments += getCCompileArguments(mOnlyCheckSyntax);
|
|
|
|
mArguments += getCIncludeArguments();
|
|
|
|
strFileType = "C++";
|
|
|
|
mCompiler = compilerSet()->cppCompiler();
|
|
|
|
break;
|
|
|
|
default:
|
2021-06-20 22:54:16 +08:00
|
|
|
error(tr("Can't find the compiler for file %1").arg(mFileName));
|
2021-04-20 22:24:33 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mArguments += getLibraryArguments();
|
|
|
|
|
|
|
|
log(tr("Processing %1 source file:").arg(strFileType));
|
|
|
|
log("------------------");
|
|
|
|
log(tr("%1 Compiler: %2").arg(strFileType).arg(mCompiler));
|
|
|
|
log(tr("Command: %1 %2").arg(QFileInfo(mCompiler).fileName()).arg(mArguments));
|
|
|
|
return true;
|
|
|
|
}
|