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
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2008 by Eran Ifrah
// file name : compiler.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.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#include "compiler.h"
#include "xmlutils.h"
#include <wx/log.h>
#include "macros.h"
#include "wx_xml_compatibility.h"
#include "build_system.h"
#include "build_settings_config.h"
#include <ICompilerLocator.h>
#include <wx/regex.h>
#include <procutils.h>
#include "globals.h"
#include <wx/tokenzr.h>
Compiler::Compiler(wxXmlNode *node, Compiler::eRegexType regexType)
: m_objectNameIdenticalToFileName(false)
, m_isDefault(false)
{
// ensure all relevant entries exist in switches map (makes sure they show up in build settings dlg)
SetSwitch("Include", "");
SetSwitch("Debug", "");
SetSwitch("Preprocessor", "");
SetSwitch("Library", "");
SetSwitch("LibraryPath", "");
SetSwitch("Source", "");
SetSwitch("Output", "");
SetSwitch("Object", "");
SetSwitch("ArchiveOutput", "");
SetSwitch("PreprocessOnly","");
// ensure all relevant entries exist in tools map (makes sure they show up in build settings dlg)
SetTool("LinkerName", "");
SetTool("SharedObjectLinkerName", "");
SetTool("CXX", "");
SetTool("CC", "");
SetTool("AR", "");
SetTool("ResourceCompiler", "");
SetTool("MAKE", "");
SetTool("AS", "as"); // Assembler, default to as
m_fileTypes.clear();
if (node) {
m_name = XmlUtils::ReadString(node, wxT("Name"));
m_compilerFamily = XmlUtils::ReadString(node, "CompilerFamily");
if ( m_compilerFamily == "GNU GCC" ) {
// fix wrong name
m_compilerFamily = COMPILER_FAMILY_GCC;
}
m_isDefault = XmlUtils::ReadBool(node, "IsDefault");
if (!node->HasProp(wxT("GenerateDependenciesFiles"))) {
if (m_name == wxT("gnu g++") || m_name == wxT("gnu gcc")) {
m_generateDependeciesFile = true;
} else
m_generateDependeciesFile = false;
} else {
m_generateDependeciesFile = XmlUtils::ReadBool(node, wxT("GenerateDependenciesFiles"));
}
if (!node->HasProp(wxT("ReadObjectsListFromFile"))) {
m_readObjectFilesFromList = true;
} else {
m_readObjectFilesFromList = XmlUtils::ReadBool(node, wxT("ReadObjectsListFromFile"));
}
m_objectNameIdenticalToFileName = XmlUtils::ReadBool(node, wxT("ObjectNameIdenticalToFileName"));
wxXmlNode *child = node->GetChildren();
while (child) {
if (child->GetName() == wxT("Switch")) {
m_switches[XmlUtils::ReadString(child, wxT("Name"))] = XmlUtils::ReadString(child, wxT("Value"));
}
else if (child->GetName() == wxT("Tool")) {
m_tools[XmlUtils::ReadString(child, wxT("Name"))] = XmlUtils::ReadString(child, wxT("Value"));
}
else if (child->GetName() == wxT("Option")) {
wxString name = XmlUtils::ReadString(child, wxT("Name"));
if (name == wxT("ObjectSuffix")) {
m_objectSuffix = XmlUtils::ReadString(child, wxT("Value"));
} else if (name == wxT("DependSuffix")) {
m_dependSuffix = XmlUtils::ReadString(child, wxT("Value"));
} else if (name == wxT("PreprocessSuffix")) {
m_preprocessSuffix = XmlUtils::ReadString(child, wxT("Value"));
}
} else if (child->GetName() == wxT("File")) {
Compiler::CmpFileTypeInfo ft;
ft.compilation_line = XmlUtils::ReadString(child, wxT("CompilationLine"));
ft.extension = XmlUtils::ReadString(child, wxT("Extension")).Lower();
long kind = (long)CmpFileKindSource;
if (XmlUtils::ReadLong(child, wxT("Kind"), kind) == CmpFileKindSource) {
ft.kind = CmpFileKindSource;
} else {
ft.kind = CmpFileKindResource;
}
m_fileTypes[ft.extension] = ft;
}
else if (child->GetName() == wxT("Pattern")) {
if (XmlUtils::ReadString(child, wxT("Name")) == wxT("Error")) {
//found an error description
CmpInfoPattern errPattern;
errPattern.fileNameIndex = XmlUtils::ReadString(child, wxT("FileNameIndex"));
errPattern.lineNumberIndex = XmlUtils::ReadString(child, wxT("LineNumberIndex"));
errPattern.pattern = child->GetNodeContent();
m_errorPatterns.push_back(errPattern);
} else if (XmlUtils::ReadString(child, wxT("Name")) == wxT("Warning")) {
//found a warning description
CmpInfoPattern warnPattern;
warnPattern.fileNameIndex = XmlUtils::ReadString(child, wxT("FileNameIndex"));
warnPattern.lineNumberIndex = XmlUtils::ReadString(child, wxT("LineNumberIndex"));
warnPattern.pattern = child->GetNodeContent();
m_warningPatterns.push_back(warnPattern);
}
}
else if (child->GetName() == wxT("GlobalIncludePath")) {
m_globalIncludePath = child->GetNodeContent();
}
else if (child->GetName() == wxT("GlobalLibPath")) {
m_globalLibPath = child->GetNodeContent();
}
else if (child->GetName() == wxT("PathVariable")) {
m_pathVariable = child->GetNodeContent();
}
else if (child->GetName() == wxT("CompilerOption")) {
CmpCmdLineOption cmpOption;
cmpOption.name = XmlUtils::ReadString(child, wxT("Name"));
cmpOption.help = child->GetNodeContent();
m_compilerOptions[cmpOption.name] = cmpOption;
}
else if (child->GetName() == wxT("LinkerOption")) {
CmpCmdLineOption cmpOption;
cmpOption.name = XmlUtils::ReadString(child, wxT("Name"));
cmpOption.help = child->GetNodeContent();
m_linkerOptions[cmpOption.name] = cmpOption;
}
else if (child->GetName() == wxT("InstallationPath")) {
m_installationPath = child->GetNodeContent();
}
child = child->GetNext();
}
if ( GetTool("MAKE").IsEmpty() ) {
BuilderConfigPtr bldr = BuildSettingsConfigST::Get()->GetBuilderConfig("");
if ( bldr ) {
SetTool("MAKE", wxString() << bldr->GetToolPath() << " -j " << bldr->GetToolJobs());
}
}
// Default values for the assembler
if ( GetTool("AS").IsEmpty() && GetName().CmpNoCase("vc++") == 0 ) {
SetTool("AS", "nasm");
} else if ( GetTool("AS").IsEmpty() ) {
SetTool("AS", "as");
}
// For backward compatibility, if the compiler / linker options are empty - add them
if ( IsGnuCompatibleCompiler() && m_compilerOptions.empty() ) {
AddDefaultGnuComplierOptions();
}
if ( IsGnuCompatibleCompiler() && m_linkerOptions.empty() ) {
AddDefaultGnuLinkerOptions();
}
} else {
// Create a default compiler: g++
m_name = "";
m_compilerFamily = COMPILER_FAMILY_GCC;
m_isDefault = false;
SetSwitch("Include", "-I");
SetSwitch("Debug", "-g ");
SetSwitch("Preprocessor", "-D");
SetSwitch("Library", "-l");
SetSwitch("LibraryPath", "-L");
SetSwitch("Source", "-c ");
SetSwitch("Output", "-o ");
SetSwitch("Object", "-o ");
SetSwitch("ArchiveOutput", " ");
SetSwitch("PreprocessOnly", "-E");
m_objectSuffix = ".o";
m_preprocessSuffix = ".i";
if ( regexType == kRegexGNU ) {
AddPattern(eErrorPattern, "^([^ ][a-zA-Z:]{0,2}[ a-zA-Z\\.0-9_/\\+\\-]+ *)(:)([0-9]*)([:0-9]*)(: )((fatal error)|(error)|(undefined reference))", 1, 3);
AddPattern(eErrorPattern, "^([^ ][a-zA-Z:]{0,2}[ a-zA-Z\\.0-9_/\\+\\-]+ *)(:)([^ ][a-zA-Z:]{0,2}[ a-zA-Z\\.0-9_/\\+\\-]+ *)(:)(\\(\\.text\\+[0-9a-fx]*\\))", 3, 1);
AddPattern(eErrorPattern, "^([^ ][a-zA-Z:]{0,2}[ a-zA-Z\\.0-9_/\\+\\-]+ *)(:)([^ ][a-zA-Z:]{0,2}[ a-zA-Z\\.0-9_/\\+\\-]+ *)(:)([0-9]+)(:)", 3, 1);
AddPattern(eErrorPattern, "undefined reference to", -1, -1);
AddPattern(eErrorPattern, "\\*\\*\\* \\[[a-zA-Z\\-_0-9 ]+\\] (Error)", -1, -1);
AddPattern(eWarningPattern, "([a-zA-Z:]{0,2}[ a-zA-Z\\.0-9_/\\+\\-]+ *)(:)([0-9]+ *)(:)([0-9:]*)?( warning)", 1, 3);
AddPattern(eWarningPattern, "([a-zA-Z:]{0,2}[ a-zA-Z\\.0-9_/\\+\\-]+ *)(:)([0-9]+ *)(:)([0-9:]*)?( note)", 1, 3);
AddPattern(eWarningPattern, "([a-zA-Z:]{0,2}[ a-zA-Z\\.0-9_/\\+\\-]+ *)(:)([0-9]+ *)(:)([0-9:]*)?([ ]+instantiated)", 1, 3);
AddPattern(eWarningPattern, "(In file included from *)([a-zA-Z:]{0,2}[ a-zA-Z\\.0-9_/\\+\\-]+ *)(:)([0-9]+ *)(:)([0-9:]*)?", 2, 4);
AddDefaultGnuComplierOptions();
AddDefaultGnuLinkerOptions();
} else {
AddPattern(eErrorPattern, "^windres: ([a-zA-Z:]{0,2}[ a-zA-Z\\\\.0-9_/\\+\\-]+) *:([0-9]+): syntax error", 1, 2);
AddPattern(eErrorPattern, "(^[a-zA-Z\\\\.0-9 _/\\:\\+\\-]+ *)(\\()([0-9]+)(\\))( \\: )(error)", 1, 3);
AddPattern(eErrorPattern, "(LINK : fatal error)", 1, 1);
AddPattern(eErrorPattern, "(NMAKE : fatal error)", 1, 1);
AddPattern(eWarningPattern, "(^[a-zA-Z\\\\.0-9 _/\\:\\+\\-]+ *)(\\()([0-9]+)(\\))( \\: )(warning)", 1, 3);
AddPattern(eWarningPattern, "([a-z_A-Z]*\\.obj)( : warning)", 1, 1);
AddPattern(eWarningPattern, "(cl : Command line warning)", 1, 1);
}
SetTool("LinkerName", "g++");
#ifdef __WXMAC__
SetTool("SharedObjectLinkerName", "g++ -dynamiclib -fPIC");
#else
SetTool("SharedObjectLinkerName", "g++ -shared -fPIC");
#endif
SetTool("CXX", "g++");
SetTool("CC", "gcc");
SetTool("AR", "ar rcu");
SetTool("ResourceCompiler", "windres");
SetTool("AS", "as");
#ifdef __WXMSW__
SetTool("MAKE", "mingw32-make");
#else
SetTool("MAKE", "make");
#endif
m_globalIncludePath = wxEmptyString;
m_globalLibPath = wxEmptyString;
m_pathVariable = wxEmptyString;
m_generateDependeciesFile = false;
m_readObjectFilesFromList = true;
m_objectNameIdenticalToFileName = false;
}
if (m_generateDependeciesFile && m_dependSuffix.IsEmpty()) {
m_dependSuffix = m_objectSuffix + wxT(".d");
}
if (!m_switches[wxT("PreprocessOnly")].IsEmpty() && m_preprocessSuffix.IsEmpty()) {
m_preprocessSuffix = m_objectSuffix + wxT(".i");
}
if (m_fileTypes.empty()) {
AddCmpFileType("cpp", CmpFileKindSource, "$(CXX) $(SourceSwitch) \"$(FileFullPath)\" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/$(ObjectName)$(ObjectSuffix) $(IncludePath)");
AddCmpFileType("cxx", CmpFileKindSource, "$(CXX) $(SourceSwitch) \"$(FileFullPath)\" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/$(ObjectName)$(ObjectSuffix) $(IncludePath)");
AddCmpFileType("c++", CmpFileKindSource, "$(CXX) $(SourceSwitch) \"$(FileFullPath)\" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/$(ObjectName)$(ObjectSuffix) $(IncludePath)");
AddCmpFileType("c", CmpFileKindSource, "$(CC) $(SourceSwitch) \"$(FileFullPath)\" $(CFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/$(ObjectName)$(ObjectSuffix) $(IncludePath)");
AddCmpFileType("cc", CmpFileKindSource, "$(CXX) $(SourceSwitch) \"$(FileFullPath)\" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/$(ObjectName)$(ObjectSuffix) $(IncludePath)");
AddCmpFileType("m", CmpFileKindSource, "$(CXX) -x objective-c $(SourceSwitch) \"$(FileFullPath)\" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/$(ObjectName)$(ObjectSuffix) $(IncludePath)");
AddCmpFileType("mm", CmpFileKindSource, "$(CXX) -x objective-c++ $(SourceSwitch) \"$(FileFullPath)\" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/$(ObjectName)$(ObjectSuffix) $(IncludePath)");
AddCmpFileType("s", CmpFileKindSource, "$(AS) \"$(FileFullPath)\" $(ASFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/$(ObjectName)$(ObjectSuffix) -I$(IncludePath)");
AddCmpFileType("rc", CmpFileKindResource, "$(RcCompilerName) -i \"$(FileFullPath)\" $(RcCmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/$(ObjectName)$(ObjectSuffix) $(RcIncludePath)");
}
// Add support for assembler file
if ( m_fileTypes.count("s") == 0 ) {
AddCmpFileType("s",
CmpFileKindSource,
"$(AS) \"$(FileFullPath)\" $(ASFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/$(ObjectName)$(ObjectSuffix) -I$(IncludePath)");
}
}
Compiler::~Compiler()
{
}
wxXmlNode *Compiler::ToXml() const
{
wxXmlNode *node = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Compiler"));
node->AddProperty(wxT("Name"), m_name);
node->AddProperty(wxT("GenerateDependenciesFiles"), BoolToString(m_generateDependeciesFile));
node->AddProperty(wxT("ReadObjectsListFromFile"), BoolToString(m_readObjectFilesFromList));
node->AddProperty(wxT("ObjectNameIdenticalToFileName"), BoolToString(m_objectNameIdenticalToFileName));
node->AddProperty("CompilerFamily", m_compilerFamily);
node->AddProperty("IsDefault", BoolToString(m_isDefault));
wxXmlNode* installPath = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, "InstallationPath");
node->AddChild( installPath );
XmlUtils::SetCDATANodeContent(installPath, m_installationPath);
std::map<wxString, wxString>::const_iterator iter = m_switches.begin();
for (; iter != m_switches.end(); iter++) {
wxXmlNode *child = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Switch"));
child->AddProperty(wxT("Name"), iter->first);
child->AddProperty(wxT("Value"), iter->second);
node->AddChild(child);
}
iter = m_tools.begin();
for (; iter != m_tools.end(); iter++) {
wxXmlNode *child = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Tool"));
child->AddProperty(wxT("Name"), iter->first);
child->AddProperty(wxT("Value"), iter->second);
node->AddChild(child);
}
std::map<wxString, Compiler::CmpFileTypeInfo>::const_iterator it = m_fileTypes.begin();
for (; it != m_fileTypes.end(); it++) {
wxXmlNode *child = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("File"));
Compiler::CmpFileTypeInfo ft = it->second;
child->AddProperty(wxT("Extension"), ft.extension);
child->AddProperty(wxT("CompilationLine"), ft.compilation_line);
wxString strKind;
strKind << (long)ft.kind;
child->AddProperty(wxT("Kind"), strKind);
node->AddChild(child);
}
wxXmlNode *options = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Option"));
options->AddProperty(wxT("Name"), wxT("ObjectSuffix"));
options->AddProperty(wxT("Value"), m_objectSuffix);
node->AddChild(options);
options = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Option"));
options->AddProperty(wxT("Name"), wxT("DependSuffix"));
options->AddProperty(wxT("Value"), m_dependSuffix);
node->AddChild(options);
options = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Option"));
options->AddProperty(wxT("Name"), wxT("PreprocessSuffix"));
options->AddProperty(wxT("Value"), m_preprocessSuffix);
node->AddChild(options);
//add patterns
CmpListInfoPattern::const_iterator itPattern;
for (itPattern = m_errorPatterns.begin(); itPattern != m_errorPatterns.end(); ++itPattern) {
wxXmlNode *error = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Pattern"));
error->AddProperty(wxT("Name"), wxT("Error"));
error->AddProperty(wxT("FileNameIndex"), itPattern->fileNameIndex);
error->AddProperty(wxT("LineNumberIndex"), itPattern->lineNumberIndex);
XmlUtils::SetNodeContent(error, itPattern->pattern);
node->AddChild(error);
}
for (itPattern = m_warningPatterns.begin(); itPattern != m_warningPatterns.end(); ++itPattern) {
wxXmlNode *warning = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("Pattern"));
warning->AddProperty(wxT("Name"), wxT("Warning"));
warning->AddProperty(wxT("FileNameIndex"), itPattern->fileNameIndex);
warning->AddProperty(wxT("LineNumberIndex"), itPattern->lineNumberIndex);
XmlUtils::SetNodeContent(warning, itPattern->pattern);
node->AddChild(warning);
}
wxXmlNode *globalIncludePath = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("GlobalIncludePath"));
XmlUtils::SetNodeContent(globalIncludePath, m_globalIncludePath);
node->AddChild(globalIncludePath);
wxXmlNode *globalLibPath = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("GlobalLibPath"));
XmlUtils::SetNodeContent(globalLibPath, m_globalLibPath);
node->AddChild(globalLibPath);
wxXmlNode *pathVariable = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("PathVariable"));
XmlUtils::SetNodeContent(pathVariable, m_pathVariable);
node->AddChild(pathVariable);
// Add compiler options
CmpCmdLineOptions::const_iterator itCmpOption = m_compilerOptions.begin();
for ( ; itCmpOption != m_compilerOptions.end(); ++itCmpOption) {
const CmpCmdLineOption& cmpOption = itCmpOption->second;
wxXmlNode* pCmpOptionNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("CompilerOption"));
pCmpOptionNode->AddProperty(wxT("Name"), cmpOption.name);
XmlUtils::SetNodeContent(pCmpOptionNode, cmpOption.help);
node->AddChild(pCmpOptionNode);
}
// Add linker options
CmpCmdLineOptions::const_iterator itLnkOption = m_linkerOptions.begin();
for ( ; itLnkOption != m_linkerOptions.end(); ++itLnkOption) {
const CmpCmdLineOption& lnkOption = itLnkOption->second;
wxXmlNode* pLnkOptionNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("LinkerOption"));
pLnkOptionNode->AddProperty(wxT("Name"), lnkOption.name);
XmlUtils::SetNodeContent(pLnkOptionNode, lnkOption.help);
node->AddChild(pLnkOptionNode);
}
return node;
}
wxString Compiler::GetSwitch(const wxString &name) const
{
std::map<wxString, wxString>::const_iterator iter = m_switches.find(name);
if (iter == m_switches.end()) {
return wxEmptyString;
}
return iter->second;
}
wxString Compiler::GetTool(const wxString &name) const
{
std::map<wxString, wxString>::const_iterator iter = m_tools.find(name);
if (iter == m_tools.end()) {
if(name == wxT("CC")) {
// an upgrade, return the CXX
return GetTool(wxT("CXX"));
}
return wxEmptyString;
}
if(name == wxT("CC") && iter->second.empty()) {
return GetTool(wxT("CXX"));
}
wxString tool = iter->second;
tool.Replace("\\", "/");
return tool;
}
bool Compiler::GetCmpFileType(const wxString& extension, Compiler::CmpFileTypeInfo &ft)
{
std::map<wxString, Compiler::CmpFileTypeInfo>::iterator iter = m_fileTypes.find(extension.Lower());
if (iter == m_fileTypes.end()) {
return false;
}
ft = iter->second;
return true;
}
void Compiler::AddCmpFileType(const wxString &extension, CmpFileKind type, const wxString &compile_line)
{
Compiler::CmpFileTypeInfo ft;
ft.extension = extension.Lower();
if ( m_fileTypes.count(ft.extension) ) {
m_fileTypes.erase(ft.extension);
}
ft.compilation_line = compile_line;
ft.kind = type;
m_fileTypes[extension] = ft;
}
void Compiler::SetSwitch(const wxString& switchName, const wxString& switchValue)
{
if ( m_switches.count(switchName) ) {
m_switches.erase(switchName);
}
m_switches.insert(std::make_pair(switchName, switchValue));
}
void Compiler::AddPattern(int type, const wxString& pattern, int fileNameIndex, int lineNumberIndex)
{
CmpInfoPattern pt;
pt.pattern = pattern;
pt.fileNameIndex = wxString::Format("%d", (int)fileNameIndex);
pt.lineNumberIndex = wxString::Format("%d", (int)lineNumberIndex);
if ( type == eErrorPattern ) {
m_errorPatterns.push_back(pt);
} else {
m_warningPatterns.push_back(pt);
}
}
void Compiler::SetTool(const wxString& toolname, const wxString& cmd)
{
if ( m_tools.count(toolname) ) {
m_tools.erase(toolname);
}
m_tools.insert(std::make_pair(toolname, cmd));
}
void Compiler::AddCompilerOption(const wxString& name, const wxString& desc)
{
CmpCmdLineOption option;
option.help = desc;
option.name = name;
m_compilerOptions.erase( name );
m_compilerOptions.insert( std::make_pair(name, option) );
}
void Compiler::AddLinkerOption(const wxString& name, const wxString& desc)
{
CmpCmdLineOption option;
option.help = desc;
option.name = name;
m_linkerOptions.erase( name );
m_linkerOptions.insert( std::make_pair(name, option) );
}
bool Compiler::IsGnuCompatibleCompiler() const
{
return m_compilerFamily.IsEmpty() ||
m_compilerFamily == COMPILER_FAMILY_CLANG ||
m_compilerFamily == COMPILER_FAMILY_GCC ||
m_compilerFamily == COMPILER_FAMILY_MINGW;
}
void Compiler::AddDefaultGnuComplierOptions()
{
// Add GCC / CLANG default compiler options
AddCompilerOption("-O", "Optimize generated code. (for speed)");
AddCompilerOption("-O1", "Optimize more (for speed)");
AddCompilerOption("-O2", "Optimize even more (for speed)");
AddCompilerOption("-O3", "Optimize fully (for speed)");
AddCompilerOption("-Os", "Optimize generated code (for size)");
AddCompilerOption("-O0", "Optimize for debugging");
AddCompilerOption("-W", "Enable standard compiler warnings");
AddCompilerOption("-Wall", "Enable all compiler warnings");
AddCompilerOption("-Wfatal-errors", "Stop compiling after first error");
AddCompilerOption("-Wmain", "Warn if main() is not conformant");
AddCompilerOption("-ansi", "In C mode, support all ISO C90 programs. In C++ mode, remove GNU extensions that conflict with ISO C++");
AddCompilerOption("-fexpensive-optimizations", "Expensive optimizations");
AddCompilerOption("-fopenmp", "Enable OpenMP (compilation)");
AddCompilerOption("-g", "Produce debugging information");
AddCompilerOption("-pedantic", "Enable warnings demanded by strict ISO C and ISO C++");
AddCompilerOption("-pedantic-errors", "Treat as errors the warnings demanded by strict ISO C and ISO C++");
AddCompilerOption("-pg", "Profile code when executed");
AddCompilerOption("-w", "Inhibit all warning messages");
AddCompilerOption("-std=c99", "Enable ANSI C99 features");
AddCompilerOption("-std=c++11", "Enable C++11 features");
}
void Compiler::AddDefaultGnuLinkerOptions()
{
// Linker options
AddLinkerOption("-fopenmp", "Enable OpenMP (linkage)");
AddLinkerOption("-mwindows", "Prevent a useless terminal console appearing with MSWindows GUI programs");
AddLinkerOption("-pg", "Profile code when executed");
AddLinkerOption("-s", "Remove all symbol table and relocation information from the executable");
}
wxArrayString Compiler::GetDefaultIncludePaths() const
{
wxArrayString defaultPaths;
if ( GetCompilerFamily() == COMPILER_FAMILY_MINGW ) {
wxString ver = GetGCCVersion();
if ( ver.IsEmpty() ) {
return defaultPaths;
}
// FIXME : support 64 bit compilers
defaultPaths.Add( GetIncludePath("lib/gcc/mingw32/" + ver + "/include/c++") );
defaultPaths.Add( GetIncludePath("lib/gcc/mingw32/" + ver + "/include/c++/mingw32") );
defaultPaths.Add( GetIncludePath("lib/gcc/mingw32/" + ver + "/include/c++/backward") );
defaultPaths.Add( GetIncludePath("lib/gcc/mingw32/" + ver + "/include") );
defaultPaths.Add( GetIncludePath("include") );
defaultPaths.Add( GetIncludePath("lib/gcc/mingw32/" + ver + "/include-fixed") );
} else if ( GetCompilerFamily() == COMPILER_FAMILY_CLANG || GetCompilerFamily() == COMPILER_FAMILY_GCC) {
#ifndef __WXMSW__
defaultPaths = POSIXGetIncludePaths();
#endif
}
return defaultPaths;
}
wxString Compiler::GetGCCVersion() const
{
// Get the compiler version
static wxRegEx reVersion("([0-9]+\\.[0-9]+\\.[0-9]+)");
wxString command;
command << GetTool("CXX") << " --version";
wxArrayString out;
ProcUtils::SafeExecuteCommand(command, out);
if ( out.IsEmpty() ) {
return "";
}
if ( reVersion.Matches( out.Item(0) ) ) {
return reVersion.GetMatch( out.Item(0) );
}
return "";
}
wxString Compiler::GetIncludePath(const wxString& pathSuffix) const
{
wxString fullpath;
fullpath << GetInstallationPath() << "/" << pathSuffix;
wxFileName fn(fullpath, "");
return fn.GetPath();
}
wxArrayString Compiler::POSIXGetIncludePaths() const
{
wxString command;
command << GetTool("CXX") << " -v -x c++ /dev/null -fsyntax-only";
wxString outputStr = ::wxShellExec(command, wxEmptyString);
wxArrayString arr;
wxArrayString outputArr = ::wxStringTokenize(outputStr, wxT("\n\r"), wxTOKEN_STRTOK);
// Analyze the output
bool collect(false);
for(size_t i=0; i<outputArr.GetCount(); i++) {
if(outputArr[i].Contains(wxT("#include <...> search starts here:"))) {
collect = true;
continue;
}
if(outputArr[i].Contains(wxT("End of search list."))) {
break;
}
if(collect) {
wxString file = outputArr.Item(i).Trim().Trim(false);
// on Mac, (framework directory) appears also,
// but it is harmless to use it under all OSs
file.Replace(wxT("(framework directory)"), wxT(""));
file.Trim().Trim(false);
wxFileName includePath(file, "");
includePath.Normalize();
arr.Add( includePath.GetPath() );
}
}
return arr;
}
|