1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 The CodeLite Team
// file name : CMakePlugin.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// 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.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/* ************************************************************************ */
/* */
/* CMakePlugin for Codelite */
/* Copyright (C) 2013 Jiří Fatka <ntsfka@gmail.com> */
/* */
/* 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 3 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, see <http://www.gnu.org/licenses/>. */
/* */
/* ************************************************************************ */
/* ************************************************************************ */
/* INCLUDES */
/* ************************************************************************ */
// Declaration
#include "CMakePlugin.h"
// wxWidgets
#include <wx/app.h>
#include <wx/stdpaths.h>
#include <wx/msgdlg.h>
#include <wx/xrc/xmlres.h>
#include <wx/mimetype.h>
#include <wx/menu.h>
#include <wx/dir.h>
#include <wx/event.h>
#include <wx/busyinfo.h>
// CodeLite
#include "environmentconfig.h"
#include "event_notifier.h"
#include "globals.h"
#include "dirsaver.h"
#include "procutils.h"
#include "project.h"
#include "workspace.h"
#include "build_settings_config.h"
#include "build_config.h"
#include "build_system.h"
#include "file_logger.h"
#include "macromanager.h"
#include "async_executable_cmd.h"
#include "dockablepane.h"
#include "detachedpanesinfo.h"
// CMakePlugin
#include "CMake.h"
#include "CMakeGenerator.h"
#include "CMakeWorkspaceMenu.h"
#include "CMakeProjectMenu.h"
#include "CMakeSettingsDialog.h"
#include "CMakeSettingsManager.h"
#include "CMakeProjectSettings.h"
#include "CMakeProjectSettingsPanel.h"
#include "CMakeGenerator.h"
#include "CMakeHelpTab.h"
/* ************************************************************************ */
/* VARIABLES */
/* ************************************************************************ */
static CMakePlugin* g_plugin = NULL;
/* ************************************************************************ */
const wxString CMakePlugin::CMAKELISTS_FILE = "CMakeLists.txt";
/* ************************************************************************ */
static const wxString HELP_TAB_NAME = "CMake Help";
/* ************************************************************************ */
/* FUNCTIONS */
/* ************************************************************************ */
/**
* @brief Creates plugin.
*
* @param manager Pointer to plugin manager.
*
* @return CMake plugin instance.
*/
extern "C" EXPORT IPlugin* CreatePlugin(IManager* manager)
{
if (!g_plugin) {
g_plugin = new CMakePlugin(manager);
}
return g_plugin;
}
/* ************************************************************************ */
/**
* @brief Returns plugin's info.
*
* @return Plugin info.
*/
extern "C" EXPORT PluginInfo GetPluginInfo()
{
PluginInfo info;
info.SetAuthor(L"Jiří Fatka");
info.SetName("CMakePlugin");
info.SetDescription(_("CMake integration for CodeLite"));
info.SetVersion("0.8");
return info;
}
/* ************************************************************************ */
/**
* @brief Returns required Codelite interface version.
*
* @return Interface version.
*/
extern "C" EXPORT int GetPluginInterfaceVersion()
{
return PLUGIN_INTERFACE_VERSION;
}
/* ************************************************************************ */
/**
* @brief Join arguments for project settings.
*
* @param settings Project settings.
* @param configuration CMakePlugin global configuration.
*
* @return Command line arguments.
*/
static wxString CreateArguments(const CMakeProjectSettings& settings,
const CMakeConfiguration& configuration)
{
wxArrayString args;
// Get generator
wxString generator = settings.generator;
// Use global value
if (generator.IsEmpty())
generator = configuration.GetDefaultGenerator();
// Generator
if (!generator.IsEmpty())
args.Add("-G \"" + generator + "\"");
if (!settings.buildType.IsEmpty())
args.Add("-DCMAKE_BUILD_TYPE=" + settings.buildType);
// Copy additional arguments
for (wxArrayString::const_iterator it = settings.arguments.begin(),
ite = settings.arguments.end(); it != ite; ++it) {
args.Add(*it);
}
return wxJoin(args, ' ', '\0');
}
/* ************************************************************************ */
/* CLASSES */
/* ************************************************************************ */
CMakePlugin::CMakePlugin(IManager* manager)
: IPlugin(manager)
, m_configuration(NULL)
, m_cmake(NULL)
, m_settingsManager(new CMakeSettingsManager(this))
, m_panel(NULL)
{
m_longName = _("CMake integration with CodeLite");
m_shortName = "CMakePlugin";
// Create CMake configuration file
m_configuration.reset(new CMakeConfiguration(wxStandardPaths::Get().
GetUserDataDir() + wxFileName::GetPathSeparator() + "config/cmake.ini")
);
// Create cmake application
m_cmake.reset(new CMake(m_configuration->GetProgramPath()));
Notebook* book = m_mgr->GetWorkspacePaneNotebook();
cmakeImages images;
const wxBitmap &bmp = images.Bitmap("cmake_16");
if (IsPaneDetached()) {
DockablePane* cp = new DockablePane(book->GetParent()->GetParent(), book, HELP_TAB_NAME, bmp, wxSize(200, 200));
cp->SetChildNoReparent(new CMakeHelpTab(cp, this));
} else {
book->AddPage(new CMakeHelpTab(book, this), HELP_TAB_NAME, false, bmp);
}
// Bind events
EventNotifier::Get()->Bind(wxEVT_CMD_PROJ_SETTINGS_SAVED, wxCommandEventHandler(CMakePlugin::OnSaveConfig), this);
EventNotifier::Get()->Bind(wxEVT_GET_PROJECT_BUILD_CMD, clBuildEventHandler(CMakePlugin::OnGetBuildCommand), this);
EventNotifier::Get()->Bind(wxEVT_GET_PROJECT_CLEAN_CMD, clBuildEventHandler(CMakePlugin::OnGetCleanCommand), this);
EventNotifier::Get()->Bind(wxEVT_GET_IS_PLUGIN_MAKEFILE, clBuildEventHandler(CMakePlugin::OnGetIsPluginMakefile), this);
EventNotifier::Get()->Bind(wxEVT_PLUGIN_EXPORT_MAKEFILE, clBuildEventHandler(CMakePlugin::OnExportMakefile), this);
EventNotifier::Get()->Bind(wxEVT_WORKSPACE_LOADED, wxCommandEventHandler(CMakePlugin::OnWorkspaceLoaded), this);
}
/* ************************************************************************ */
CMakePlugin::~CMakePlugin()
{
// Nothing to do
}
/* ************************************************************************ */
wxFileName
CMakePlugin::GetWorkspaceDirectory() const
{
const Workspace* workspace = m_mgr->GetWorkspace();
wxASSERT(workspace);
return wxFileName::DirName(workspace->GetWorkspaceFileName().GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME));
}
/* ************************************************************************ */
wxFileName
CMakePlugin::GetProjectDirectory(const wxString& projectName) const
{
const Workspace* workspace = m_mgr->GetWorkspace();
wxASSERT(workspace);
wxString errMsg;
const ProjectPtr proj = workspace->FindProjectByName(projectName, errMsg);
wxASSERT(proj);
return wxFileName::DirName(proj->GetFileName().GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME));
}
/* ************************************************************************ */
wxString
CMakePlugin::GetSelectedProjectConfig() const
{
BuildConfigPtr configPtr = GetSelectedBuildConfig();
if (configPtr)
return configPtr->GetName();
return wxEmptyString;
}
/* ************************************************************************ */
BuildConfigPtr
CMakePlugin::GetSelectedBuildConfig() const
{
const Workspace* workspace = m_mgr->GetWorkspace();
wxASSERT(workspace);
const ProjectPtr projectPtr = GetSelectedProject();
wxASSERT(projectPtr);
return workspace->GetProjBuildConf(projectPtr->GetName(), wxEmptyString);
}
/* ************************************************************************ */
const CMakeProjectSettings*
CMakePlugin::GetSelectedProjectSettings() const
{
const ProjectPtr projectPtr = GetSelectedProject();
wxASSERT(projectPtr);
const wxString project = projectPtr->GetName();
const wxString config = GetSelectedProjectConfig();
wxASSERT(m_settingsManager);
return m_settingsManager->GetProjectSettings(project, config);
}
/* ************************************************************************ */
bool
CMakePlugin::IsSeletedProjectEnabled() const
{
const CMakeProjectSettings* settings = GetSelectedProjectSettings();
return settings && settings->enabled;
}
/* ************************************************************************ */
wxArrayString
CMakePlugin::GetSupportedGenerators() const
{
wxArrayString generators;
#ifdef __WXMSW__
// Windows supported generators
generators.Add("MinGW Makefiles");
#else
// Linux / Mac supported generators
generators.Add("Unix Makefiles");
//generators.Add("Ninja");
#endif
return generators;
}
/* ************************************************************************ */
bool
CMakePlugin::IsPaneDetached() const
{
wxASSERT(m_mgr);
IConfigTool* configTool = m_mgr->GetConfigTool();
wxASSERT(configTool);
DetachedPanesInfo dpi;
configTool->ReadObject("DetachedPanesList", &dpi);
const wxArrayString& detachedPanes = dpi.GetPanes();
return detachedPanes.Index(HELP_TAB_NAME) != wxNOT_FOUND;
}
/* ************************************************************************ */
clToolBar*
CMakePlugin::CreateToolBar(wxWindow* parent)
{
wxUnusedVar(parent);
return NULL;
}
/* ************************************************************************ */
void
CMakePlugin::CreatePluginMenu(wxMenu* pluginsMenu)
{
wxMenu* menu = new wxMenu();
menu->Append(new wxMenuItem(menu, XRCID("cmake_settings"), _("Settings...")));
pluginsMenu->Append(wxID_ANY, "CMake", menu);
wxTheApp->Bind(wxEVT_COMMAND_MENU_SELECTED, &CMakePlugin::OnSettings, this, XRCID("cmake_settings"));
}
/* ************************************************************************ */
void
CMakePlugin::HookPopupMenu(wxMenu* menu, MenuType type)
{
// Add menu to project menu
if (type == MenuTypeFileView_Project) {
if (!menu->FindItem(XRCID("cmake_project_menu"))) {
menu->PrependSeparator();
menu->Prepend(XRCID("cmake_project_menu"), _("CMake"), new CMakeProjectMenu(this));
}
} else if (type == MenuTypeFileView_Workspace) {
if (!menu->FindItem(XRCID("cmake_workspace_menu"))) {
menu->PrependSeparator();
menu->Prepend(XRCID("cmake_workspace_menu"), _("CMake"), new CMakeWorkspaceMenu(this));
}
}
}
/* ************************************************************************ */
void
CMakePlugin::HookProjectSettingsTab(wxBookCtrlBase* notebook,
const wxString& projectName,
const wxString& configName)
{
wxASSERT(notebook);
/*
* Let's save some memory and use only one panel for all
* configurations.
*/
if (!m_panel) {
wxASSERT(m_mgr);
wxASSERT(m_mgr->GetWorkspace());
// Create panel
m_panel = new CMakeProjectSettingsPanel(notebook, this);
// Add panel to the notebook
notebook->AddPage(m_panel, wxT("CMake"), true);
}
wxASSERT(m_panel);
// Check panel owner
wxASSERT(notebook == m_panel->GetParent());
// It's not exactly good idea to load config everytime
m_settingsManager->LoadProject(projectName);
// Find settings or create new one
m_panel->SetSettings(
m_settingsManager->GetProjectSettings(projectName, configName, true),
projectName,
configName
);
}
/* ************************************************************************ */
void
CMakePlugin::UnHookProjectSettingsTab(wxBookCtrlBase* notebook,
const wxString& projectName,
const wxString& configName)
{
// The configName is empty :(
wxASSERT(notebook);
wxUnusedVar(projectName);
wxUnusedVar(configName);
// Try to find panel
int pos = notebook->FindPage(m_panel);
if (pos != wxNOT_FOUND) {
// Remove and destroy
notebook->RemovePage(pos);
m_panel->Destroy();
m_panel = NULL;
}
}
/* ************************************************************************ */
void
CMakePlugin::UnPlug()
{
wxASSERT(m_mgr);
Notebook* notebook = m_mgr->GetWorkspacePaneNotebook();
wxASSERT(notebook);
size_t pos = notebook->GetPageIndex("CMake Help");
if (pos != Notebook::npos) {
CMakeHelpTab* helpTab = dynamic_cast<CMakeHelpTab*>( notebook->GetPage(pos) );
if ( helpTab ) {
helpTab->Stop();
}
notebook->RemovePage(pos);
}
// Unbind events
wxTheApp->Unbind(wxEVT_COMMAND_MENU_SELECTED, &CMakePlugin::OnSettings, this, XRCID("cmake_settings"));
EventNotifier::Get()->Unbind(wxEVT_CMD_PROJ_SETTINGS_SAVED, wxCommandEventHandler(CMakePlugin::OnSaveConfig), this);
EventNotifier::Get()->Unbind(wxEVT_GET_PROJECT_BUILD_CMD, clBuildEventHandler(CMakePlugin::OnGetBuildCommand), this);
EventNotifier::Get()->Unbind(wxEVT_GET_PROJECT_CLEAN_CMD, clBuildEventHandler(CMakePlugin::OnGetCleanCommand), this);
EventNotifier::Get()->Unbind(wxEVT_GET_IS_PLUGIN_MAKEFILE, clBuildEventHandler(CMakePlugin::OnGetIsPluginMakefile), this);
EventNotifier::Get()->Unbind(wxEVT_PLUGIN_EXPORT_MAKEFILE, clBuildEventHandler(CMakePlugin::OnExportMakefile), this);
EventNotifier::Get()->Unbind(wxEVT_WORKSPACE_LOADED, wxCommandEventHandler(CMakePlugin::OnWorkspaceLoaded), this);
}
/* ************************************************************************ */
bool
CMakePlugin::ExistsCMakeLists(wxFileName directory) const
{
// Add CMakeLists.txt
directory.SetFullName(CMAKELISTS_FILE);
return directory.Exists();
}
/* ************************************************************************ */
void
CMakePlugin::OpenCMakeLists(wxFileName filename) const
{
filename.SetFullName(CMAKELISTS_FILE);
if (!m_mgr->OpenFile(filename.GetFullPath()))
wxMessageBox("Unable to open \"" + filename.GetFullPath() + "\"", wxMessageBoxCaptionStr, wxOK | wxCENTER | wxICON_ERROR);
}
/* ************************************************************************ */
void
CMakePlugin::OnSettings(wxCommandEvent& event)
{
CMakeSettingsDialog dlg(NULL, this);
// Set original value
dlg.SetCMakePath(m_configuration->GetProgramPath());
dlg.SetDefaultGenerator(m_configuration->GetDefaultGenerator());
// Store change
if (dlg.ShowModal() == wxID_OK) {
m_configuration->SetProgramPath(dlg.GetCMakePath());
m_configuration->SetDefaultGenerator(dlg.GetDefaultGenerator());
m_cmake->SetPath(dlg.GetCMakePath());
}
}
/* ************************************************************************ */
void
CMakePlugin::OnSaveConfig(wxCommandEvent& event)
{
event.Skip();
CL_DEBUG("Saving CMake config...");
// Panel doesn't exists
if (!m_panel)
return;
// Get project name
const wxString* proj = reinterpret_cast<wxString*>(event.GetClientData());
wxASSERT(proj);
const wxString project = *proj;
// Store settings into pointer
m_panel->StoreSettings();
wxASSERT(m_settingsManager);
// Save settings
m_settingsManager->SaveProject(project);
}
/* ************************************************************************ */
void
CMakePlugin::OnGetCleanCommand(clBuildEvent& event)
{
ProcessBuildEvent(event, "clean");
}
/* ************************************************************************ */
void
CMakePlugin::OnGetBuildCommand(clBuildEvent& event)
{
ProcessBuildEvent(event);
}
/* ************************************************************************ */
void
CMakePlugin::OnGetIsPluginMakefile(clBuildEvent& event)
{
wxString project = event.GetProjectName();
const wxString config = event.GetConfigurationName();
// Get settings
const CMakeProjectSettings* settings = GetSettingsManager()->GetProjectSettings(project, config);
// Doesn't exists or not enabled
if (!settings || !settings->enabled) {
// Cannot provide custom makefile
event.Skip();
return;
}
// Custom makefile is provided
}
/* ************************************************************************ */
void
CMakePlugin::OnExportMakefile(clBuildEvent& event)
{
const wxString project = event.GetProjectName();
const wxString config = event.GetConfigurationName();
// Get settings
const CMakeProjectSettings* settings = GetSettingsManager()->GetProjectSettings(project, config);
// Doesn't exists or not enabled
if (!settings || !settings->enabled) {
// Unable to export makefile
event.Skip();
return;
}
// Get project directory - this is directory where the makefile is stored
const wxFileName projectDir = GetProjectDirectory(project);
// Targets forward inspired by
// https://gist.github.com/doitian/4978329
// Content of the generated makefile
wxString content = wxString() <<
"# Generated by CMakePlugin\n"
".PHONY: all clean $(MAKECMDGOALS)\n"
"\n"
;
// Parent project is set
if (!settings->parentProject.IsEmpty()) {
// Configure parent project instead
const wxString& parentProject = settings->parentProject;
settings = GetSettingsManager()->GetProjectSettings(parentProject, config);
// Parent project not found
if (!settings || !settings->enabled) {
CL_ERROR("Unable to find or not enabled parent project "
"'" + parentProject + "' for project '" + project + "'");
return;
}
// Get parent project directory
wxFileName parentProjectDir = GetProjectDirectory(parentProject);
parentProjectDir.MakeRelativeTo(projectDir.GetFullPath());
// Path is relative so UNIX path system can be used
const wxString parentProjectDirEsc = parentProjectDir.GetPath(wxPATH_NO_SEPARATOR, wxPATH_UNIX);
// Redirect make to the parent project
content <<
"# Parent project\n"
"PARENT := " << parentProjectDirEsc << "\n"
"PARENT_MAKEFILE := " << parentProject << ".mk\n"
"\n"
"all:\n"
"\t$(MAKE) -C \"$(PARENT)\" -f \"$(PARENT_MAKEFILE)\" " << project << "\n"
"\n"
"clean:\n"
"\t$(MAKE) -C \"$(PARENT)\" -f \"$(PARENT_MAKEFILE)\" " << project << " clean\n"
"\n"
;
} else {
// Macro expander
// FIXME use IMacroManager (unable to find it yet)
MacroManager* macro = MacroManager::Instance();
wxASSERT(macro);
// Get variables
// Expand variables for final project
const wxString cmake = GetConfiguration()->GetProgramPath();
wxFileName sourceDir = wxFileName::DirName(macro->Expand(settings->sourceDirectory, GetManager(), project, config));
wxFileName buildDir = wxFileName::DirName(macro->Expand(settings->buildDirectory, GetManager(), project, config));
// Source dir must be relative to build directory (here is cmake called)
sourceDir.MakeRelativeTo(buildDir.GetFullPath());
// Build dir must be relative to project directory
buildDir.MakeRelativeTo(projectDir.GetFullPath());
// Relative paths
const wxString sourceDirEsc = sourceDir.GetPath(wxPATH_NO_SEPARATOR, wxPATH_UNIX);
const wxString buildDirEsc = buildDir.GetPath(wxPATH_NO_SEPARATOR, wxPATH_UNIX);
// Generated makefile
content <<
"CMAKE := \"" << cmake << "\"\n"
"BUILD_DIR := " << buildDirEsc << "\n"
"SOURCE_DIR := " << sourceDirEsc << "\n"
"CMAKE_ARGS := " << CreateArguments(*settings, *m_configuration.get()) << "\n"
"\n"
"# Building project(s)\n"
"$(or $(lastword $(MAKECMDGOALS)), all): $(BUILD_DIR)/Makefile\n"
"\t$(MAKE) -C \"$(BUILD_DIR)\" $(MAKECMDGOALS)\n"
"\n"
"# Building directory\n"
"$(BUILD_DIR):\n"
"\t$(CMAKE) -E make_directory \"$(BUILD_DIR)\"\n"
"\n"
"# Rule that detects if cmake is called\n"
"$(BUILD_DIR)/Makefile: .cmake_dirty | $(BUILD_DIR)\n"
"\tcd \"$(BUILD_DIR)\" && $(CMAKE) $(CMAKE_ARGS) \"$(SOURCE_DIR)\"\n"
"\n"
"# This rule / file allows force cmake run\n"
".cmake_dirty:\n"
"\t@echo '' > .cmake_dirty\n"
"\n"
;
}
// Path to makefile - called project directory required
wxFileName makefile = projectDir;
makefile.SetName(project);
makefile.SetExt("mk");
// Read old content from disk
wxString oldContent;
bool ok = ReadFileWithConversion(makefile.GetFullPath(), oldContent);
// Write only if there are some changes
if (!ok || content != oldContent) {
// Write make file content
wxFile file(makefile.GetFullPath(), wxFile::write);
if (!file.Write(content)) {
CL_ERROR("Unable to write custom makefile (CMakePlugin): " + makefile.GetFullPath());
}
}
}
/* ************************************************************************ */
void
CMakePlugin::OnWorkspaceLoaded(wxCommandEvent& event)
{
// Allow others to do something
event.Skip();
// Load everything into memory
m_settingsManager->Load();
}
/* ************************************************************************ */
void
CMakePlugin::ProcessBuildEvent(clBuildEvent& event, wxString param)
{
wxString project = event.GetProjectName();
const wxString config = event.GetConfigurationName();
// Get settings
const CMakeProjectSettings* settings = GetSettingsManager()->GetProjectSettings(project, config);
// Doesn't exists or not enabled
if (!settings || !settings->enabled) {
// Unable to export makefile
event.Skip();
return;
}
// Project has parent project
if (!settings->parentProject.IsEmpty()) {
// Add project name as target
param = project + " " + param;
// Build parent project
project = settings->parentProject;
}
// Workspace directory
const wxFileName workspaceDir = GetWorkspaceDirectory();
// Use relative path
wxFileName projectDir = GetProjectDirectory(project);
projectDir.MakeRelativeTo(workspaceDir.GetFullPath());
const wxString projectDirEsc = projectDir.GetPath(wxPATH_NO_SEPARATOR, wxPATH_UNIX);
// Build command
wxString cmd = "$(MAKE)";
if (!projectDirEsc.IsEmpty())
cmd += " -C \"" + projectDirEsc + "\"";
// Add makefile
cmd += " -f \"" + project + ".mk\"";
// Add optional parameters
if (!param.IsEmpty())
cmd += " " + param;
// The build command is simple make call with different makefile
event.SetCommand(cmd);
}
/* ************************************************************************ */
|