bool CompilerLocatorMinGW::Locate() { m_compilers.clear(); m_locatedFolders.clear(); // for wxRegKey #ifdef __WXMSW__ { // HKEY_LOCAL_MACHINE\SOFTWARE\codelite\settings wxRegKey regClMinGW(wxRegKey::HKLM, "SOFTWARE\\codelite\\settings"); wxString clInstallFolder; if ( regClMinGW.QueryValue("MinGW", clInstallFolder) && wxDirExists(clInstallFolder)) { wxFileName gccExe(clInstallFolder, "gcc.exe"); wxString ver; regClMinGW.QueryValue("MinGW_Version", ver); gccExe.AppendDir("bin"); if ( gccExe.FileExists() ) { AddTools(gccExe.GetPath(), "CodeLite-" + ver); } } } { // HKEY_LOCAL_MACHINE\SOFTWARE\codelite\settings wxRegKey regClMinGW(wxRegKey::HKLM, "SOFTWARE\\Wow6432Node\\codelite\\settings"); wxString clInstallFolder; if ( regClMinGW.QueryValue("MinGW", clInstallFolder) && wxDirExists(clInstallFolder)) { wxFileName gccExe(clInstallFolder, "gcc.exe"); wxString ver; regClMinGW.QueryValue("MinGW_Version", ver); gccExe.AppendDir("bin"); if ( gccExe.FileExists() ) { AddTools(gccExe.GetPath(), "CodeLite-" + ver); } } } // Check registry for TDM-GCC-64 wxRegKey regTDM(wxRegKey::HKCU, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TDM-GCC"); wxString tdmInstallFolder; tdmInstallFolder.Clear(); if ( regTDM.QueryValue("InstallLocation", tdmInstallFolder) && wxFileName::DirExists(tdmInstallFolder)) { wxFileName fnTDMBinFolder( tdmInstallFolder, "" ); fnTDMBinFolder.AppendDir("bin"); AddTools(fnTDMBinFolder.GetPath(), "TDM-GCC-64"); } // Check for 32 bit wxRegKey regTDM_32(wxRegKey::HKLM, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TDM-GCC"); tdmInstallFolder.Clear(); if ( regTDM_32.QueryValue("InstallLocation", tdmInstallFolder) && wxFileName::DirExists(tdmInstallFolder)) { wxFileName fnTDMBinFolder( tdmInstallFolder, "" ); fnTDMBinFolder.AppendDir("bin"); AddTools(fnTDMBinFolder.GetPath(), "TDM-GCC-32"); } // locate codeblock's MinGW wxRegKey regCB(wxRegKey::HKCU, "SOFTWARE\\CodeBlocks"); wxString cbInstallPath; if ( regCB.QueryValue("Path", cbInstallPath) ) { wxFileName mingwBinFolder( cbInstallPath, "" ); mingwBinFolder.AppendDir("MinGW"); mingwBinFolder.AppendDir("bin"); if ( mingwBinFolder.DirExists() && wxFileName(mingwBinFolder.GetFullPath(), "gcc.exe").FileExists() ) { AddTools(mingwBinFolder.GetPath(), "Code::Blocks"); } } // Last: many people install MinGW by simply extracting it into the // root folder: // C:\MinGW-X.Y.Z wxArrayString volumes = wxFSVolume::GetVolumes(); wxArrayString mingwFolderArr; // Get list of folders for the volume only for(size_t i=0; i<volumes.GetCount(); ++i) { wxDir dir( volumes.Item(i) ); if ( dir.IsOpened() ) { wxString path; bool cont = dir.GetFirst(&path, "*mingw*", wxDIR_DIRS); while (cont ) { wxString fullpath; fullpath << volumes.Item(i) << path; CL_DEBUG("Found folder containing MinGW: %s", fullpath); mingwFolderArr.Add( fullpath ); cont = dir.GetNext( &path ); } } } for(size_t i=0; i<mingwFolderArr.GetCount(); ++i) { wxString binFolder = FindBinFolder( mingwFolderArr.Item(i) ); if ( binFolder.IsEmpty() ) continue; wxFileName gcc(binFolder, "gcc.exe"); if( gcc.FileExists() ) { AddTools(gcc.GetPath()); } } #endif // try to find MinGW in environment variable PATH (last) wxString pathValues; wxGetEnv("PATH", &pathValues); if ( !pathValues.IsEmpty() ) { wxArrayString pathArray = ::wxStringTokenize(pathValues, wxPATH_SEP, wxTOKEN_STRTOK); for (size_t i = 0; i < pathArray.GetCount(); ++i) { wxFileName gccComp( pathArray.Item(i), "gcc.exe" ); if ( gccComp.GetDirs().Last() == "bin" && gccComp.Exists() ) { // We found gcc.exe wxString pathToGcc = gccComp.GetPath(); pathToGcc.MakeLower(); // Don't mix cygwin and mingw if ( !pathToGcc.Contains("cygwin") ) { AddTools( gccComp.GetPath() ); } } } } return !m_compilers.empty(); }
bool CompilerLocatorMinGW::Locate() { // try to find MinGW in environment variable PATH first wxString pathValues; wxGetEnv("PATH", &pathValues); if ( !pathValues.IsEmpty() ) { wxArrayString pathArray = ::wxStringTokenize(pathValues, wxPATH_SEP, wxTOKEN_STRTOK); for (size_t i = 0; i < pathArray.GetCount(); ++i) { wxFileName gccComp( pathArray.Item(i), "gcc.exe" ); if ( gccComp.GetDirs().Last() == "bin" && gccComp.Exists() ) { // We found gcc.exe CompilerPtr compiler( new Compiler(NULL) ); m_compilers.push_back( compiler ); AddTools( compiler, gccComp.GetPath() ); } } } #ifdef __WXMSW__ // for wxRegKey // Check registry for TDM-GCC // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TDM-GCC wxRegKey regTDM(wxRegKey::HKLM, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TDM-GCC"); wxString tdmInstallFolder; if ( regTDM.QueryValue("InstallLocation", tdmInstallFolder) ) { wxFileName fnTDMBinFolder( tdmInstallFolder, "" ); fnTDMBinFolder.AppendDir("bin"); CompilerPtr compiler( new Compiler(NULL) ); m_compilers.push_back( compiler ); AddTools(compiler, fnTDMBinFolder.GetPath(), "TDM-GCC"); } // 64 bit // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TDM-GCC wxRegKey regTDM_64(wxRegKey::HKLM, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"); if ( regTDM_64.QueryValue("InstallLocation", tdmInstallFolder) ) { wxFileName fnTDMBinFolder( tdmInstallFolder, "" ); fnTDMBinFolder.AppendDir("bin"); CompilerPtr compiler( new Compiler(NULL) ); m_compilers.push_back( compiler ); AddTools(compiler, fnTDMBinFolder.GetPath(), "TDM-GCC-64"); } // locate codeblock's MinGW wxRegKey regCB(wxRegKey::HKCU, "SOFTWARE\\CodeBlocks"); wxString cbInstallPath; if ( regCB.QueryValue("Path", cbInstallPath) ) { wxFileName mingwBinFolder( cbInstallPath, "" ); mingwBinFolder.AppendDir("MinGW"); mingwBinFolder.AppendDir("bin"); if ( mingwBinFolder.DirExists() && wxFileName(mingwBinFolder.GetFullPath(), "gcc.exe").FileExists() ) { CompilerPtr compiler( new Compiler(NULL) ); m_compilers.push_back( compiler ); AddTools(compiler, mingwBinFolder.GetPath(), "Code::Blocks MinGW"); } } // Last: many people install MinGW by simply extracting it into the // root folder: // C:\MinGW-X.Y.Z wxArrayString volumes = wxFSVolume::GetVolumes(); wxArrayString mingwFolderArr; // Get list of folders for the volume only for(size_t i=0; i<volumes.GetCount(); ++i) { wxDir dir( volumes.Item(i) ); if ( dir.IsOpened() ) { wxString path; bool cont = dir.GetFirst(&path, "*mingw*", wxDIR_DIRS); while (cont ) { wxString fullpath; fullpath << volumes.Item(i) << path; CL_DEBUG("Found folder containing MinGW: %s", fullpath); mingwFolderArr.Add( fullpath ); cont = dir.GetNext( &path ); } } } for(size_t i=0; i<mingwFolderArr.GetCount(); ++i) { wxString binFolder = FindBinFolder( mingwFolderArr.Item(i) ); if ( binFolder.IsEmpty() ) continue; wxFileName gcc(binFolder, "gcc.exe"); if( gcc.FileExists() ) { CompilerPtr compiler( new Compiler(NULL) ); m_compilers.push_back( compiler ); AddTools(compiler, gcc.GetPath()); } } #endif return !m_compilers.empty(); }