bool CompilerLocatorGCC::Locate()
{
    // Locate GCC under /usr/bin
    m_compilers.clear();

    wxArrayString gcc_versions;
    gcc_versions.Add(""); // Default gcc
    gcc_versions.Add("4.2");
    gcc_versions.Add("4.3");
    gcc_versions.Add("4.4");
    gcc_versions.Add("4.5");
    gcc_versions.Add("4.6");
    gcc_versions.Add("4.7");
    gcc_versions.Add("4.8");
    gcc_versions.Add("4.9");

    for(size_t i=0; i<gcc_versions.GetCount(); ++i) {
        wxString suffix = gcc_versions.Item(i);
        if ( !suffix.IsEmpty() ) {
            suffix.Prepend("-");
        }

        wxFileName gccFile("/usr/bin", "gcc" + suffix);
        if ( gccFile.FileExists() ) {
            // add this compiler
            CompilerPtr compiler( new Compiler(NULL) );
            wxString toolchainName;
            toolchainName << "GCC";
            if ( !gcc_versions.Item(i).IsEmpty() ) {
                toolchainName << " ( " << gcc_versions.Item(i) << " )";
            }
            compiler->SetName( toolchainName );
            compiler->SetGenerateDependeciesFile(true);
            compiler->SetCompilerFamily(COMPILER_FAMILY_GCC);
            m_compilers.push_back( compiler );
            AddTools(compiler, "/usr/bin", gcc_versions.Item(i));
        }
    }

    // XCode GCC is installed under /Applications/Xcode.app/Contents/Developer/usr/bin
    wxFileName xcodeGcc("/Applications/Xcode.app/Contents/Developer/usr/bin", "gcc");
    if ( xcodeGcc.FileExists() ) {
        // add this compiler
        CompilerPtr compiler( new Compiler(NULL) );
        compiler->SetCompilerFamily(COMPILER_FAMILY_GCC);
        compiler->SetName("GCC ( XCode )");
        m_compilers.push_back( compiler );
        AddTools(compiler, xcodeGcc.GetPath());
    }

    return !m_compilers.empty();
}
bool CompilerLocatorMSVC12::Locate()
{
    m_compilers.clear();
    
    // We locate it by searching for the environment variable
    // %VS120COMNTOOLS%
    wxString path = ::wxGetenv("VS120COMNTOOLS");
    if ( path.IsEmpty() ) {
        return false;
    }
    
    // We found the installation path
    // Go to 1 folder up
    wxFileName masterPath(path, "");
    wxFileName binPath( masterPath );
    binPath.RemoveLastDir();
    binPath.RemoveLastDir();
    binPath.AppendDir("VC");
    binPath.AppendDir("bin");
    
    wxFileName cl(binPath.GetPath(), "cl.exe");
    if ( !cl.FileExists() ) {
        return false;
    }
    
    // Add the tools
    AddTools(masterPath.GetPath(), "Visual C++ 12");
    return true;
}
CompilerPtr CompilerLocatorCrossGCC::Locate(const wxString& folder, bool clear)
{
    if(clear) {
        m_compilers.clear();
    }

    wxArrayString matches;
    wxFileName fnFolder(folder, "");

    // We collect "*-gcc" files
    wxString pattern = "*-gcc";
#ifdef __WXMSW__
    pattern << ".exe";
#endif

    int count = wxDir::GetAllFiles(fnFolder.GetPath(), &matches, pattern, wxDIR_FILES);
    if(count == 0) {
        // try to see if we have a 'bin' folder under 'folder'
        fnFolder.AppendDir("bin");
        if(wxDir::Exists(fnFolder.GetPath())) {
            count = wxDir::GetAllFiles(fnFolder.GetPath(), &matches, pattern, wxDIR_FILES);
        }
    }

    if(count == 0) return NULL;

    for(int i = 0; i < count; ++i) {
#ifndef __WXMSW__
        // Check if this is a script
        char sha[2];
        wxFile(matches[i]).Read(sha, 2);
        if(strncmp(sha, "#!", 2) == 0) {
            continue;
        }
#endif
        wxFileName filename(matches.Item(i));
        if(filename.GetName() == "mingw32-gcc" || filename.GetName() == "x86_64-w64-mingw32-gcc") {
            // Don't include standard mingw32-gcc (32 and 64 bit) binaries
            // they will be picked up later by the MinGW locator
            continue;
        }

        CompilerPtr compiler(new Compiler(NULL));
        compiler->SetCompilerFamily(COMPILER_FAMILY_GCC);

        // get the compiler version
        compiler->SetName(filename.GetName());
        compiler->SetGenerateDependeciesFile(true);
        m_compilers.push_back(compiler);

        // we path the bin folder
        AddTools(compiler, filename.GetPath(), filename.GetName().BeforeLast('-'), filename.GetExt());
    }

    if(m_compilers.empty()) {
        return NULL;
    } else {
        return *m_compilers.begin();
    }
}
void CompilerLocatorCLANG::MSWLocate()
{
#ifdef __WXMSW__
    bool found = false;
    {
        wxRegKey reg(wxRegKey::HKCU, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\LLVM");
        wxString llvmInstallPath;
        wxString llvmVersion;
        if ( reg.Exists() ) {
            found = true;
            reg.QueryValue("DisplayIcon",    llvmInstallPath);
            reg.QueryValue("DisplayVersion", llvmVersion);

            CompilerPtr compiler( new Compiler(NULL) );
            compiler->SetCompilerFamily(COMPILER_FAMILY_CLANG);
            compiler->SetGenerateDependeciesFile(true);
            compiler->SetName( wxString() << "clang ( " << llvmVersion << " )");
            m_compilers.push_back( compiler );
            AddTools(compiler, llvmInstallPath);
        }
    }
    if ( !found ) {
        wxRegKey reg(wxRegKey::HKLM, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\LLVM");
        wxString llvmInstallPath;
        wxString llvmVersion;
        if ( reg.Exists() ) {
            reg.QueryValue("DisplayIcon",    llvmInstallPath);
            reg.QueryValue("DisplayVersion", llvmVersion);

            CompilerPtr compiler( new Compiler(NULL) );
            compiler->SetCompilerFamily(COMPILER_FAMILY_CLANG);
            compiler->SetGenerateDependeciesFile(true);
            compiler->SetName( wxString() << "clang ( " << llvmVersion << " )");
            m_compilers.push_back( compiler );
            AddTools(compiler, llvmInstallPath);
        }
    }
#endif

}
CompilerPtr CompilerLocatorCLANG::Locate(const wxString& folder)
{
    m_compilers.clear();
    wxFileName clang(folder, "clang");
#ifdef __WXMSW__
    clang.SetExt("exe");
#endif
    bool found = clang.FileExists();
    if ( ! found ) {
        // try to see if we have a bin folder here
        clang.AppendDir("bin");
        found = clang.FileExists();
    }
    
    if ( found ) {
        CompilerPtr compiler( new Compiler(NULL) );
        compiler->SetCompilerFamily(COMPILER_FAMILY_CLANG);
        // get the compiler version
        compiler->SetName( GetCompilerFullName(clang.GetFullPath() ) );
        compiler->SetGenerateDependeciesFile(true);
        m_compilers.push_back( compiler );
        clang.RemoveLastDir();
        AddTools(compiler, clang.GetPath());
        
        // Update the toolchain (if Windows)
#ifdef __WXMSW__
        CompilerPtr defaultMinGWCmp = BuildSettingsConfigST::Get()->GetDefaultCompiler(COMPILER_FAMILY_MINGW);
        if ( defaultMinGWCmp ) {
            compiler->SetTool("MAKE", defaultMinGWCmp->GetTool("MAKE"));
            compiler->SetTool("ResourceCompiler", defaultMinGWCmp->GetTool("ResourceCompiler"));
            
            // Update the include paths
            IncludePathLocator locator(NULL);
            wxArrayString includePaths, excludePaths;
            locator.Locate(includePaths, excludePaths, false, defaultMinGWCmp->GetTool("CXX"));
            
            // Convert the include paths to semi colon separated list
            wxString mingwIncludePaths = wxJoin(includePaths, ';');
            compiler->SetGlobalIncludePath( mingwIncludePaths );
        }
#endif
        return compiler;
    }
    return NULL;
}
bool CompilerLocatorCLANG::Locate()
{
    m_compilers.clear();
    MSWLocate();

    // POSIX locate
    wxFileName clang("/usr/bin", "clang");
    if ( clang.FileExists() ) {
        CompilerPtr compiler( new Compiler(NULL) );
        compiler->SetCompilerFamily(COMPILER_FAMILY_CLANG);
        // get the compiler version
        compiler->SetName( GetCompilerFullName(clang.GetFullPath() ) );
        compiler->SetGenerateDependeciesFile(true);
        m_compilers.push_back( compiler );
        clang.RemoveLastDir();
        AddTools(compiler, clang.GetPath());
    }
    return true;
}
CompilerPtr CompilerLocatorMinGW::Locate(const wxString& folder)
{
    m_compilers.clear();
    wxFileName gcc(folder, "gcc");
#ifdef __WXMSW__
    gcc.SetExt("exe");
#endif

    bool found = gcc.FileExists();
    if ( ! found ) {
        // try to see if we have a bin folder here
        gcc.AppendDir("bin");
        found = gcc.FileExists();
    }
    
    if ( found ) {
        AddTools(gcc.GetPath(), GetGCCVersion(gcc.GetFullPath() ));
        return *m_compilers.begin();
    }
    return NULL;
}
CompilerPtr CompilerLocatorGCC::Locate(const wxString& folder)
{
    m_compilers.clear();
    wxFileName gcc(folder, "gcc");
    wxFileName tmpfn(folder, "");
    
    wxString name;
    if( tmpfn.GetDirCount() > 1 && tmpfn.GetDirs().Last() == "bin" ) {
        tmpfn.RemoveLastDir();
        name = tmpfn.GetDirs().Last();
    }
    
#ifdef __WXMSW__
    gcc.SetExt("exe");
#endif

    bool found = gcc.FileExists();
    if ( ! found ) {
        // try to see if we have a bin folder here
        gcc.AppendDir("bin");
        found = gcc.FileExists();
    }
    
    if ( found ) {
        CompilerPtr compiler( new Compiler(NULL) );
        compiler->SetCompilerFamily(COMPILER_FAMILY_GCC);
        
        // get the compiler version
        compiler->SetName( name.IsEmpty() ? "GCC" : name );
        compiler->SetGenerateDependeciesFile(true);
        m_compilers.push_back( compiler );
        
        // we path the bin folder
        AddTools(compiler, gcc.GetPath());
        return compiler;
    }
    return NULL;
}
CompilerPtr CompilerLocatorCygwin::Locate(const wxString& folder)
{
    m_compilers.clear();
    
    wxString binFolder;
    wxFileName gcc(folder, "gcc.exe");
    if ( gcc.FileExists() ) {
        binFolder = gcc.GetPath();
    } else {
        gcc.AppendDir("bin");
        if ( gcc.FileExists() ) {
            binFolder = gcc.GetPath();
        }
    }
    
    if ( binFolder.IsEmpty() )
        return NULL;
    
    wxArrayString suffixes = GetSuffixes(binFolder);
    if ( suffixes.IsEmpty() )
        return NULL;
    
    for(size_t i=0; i<suffixes.GetCount(); ++i) {
        gcc.SetFullName( "gcc-" + suffixes.Item(i) + ".exe" );
        wxString gccVer = GetGCCVersion( gcc.GetFullPath() );

        wxString compilerName;
        compilerName << "Cygwin";
        if ( !gccVer.IsEmpty() ) {
            compilerName <<  " - " << gccVer;
        }
        // Add the tools (use the bin folder)
        AddTools(gcc.GetPath(), compilerName, suffixes.Item(i));
    }
    return m_compilers.at(0);
}
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();
}
Example #11
0
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();
}