- fix: can't find the gcc compiler, if there are gcc and clang compilers in the same folder

This commit is contained in:
royqh1979@gmail.com 2022-07-24 18:24:21 +08:00
parent d034089214
commit 8d51876518
3 changed files with 72 additions and 43 deletions

View File

@ -13,6 +13,7 @@ Red Panda C++ Version 1.1.5
- fix: bug in the project template - fix: bug in the project template
- change: sort local identifiers before keywords in the auto completion popup - change: sort local identifiers before keywords in the auto completion popup
- fix: can't create folder in files view, if nothing is selected - fix: can't create folder in files view, if nothing is selected
- fix: can't find the gcc compiler, if there are gcc and clang compilers in the same folder
Red Panda C++ Version 1.1.4 Red Panda C++ Version 1.1.4

View File

@ -1463,16 +1463,26 @@ void Settings::Editor::setTabToSpaces(bool tabToSpaces)
mTabToSpaces = tabToSpaces; mTabToSpaces = tabToSpaces;
} }
Settings::CompilerSet::CompilerSet(const QString& compilerFolder): Settings::CompilerSet::CompilerSet():
mAutoAddCharsetParams(true),
mExecCharset(ENCODING_SYSTEM_DEFAULT),
mStaticLink(true),
mFullLoaded(false)
{
}
Settings::CompilerSet::CompilerSet(const QString& compilerFolder, const QString& cc_prog):
mAutoAddCharsetParams(true), mAutoAddCharsetParams(true),
mExecCharset(ENCODING_SYSTEM_DEFAULT), mExecCharset(ENCODING_SYSTEM_DEFAULT),
mStaticLink(true) mStaticLink(true)
{ {
if (!compilerFolder.isEmpty()) { if (QDir(compilerFolder).exists()) {
setProperties(compilerFolder); setProperties(compilerFolder, cc_prog);
//manually set the directories //manually set the directories
setDirectories(compilerFolder); setDirectories(compilerFolder, cc_prog);
setExecutables(); setExecutables();
@ -1763,7 +1773,7 @@ QStringList &Settings::CompilerSet::defaultCIncludeDirs()
{ {
if (!mFullLoaded && !binDirs().isEmpty()) { if (!mFullLoaded && !binDirs().isEmpty()) {
mFullLoaded=true; mFullLoaded=true;
setDirectories(binDirs()[0]); setDirectories(binDirs()[0],mCCompiler);
setDefines(); setDefines();
} }
return mDefaultCIncludeDirs; return mDefaultCIncludeDirs;
@ -1773,7 +1783,7 @@ QStringList &Settings::CompilerSet::defaultCppIncludeDirs()
{ {
if (!mFullLoaded && !binDirs().isEmpty()) { if (!mFullLoaded && !binDirs().isEmpty()) {
mFullLoaded=true; mFullLoaded=true;
setDirectories(binDirs()[0]); setDirectories(binDirs()[0],mCCompiler);
setDefines(); setDefines();
} }
return mDefaultCppIncludeDirs; return mDefaultCppIncludeDirs;
@ -1783,7 +1793,7 @@ QStringList &Settings::CompilerSet::defaultLibDirs()
{ {
if (!mFullLoaded && !binDirs().isEmpty()) { if (!mFullLoaded && !binDirs().isEmpty()) {
mFullLoaded=true; mFullLoaded=true;
setDirectories(binDirs()[0]); setDirectories(binDirs()[0],mCCompiler);
setDefines(); setDefines();
} }
return mLibDirs; return mLibDirs;
@ -1833,7 +1843,7 @@ const QStringList& Settings::CompilerSet::defines()
{ {
if (!mFullLoaded && !binDirs().isEmpty()) { if (!mFullLoaded && !binDirs().isEmpty()) {
mFullLoaded=true; mFullLoaded=true;
setDirectories(binDirs()[0]); setDirectories(binDirs()[0],mCCompiler);
setDefines(); setDefines();
} }
return mDefines; return mDefines;
@ -1920,15 +1930,17 @@ static void addExistingDirectory(QStringList& dirs, const QString& directory) {
dirs.append(dirPath); dirs.append(dirPath);
} }
void Settings::CompilerSet::setProperties(const QString &binDir) void Settings::CompilerSet::setProperties(const QString &binDir, const QString& cc_prog)
{ {
QString cc_prog; if (cc_prog.isEmpty())
if (fileExists(binDir, CLANG_PROGRAM))
cc_prog = CLANG_PROGRAM;
else if (fileExists(binDir,GCC_PROGRAM))
cc_prog = GCC_PROGRAM;
else
return; return;
// QString cc_prog;
// if (fileExists(binDir, CLANG_PROGRAM))
// cc_prog = CLANG_PROGRAM;
// else if (fileExists(binDir,GCC_PROGRAM))
// cc_prog = GCC_PROGRAM;
// else
// return;
// Obtain version number and compiler distro etc // Obtain version number and compiler distro etc
QStringList arguments; QStringList arguments;
arguments.append("-v"); arguments.append("-v");
@ -2088,7 +2100,7 @@ void Settings::CompilerSet::setExecutables()
mProfiler = findProgramInBinDirs(GPROF_PROGRAM); mProfiler = findProgramInBinDirs(GPROF_PROGRAM);
} }
void Settings::CompilerSet::setDirectories(const QString& binDir) void Settings::CompilerSet::setDirectories(const QString& binDir,const QString& cc_prog)
{ {
QString folder = QFileInfo(binDir).absolutePath(); QString folder = QFileInfo(binDir).absolutePath();
// Find default directories // Find default directories
@ -2099,7 +2111,7 @@ void Settings::CompilerSet::setDirectories(const QString& binDir)
arguments.append("-v"); arguments.append("-v");
arguments.append("-E"); arguments.append("-E");
arguments.append(NULL_FILE); arguments.append(NULL_FILE);
QByteArray output = getCompilerOutput(binDir,GCC_PROGRAM,arguments); QByteArray output = getCompilerOutput(binDir,cc_prog,arguments);
int delimPos1 = output.indexOf("#include <...> search starts here:"); int delimPos1 = output.indexOf("#include <...> search starts here:");
int delimPos2 = output.indexOf("End of search list."); int delimPos2 = output.indexOf("End of search list.");
@ -2121,7 +2133,7 @@ void Settings::CompilerSet::setDirectories(const QString& binDir)
arguments.append("-E"); arguments.append("-E");
arguments.append("-v"); arguments.append("-v");
arguments.append(NULL_FILE); arguments.append(NULL_FILE);
output = getCompilerOutput(binDir,GCC_PROGRAM,arguments); output = getCompilerOutput(binDir,cc_prog,arguments);
//gcc -xc++ -E -v NUL //gcc -xc++ -E -v NUL
delimPos1 = output.indexOf("#include <...> search starts here:"); delimPos1 = output.indexOf("#include <...> search starts here:");
@ -2141,7 +2153,7 @@ void Settings::CompilerSet::setDirectories(const QString& binDir)
arguments.clear(); arguments.clear();
arguments.append("-print-search-dirs"); arguments.append("-print-search-dirs");
arguments.append(NULL_FILE); arguments.append(NULL_FILE);
output = getCompilerOutput(binDir,GCC_PROGRAM,arguments); output = getCompilerOutput(binDir,cc_prog,arguments);
// bin dirs // bin dirs
QByteArray targetStr = QByteArray("programs: ="); QByteArray targetStr = QByteArray("programs: =");
delimPos1 = output.indexOf(targetStr); delimPos1 = output.indexOf(targetStr);
@ -2350,16 +2362,18 @@ Settings::CompilerSets::CompilerSets(Settings *settings):
prepareCompatibleIndex(); prepareCompatibleIndex();
} }
Settings::PCompilerSet Settings::CompilerSets::addSet(const Settings::CompilerSet& set) Settings::PCompilerSet Settings::CompilerSets::addSet()
{ {
PCompilerSet p=std::make_shared<CompilerSet>(set); PCompilerSet p=std::make_shared<CompilerSet>();
mList.push_back(p); mList.push_back(p);
return p; return p;
} }
Settings::PCompilerSet Settings::CompilerSets::addSet(const QString &folder) Settings::PCompilerSet Settings::CompilerSets::addSet(const QString &folder, const QString& cc_prog)
{ {
PCompilerSet p=std::make_shared<CompilerSet>(folder); PCompilerSet p=std::make_shared<CompilerSet>(folder,cc_prog);
if (cc_prog==GCC_PROGRAM && p->compilerType()==COMPILER_CLANG)
return PCompilerSet();
mList.push_back(p); mList.push_back(p);
return p; return p;
} }
@ -2391,15 +2405,11 @@ static void setDebugOptions(Settings::PCompilerSet pSet) {
pSet->setStaticLink(false); pSet->setStaticLink(false);
} }
bool Settings::CompilerSets::addSets(const QString &folder) bool Settings::CompilerSets::addSets(const QString &folder, const QString& cc_prog) {
{
if (!directoryExists(folder))
return false;
if (!fileExists(folder, GCC_PROGRAM) && !fileExists(folder, CLANG_PROGRAM)) {
return false;
}
// Default, release profile // Default, release profile
PCompilerSet baseSet = addSet(folder); PCompilerSet baseSet = addSet(folder,cc_prog);
if (!baseSet)
return false;
QString baseName = baseSet->name(); QString baseName = baseSet->name();
QString platformName; QString platformName;
if (baseSet->target() == "x86_64") { if (baseSet->target() == "x86_64") {
@ -2410,7 +2420,7 @@ bool Settings::CompilerSets::addSets(const QString &folder)
set64_32Options(baseSet); set64_32Options(baseSet);
setReleaseOptions(baseSet); setReleaseOptions(baseSet);
baseSet = addSet(folder); baseSet = addSet(folder,cc_prog);
baseSet->setName(baseName + " " + platformName + " Debug"); baseSet->setName(baseName + " " + platformName + " Debug");
baseSet->setCompilerSetType(CompilerSetType::CST_DEBUG); baseSet->setCompilerSetType(CompilerSetType::CST_DEBUG);
set64_32Options(baseSet); set64_32Options(baseSet);
@ -2422,7 +2432,7 @@ bool Settings::CompilerSets::addSets(const QString &folder)
// set64_32Options(baseSet); // set64_32Options(baseSet);
// setProfileOptions(baseSet); // setProfileOptions(baseSet);
baseSet = addSet(folder); baseSet = addSet(folder,cc_prog);
} }
platformName = "64-bit"; platformName = "64-bit";
} else { } else {
@ -2432,7 +2442,7 @@ bool Settings::CompilerSets::addSets(const QString &folder)
baseSet->setCompilerSetType(CompilerSetType::CST_RELEASE); baseSet->setCompilerSetType(CompilerSetType::CST_RELEASE);
setReleaseOptions(baseSet); setReleaseOptions(baseSet);
baseSet = addSet(folder); baseSet = addSet(folder,cc_prog);
baseSet->setName(baseName + " " + platformName + " Debug"); baseSet->setName(baseName + " " + platformName + " Debug");
baseSet->setCompilerSetType(CompilerSetType::CST_DEBUG); baseSet->setCompilerSetType(CompilerSetType::CST_DEBUG);
setDebugOptions(baseSet); setDebugOptions(baseSet);
@ -2442,8 +2452,26 @@ bool Settings::CompilerSets::addSets(const QString &folder)
// baseSet->setCompilerSetType(CompilerSetType::CST_PROFILING); // baseSet->setCompilerSetType(CompilerSetType::CST_PROFILING);
// setProfileOptions(baseSet); // setProfileOptions(baseSet);
mDefaultIndex = mList.size() - 1; mDefaultIndex = (int)mList.size() - 1;
return true; return true;
}
bool Settings::CompilerSets::addSets(const QString &folder)
{
if (!directoryExists(folder))
return false;
if (!fileExists(folder, GCC_PROGRAM) && !fileExists(folder, CLANG_PROGRAM)) {
return false;
}
if (fileExists(folder, GCC_PROGRAM)) {
addSets(folder,GCC_PROGRAM);
}
if (fileExists(folder, CLANG_PROGRAM)) {
addSets(folder,CLANG_PROGRAM);
}
return true;
} }
void Settings::CompilerSets::clearSets() void Settings::CompilerSets::clearSets()
@ -2559,7 +2587,7 @@ void Settings::CompilerSets::loadSets()
} }
saveSets(); saveSets();
if (pCurrentSet->binDirs().count()>0) { if (pCurrentSet->binDirs().count()>0) {
pCurrentSet->setProperties(pCurrentSet->binDirs()[0]); pCurrentSet->setProperties(pCurrentSet->binDirs()[0],pCurrentSet->CCompiler());
} }
} else { } else {
return; return;

View File

@ -1169,7 +1169,8 @@ public:
class CompilerSet { class CompilerSet {
public: public:
explicit CompilerSet(const QString& compilerFolder = QString()); explicit CompilerSet();
explicit CompilerSet(const QString& compilerFolder, const QString& cc_prog);
explicit CompilerSet(const CompilerSet& set); explicit CompilerSet(const CompilerSet& set);
CompilerSet& operator= (const CompilerSet& ) = delete; CompilerSet& operator= (const CompilerSet& ) = delete;
@ -1182,8 +1183,8 @@ public:
QString getCompileOptionValue(const QString& key); QString getCompileOptionValue(const QString& key);
void setProperties(const QString& binDir); void setProperties(const QString& binDir, const QString& cc_prog);
void setDirectories(const QString& binDir); void setDirectories(const QString& binDir, const QString& cc_prog);
int mainVersion(); int mainVersion();
bool dirsValid(QString& msg); bool dirsValid(QString& msg);
@ -1317,10 +1318,7 @@ public:
class CompilerSets { class CompilerSets {
public: public:
explicit CompilerSets(Settings* settings); explicit CompilerSets(Settings* settings);
PCompilerSet addSet();
PCompilerSet addSet(const CompilerSet& set);
PCompilerSet addSet(const QString& folder=QString());
bool addSets(const QString& folder); bool addSets(const QString& folder);
void clearSets(); void clearSets();
void findSets(); void findSets();
@ -1338,6 +1336,8 @@ public:
QString getKeyFromCompilerCompatibleIndex(int idx) const; QString getKeyFromCompilerCompatibleIndex(int idx) const;
private: private:
PCompilerSet addSet(const QString& folder, const QString& cc_prog);
bool addSets(const QString& folder, const QString& cc_prog);
void savePath(const QString& name, const QString& path); void savePath(const QString& name, const QString& path);
void savePathList(const QString& name, const QStringList& pathList); void savePathList(const QString& name, const QStringList& pathList);