📄 compilergcc.cpp
字号:
/*
* This file is part of Code::Blocks Studio, an open-source cross-platform IDE
* Copyright (C) 2003 Yiannis An. Mandravellos
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact e-mail: Yiannis An. Mandravellos <mandrav@codeblocks.org>
* Program URL : http://www.codeblocks.org
*
* $Id: compilergcc.cpp,v 1.104.2.1 2005/10/25 07:59:01 mandrav Exp $
* $Date: 2005/10/25 07:59:01 $
*/
#include <sdk.h>
#include "compilergcc.h"
#include <manager.h>
#include <sdk_events.h>
#include <pipedprocess.h>
#include <configmanager.h>
#include <messagemanager.h>
#include <macrosmanager.h>
#include <projectmanager.h>
#include <editormanager.h>
#include <customvars.h>
#include <wx/xrc/xmlres.h>
#include "makefilegenerator.h"
#include "compileroptionsdlg.h"
#include "directcommands.h"
#include "compilerMINGW.h"
// TODO (mandrav#1#): Find out which compilers exist for linux and adapt this
#ifdef __WXMSW__
#include "compilerMSVC.h"
#include "compilerBCC.h"
#include "compilerDMC.h"
#include "compilerOW.h"
#endif
#include "compilerSDCC.h"
#define COLOUR_MAROON wxColour(0xa0, 0x00, 0x00)
#define COLOUR_NAVY wxColour(0x00, 0x00, 0xa0)
CB_IMPLEMENT_PLUGIN(CompilerGCC);
// menu IDS
// just because we don't know other plugins' used identifiers,
// we use wxNewId() to generate a guaranteed unique ID ;), instead of enum
// (don't forget that, especially in a plugin)
int idTimerPollCompiler = XRCID("idTimerPollCompiler");
int idMenuCompile = XRCID("idCompilerMenuCompile");
int idMenuCompileTarget = XRCID("idCompilerMenuCompileTarget");
int idMenuCompileFromProjectManager = XRCID("idCompilerMenuCompileFromProjectManager");
int idMenuProjectCompilerOptions = XRCID("idCompilerMenuProjectCompilerOptions");
int idMenuTargetCompilerOptions = XRCID("idCompilerMenuTargetCompilerOptions");
int idMenuTargetCompilerOptionsSub = XRCID("idCompilerMenuTargetCompilerOptionsSub");
int idMenuCompileTargetFromProjectManager = XRCID("idCompilerMenuCompileTargetFromProjectManager");
int idMenuCompileFile = XRCID("idCompilerMenuCompileFile");
int idMenuCompileFileFromProjectManager = XRCID("idCompilerMenuCompileFileFromProjectManager");
int idMenuRebuild = XRCID("idCompilerMenuRebuild");
int idMenuRebuildTarget = XRCID("idCompilerMenuRebuildTarget");
int idMenuRebuildFromProjectManager = XRCID("idCompilerMenuRebuildFromProjectManager");
int idMenuRebuildTargetFromProjectManager = XRCID("idCompilerMenuRebuildTargetFromProjectManager");
int idMenuCompileAll = XRCID("idCompilerMenuCompileAll");
int idMenuRebuildAll = XRCID("idCompilerMenuRebuildAll");
int idMenuClean = XRCID("idCompilerMenuClean");
int idMenuDistClean = XRCID("idCompilerMenuDistClean");
int idMenuCleanTarget = XRCID("idCompilerMenuCleanTarget");
int idMenuDistCleanTarget = XRCID("idCompilerMenuDistCleanTarget");
int idMenuCleanFromProjectManager = XRCID("idCompilerMenuCleanFromProjectManager");
int idMenuDistCleanFromProjectManager = XRCID("idCompilerMenuDistCleanFromProjectManager");
int idMenuCleanTargetFromProjectManager = XRCID("idCompilerMenuCleanTargetFromProjectManager");
int idMenuDistCleanTargetFromProjectManager = XRCID("idCompilerMenuDistCleanTargetFromProjectManager");
int idMenuCompileAndRun = XRCID("idCompilerMenuCompileAndRun");
int idMenuRun = XRCID("idCompilerMenuRun");
int idMenuKillProcess = XRCID("idCompilerMenuKillProcess");
int idMenuSelectTarget = XRCID("idCompilerMenuSelectTarget");
int idMenuSelectTargetAll = XRCID("idCompilerMenuSelectTargetAll");
int idMenuSelectTargetOther[MAX_TARGETS]; // initialized in ctor
int idMenuNextError = XRCID("idCompilerMenuNextError");
int idMenuPreviousError = XRCID("idCompilerMenuPreviousError");
int idMenuClearErrors = XRCID("idCompilerMenuClearErrors");
int idMenuCreateDist = XRCID("idCompilerMenuCreateDist");
int idMenuExportMakefile = XRCID("idCompilerMenuExportMakefile");
int idMenuSettings = XRCID("idCompilerMenuSettings");
int idToolTarget = XRCID("idToolTarget");
int idToolTargetLabel = XRCID("idToolTargetLabel");
int idGCCProcess = wxNewId();
BEGIN_EVENT_TABLE(CompilerGCC, cbCompilerPlugin)
EVT_UPDATE_UI_RANGE(idMenuCompile, idToolTargetLabel, CompilerGCC::OnUpdateUI)
// these are loaded from the XRC
EVT_UPDATE_UI(XRCID("idCompilerMenuCompile"), CompilerGCC::OnUpdateUI)
EVT_UPDATE_UI(XRCID("idCompilerMenuRebuild"), CompilerGCC::OnUpdateUI)
EVT_UPDATE_UI(XRCID("idCompilerMenuCompileAndRun"), CompilerGCC::OnUpdateUI)
EVT_UPDATE_UI(XRCID("idCompilerMenuRun"), CompilerGCC::OnUpdateUI)
EVT_IDLE( CompilerGCC::OnIdle)
EVT_TIMER(idTimerPollCompiler, CompilerGCC::OnTimer)
EVT_MENU(idMenuRun, CompilerGCC::OnRun)
EVT_MENU(idMenuCompileAndRun, CompilerGCC::OnCompileAndRun)
EVT_MENU(idMenuCompile, CompilerGCC::OnCompile)
EVT_MENU(idMenuCompileFromProjectManager, CompilerGCC::OnCompile)
EVT_MENU(idMenuCompileTargetFromProjectManager, CompilerGCC::OnCompile)
EVT_MENU(idMenuCompileFile, CompilerGCC::OnCompileFile)
EVT_MENU(idMenuCompileFileFromProjectManager, CompilerGCC::OnCompileFile)
EVT_MENU(idMenuRebuild, CompilerGCC::OnRebuild)
EVT_MENU(idMenuRebuildFromProjectManager, CompilerGCC::OnRebuild)
EVT_MENU(idMenuRebuildTargetFromProjectManager, CompilerGCC::OnRebuild)
EVT_MENU(idMenuCompileAll, CompilerGCC::OnCompileAll)
EVT_MENU(idMenuRebuildAll, CompilerGCC::OnRebuildAll)
EVT_MENU(idMenuProjectCompilerOptions, CompilerGCC::OnProjectCompilerOptions)
EVT_MENU(idMenuTargetCompilerOptions, CompilerGCC::OnTargetCompilerOptions)
EVT_MENU(idMenuClean, CompilerGCC::OnClean)
EVT_MENU(idMenuDistClean, CompilerGCC::OnDistClean)
EVT_MENU(idMenuCleanFromProjectManager, CompilerGCC::OnClean)
EVT_MENU(idMenuDistCleanFromProjectManager, CompilerGCC::OnDistClean)
EVT_MENU(idMenuCleanTargetFromProjectManager, CompilerGCC::OnClean)
EVT_MENU(idMenuDistCleanTargetFromProjectManager, CompilerGCC::OnDistClean)
EVT_MENU(idMenuKillProcess, CompilerGCC::OnKillProcess)
EVT_MENU(idMenuSelectTargetAll, CompilerGCC::OnSelectTarget)
EVT_MENU(idMenuNextError, CompilerGCC::OnNextError)
EVT_MENU(idMenuPreviousError, CompilerGCC::OnPreviousError)
EVT_MENU(idMenuClearErrors, CompilerGCC::OnClearErrors)
EVT_MENU(idMenuCreateDist, CompilerGCC::OnCreateDist)
EVT_MENU(idMenuExportMakefile, CompilerGCC::OnExportMakefile)
EVT_MENU(idMenuSettings, CompilerGCC::OnConfig)
EVT_COMBOBOX(idToolTarget, CompilerGCC::OnSelectTarget)
EVT_PROJECT_ACTIVATE(CompilerGCC::OnProjectActivated)
//EVT_PROJECT_POPUP_MENU(CompilerGCC::OnProjectPopupMenu)
EVT_PIPEDPROCESS_STDOUT(idGCCProcess, CompilerGCC::OnGCCOutput)
EVT_PIPEDPROCESS_STDERR(idGCCProcess, CompilerGCC::OnGCCError)
EVT_PIPEDPROCESS_TERMINATED(idGCCProcess, CompilerGCC::OnGCCTerminated)
END_EVENT_TABLE()
CompilerGCC::CompilerGCC()
: m_CompilerIdx(-1),
m_PageIndex(-1),
m_ListPageIndex(-1),
m_Menu(0L),
m_TargetMenu(0L),
m_pToolbar(0L),
m_TargetIndex(-1),
m_ErrorsMenu(0L),
m_Project(0L),
m_Process(0L),
m_pTbar(0L),
m_Pid(0),
m_Log(0L),
m_pListLog(0L),
m_ToolTarget(0L),
m_ToolTargetLabel(0L),
m_IsRun(false),
m_RunAfterCompile(false),
m_DoAllProjects(mpjNone),
m_BackupActiveProject(0L),
m_ProjectIndex(0),
m_LastExitCode(0),
m_HasTargetAll(false),
m_QueueIndex(0),
m_DeleteTempMakefile(true)
{
Manager::Get()->Loadxrc(_T("/compiler_gcc.zip#zip:*.xrc"));
m_Type = ptCompiler;
m_PluginInfo.name = _T("Compiler");
m_PluginInfo.title = _T("Compiler");
m_PluginInfo.version = _T("1.0");
m_PluginInfo.description = _("This plugin is an interface to various compilers:\n\n"
"\tGNU GCC compiler\n"
"\tMicrosoft Visual C++ Free Toolkit 2003\n"
"\tBorland C++ Compiler 5.5");
m_PluginInfo.author = _T("Yiannis An. Mandravellos");
m_PluginInfo.authorEmail = _T("info@codeblocks.org");
m_PluginInfo.authorWebsite = _T("www.codeblocks.org");
m_PluginInfo.thanksTo = _("All the free (and not) compilers out there");
m_PluginInfo.hasConfigure = false;
m_timerIdleWakeUp.SetOwner(this, idTimerPollCompiler);
for (int i = 0; i < MAX_TARGETS; ++i)
idMenuSelectTargetOther[i] = wxNewId();
#ifndef __WXMSW__
m_ConsoleShell = ConfigManager::Get()->Read(_T("/compiler_gcc/console_shell"), DEFAULT_CONSOLE_SHELL);
#endif
// register built-in compilers
CompilerFactory::RegisterCompiler(new CompilerMINGW);
#ifdef __WXMSW__
CompilerFactory::RegisterCompiler(new CompilerMSVC);
CompilerFactory::RegisterCompiler(new CompilerBCC);
CompilerFactory::RegisterCompiler(new CompilerDMC);
CompilerFactory::RegisterCompiler(new CompilerOW);
#endif
CompilerFactory::RegisterCompiler(new CompilerSDCC);
// register (if any) user-copies of built-in compilers
CompilerFactory::RegisterUserCompilers();
ConfigManager::AddConfiguration(m_PluginInfo.title, _T("/compiler_gcc"));
}
CompilerGCC::~CompilerGCC()
{
DoDeleteTempMakefile();
if (m_ToolTarget)
delete m_ToolTarget;
CompilerFactory::UnregisterCompilers();
}
void CompilerGCC::OnAttach()
{
wxFont font(8, wxMODERN, wxNORMAL, wxNORMAL);
MessageManager* msgMan = Manager::Get()->GetMessageManager();
// create compiler's log
m_Log = new SimpleTextLog(msgMan, _("Build log"));
m_Log->GetTextControl()->SetFont(font);
m_PageIndex = msgMan->AddLog(m_Log);
// set log image
wxBitmap bmp;
wxString prefix = ConfigManager::Get()->Read(_T("data_path")) + _T("/images/");
bmp.LoadFile(prefix + _T("misc_16x16.png"), wxBITMAP_TYPE_PNG);
Manager::Get()->GetMessageManager()->SetLogImage(m_Log, bmp);
// create warnings/errors log
wxArrayString titles;
int widths[3] = {128, 48, 640};
titles.Add(_("File"));
titles.Add(_("Line"));
titles.Add(_("Message"));
m_pListLog = new CompilerMessages(msgMan, _("Build messages"), 3, widths, titles);
m_pListLog->SetCompilerErrors(&m_Errors);
m_pListLog->GetListControl()->SetFont(font);
m_ListPageIndex = msgMan->AddLog(m_pListLog);
// set log image
bmp.LoadFile(prefix + _T("flag_16x16.png"), wxBITMAP_TYPE_PNG);
Manager::Get()->GetMessageManager()->SetLogImage(m_pListLog, bmp);
// set default compiler for new projects
CompilerFactory::SetDefaultCompilerIndex(ConfigManager::Get()->Read(_T("/compiler_gcc/default_compiler"), (long int)0));
LoadOptions();
SetupEnvironment();
}
void CompilerGCC::OnRelease(bool appShutDown)
{
DoDeleteTempMakefile();
SaveOptions();
ConfigManager::Get()->Write(_T("/compiler_gcc/default_compiler"), CompilerFactory::GetDefaultCompilerIndex());
if (Manager::Get()->GetMessageManager())
{
Manager::Get()->GetMessageManager()->DeletePage(m_ListPageIndex);
Manager::Get()->GetMessageManager()->DeletePage(m_PageIndex);
}
if (appShutDown)
return; // no need to continue if app is shutting down
DoClearTargetMenu();
// if (m_Menu)
// {
// wxMenuBar* mBar = Manager::Get()->GetAppWindow()->GetMenuBar();
// int pos = mBar->FindMenu(_("&Compile"));
// if (pos != wxNOT_FOUND)
// mBar->Remove(pos);
// delete m_Menu;
// m_Menu = 0L;
// }
if (m_pToolbar)
{
m_pToolbar->DeleteTool(idMenuCompile);
m_pToolbar->DeleteTool(idMenuRun);
m_pToolbar->DeleteTool(idMenuCompileAndRun);
m_pToolbar->DeleteTool(idMenuRebuild);
m_pToolbar->DeleteTool(idToolTarget);
delete m_ToolTarget;
m_ToolTarget = 0L;
m_pToolbar->DeleteTool(idToolTargetLabel);
delete m_ToolTargetLabel;
m_ToolTargetLabel = 0L;
}
}
int CompilerGCC::Configure(cbProject* project, ProjectBuildTarget* target)
{
CompilerOptionsDlg dlg(Manager::Get()->GetAppWindow(), this, project, target);
if(dlg.ShowModal()==wxID_OK)
{
m_ConsoleShell = ConfigManager::Get()->Read(_T("/compiler_gcc/console_shell"), DEFAULT_CONSOLE_SHELL);
SaveOptions();
SetupEnvironment();
}
return 0;
}
void CompilerGCC::OnConfig(wxCommandEvent& event)
{
Configure(NULL);
}
void CompilerGCC::BuildMenu(wxMenuBar* menuBar)
{
if (!m_IsAttached)
return;
if (m_Menu)
return;
m_Menu=Manager::Get()->LoadMenu(_T("compiler_menu"),true);
// target selection menu
wxMenuItem *tmpitem=m_Menu->FindItem(idMenuSelectTarget,NULL);
m_TargetMenu = tmpitem ? tmpitem->GetSubMenu() : new wxMenu(_T(""));
DoRecreateTargetMenu();
//m_Menu->Append(idMenuSelectTarget, _("Select target..."), m_TargetMenu);
// ok, now, where do we insert?
// three possibilities here:
// a) locate "Debug" menu and insert before it
// b) locate "Project" menu and insert after it
// c) if not found (?), insert at pos 5
int finalPos = 5;
int projMenuPos = menuBar->FindMenu(_("&Debug"));
if (projMenuPos != wxNOT_FOUND)
finalPos = projMenuPos;
else
{
projMenuPos = menuBar->FindMenu(_("&Project"));
if (projMenuPos != wxNOT_FOUND)
finalPos = projMenuPos + 1;
}
menuBar->Insert(finalPos, m_Menu, _("&Build"));
// now add some entries in Project menu
projMenuPos = menuBar->FindMenu(_("&Project"));
if (projMenuPos != wxNOT_FOUND)
{
wxMenu* prj = menuBar->GetMenu(projMenuPos);
// look if we have a "Properties" item. If yes, we 'll insert
// before it, else we 'll just append...
size_t propsPos = prj->GetMenuItemCount(); // append
int propsID = prj->FindItem(_("Properties"));
if (propsID != wxNOT_FOUND)
prj->FindChildItem(propsID, &propsPos);
prj->Insert(propsPos, idMenuProjectCompilerOptions, _("Build options"), _("Set the project's build options"));
prj->InsertSeparator(propsPos);
}
// Add entry in settings menu (outside "plugins")
int settingsMenuPos = menuBar->FindMenu(_("&Settings"));
if (settingsMenuPos != wxNOT_FOUND)
{
wxMenu* settingsmenu = menuBar->GetMenu(settingsMenuPos);
settingsmenu->Insert(2,idMenuSettings,_("&Compiler"),_("Global Compiler Options"));
}
}
void CompilerGCC::BuildModuleMenu(const ModuleType type, wxMenu* menu, const wxString& arg)
{
if (!m_IsAttached)
return;
// we 're only interested in project manager's menus
if (type != mtProjectManager || !menu || m_Process)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -