27 #include <wx/arrimpl.cpp> 38 const wxString Compiler::FilePathWithSpaces =
_T(
"[][{}() \t#%$~[:alnum:]&_:+/\\.-]+");
81 _(
"Compile single file to object file"),
82 _(
"Generate dependencies for file"),
83 _(
"Compile Win32 resource file"),
84 _(
"Link object files to executable"),
85 _(
"Link object files to console executable"),
86 _(
"Link object files to dynamic library"),
87 _(
"Link object files to static library"),
88 _(
"Link object files to native executable")
93 m_MultiLineMessages(false),
95 m_ParentID(parentID.Lower()),
97 m_NeedValidityCheck(true),
145 for (
int i = 0; i <
ctCount; ++i)
160 for (
int i = 0; i <
ctCount; ++i)
236 return _(
"Compiler doesn't support this platform!\n");
243 triedPathsMsgs +=
F(
_T(
"Tried to run compiler executable '%s', but failed!\n"), tmp.
wx_str());
252 triedPathsMsgs +=
F(
_T(
"Tried to run compiler executable '%s', but failed!\n"), tmp.wx_str());
258 return triedPathsMsgs;
301 generator->
Init(project);
317 for (
size_t i = 0; i < vec.size(); ++i)
319 if (vec[i].extensions.GetCount() == 0)
324 for (
size_t n = 0; n < vec[i].extensions.GetCount(); ++n)
326 if (vec[i].extensions[n] == fileExtension)
327 return vec[i].command;
331 return vec[catchAll].command;
343 for (
size_t i = 0; i < vec.size(); ++i)
345 if (vec[i].extensions.GetCount() == 0)
350 for (
size_t n = 0; n < vec[i].extensions.GetCount(); ++n)
352 if (vec[i].extensions[n] == fileExtension)
357 return &vec[catchAll];
373 for (
int i = 0; i <
ctCount; ++i)
400 cfg->
Write(
_T(
"settings_version"), CompilerSettingsVersion);
416 cfg->
Write(tmp +
_T(
"/compiler_options"), key,
false);
421 cfg->
Write(tmp +
_T(
"/resource_compiler_options"), key,
false);
426 cfg->
Write(tmp +
_T(
"/linker_options"), key,
false);
431 cfg->
Write(tmp +
_T(
"/include_dirs"), key,
false);
436 cfg->
Write(tmp +
_T(
"/res_include_dirs"), key,
false);
441 cfg->
Write(tmp +
_T(
"/library_dirs"), key,
false);
446 cfg->
Write(tmp +
_T(
"/libraries"), key,
false);
451 cfg->
Write(tmp +
_T(
"/commands_before"), key,
true);
456 cfg->
Write(tmp +
_T(
"/commands_after"), key,
true);
478 for (
int i = 0; i <
ctCount; ++i)
480 for (
size_t n = 0; n <
m_Commands[i].size(); ++n)
547 for (
size_t i = 0; i <
m_RegExes.size(); ++i)
552 group.
Printf(
_T(
"%s/regex/re%3.3lu"), tmp.
c_str(),
static_cast<unsigned long>(i + 1));
554 cfg->
Write(group +
_T(
"/description"), rs.
desc,
true);
577 wxString configpath = tmp +
_T(
"/custom_variables/");
580 for (StringHash::const_iterator it = v.begin(); it != v.end(); ++it)
581 cfg->
Write(configpath + it->first, it->second);
600 static bool saidAboutCompilerIDs =
false;
604 if (!saidAboutCompilerIDs)
606 saidAboutCompilerIDs =
true;
607 cbMessageBox(
_(
"Compilers now use unique names instead of integer IDs.\n" 608 "Projects will be updated accordingly on load, mostly automatic."),
617 if (!cfg->
Exists(tmp +
_T(
"/name")))
620 if (!cfg->
Exists(tmp +
_T(
"/name")))
653 for (
int i = 0; i <
ctCount; ++i)
656 for (
size_t n = 0; n < keys.size(); ++n)
658 unsigned long index = 0;
659 if (keys[n].Mid(4).ToULong(&index))
708 for (
size_t i = 0; i < keys.
GetCount(); ++i)
716 if (!key.
ToLong(&index, 10))
724 if (!cfg->
Exists(group+
_T(
"/description")))
729 cfg->
Read(group +
_T(
"/regex")),
731 cfg->
ReadInt(group +
_T(
"/filename"), 0),
747 wxString configpath = tmp +
_T(
"/custom_variables/");
750 for (
unsigned int i = 0; i < list.
GetCount(); ++i)
751 SetVar(list[i], cfg->
Read(configpath + _T(
'/') + list[i]),
false);
756 msg <<
_(
"Some compiler settings defaults have changed in this version.\n" 757 "It is recommended that you allow updating of your settings to the new defaults.\n" 758 "Only disallow this if you don't want to lose any customizations you have done to this compiler's settings.\n\n" 759 "Note that the only settings that are affected are those found in \"Advanced compiler options\"...\n\n" 760 "Do you want to update your current settings to the new defaults?");
764 for (
int i = 0; i <
ctCount; ++i)
782 for (
size_t i = 0; i <
m_RegExes.size(); ++i)
794 for (
int x = 0; x < 3; ++x)
815 wxString msg(
_(
"Error: file 'options_") + name +
_(
".xml' not found."));
822 wxString msg(
_(
"Warning: '") + doc +
_(
"' not loaded due to excessive recursion."));
827 if (!options.
Load(doc))
829 wxString msg(
_(
"Error: Compiler options file '") + doc +
_(
"' not found for compiler '") + name +
wxT(
"'."));
836 wxString msg(
_(
"Error: Invalid Code::Blocks compiler options file for compiler '") + name +
wxT(
"'."));
880 if (prog ==
wxT(
"C"))
885 else if (prog ==
wxT(
"CPP"))
890 else if (prog ==
wxT(
"LD"))
895 else if (prog ==
wxT(
"DBGconfig"))
897 else if (prog ==
wxT(
"LIB"))
902 else if (prog ==
wxT(
"WINDRES"))
907 else if (prog ==
wxT(
"MAKE"))
916 if (swi ==
wxT(
"includeDirs"))
918 else if (swi ==
wxT(
"libDirs"))
920 else if (swi ==
wxT(
"linkLibs"))
922 else if (swi ==
wxT(
"defines"))
924 else if (swi ==
wxT(
"genericSwitch"))
926 else if (swi ==
wxT(
"objectExtension"))
928 else if (swi ==
wxT(
"forceFwdSlashes"))
930 else if (swi ==
wxT(
"forceLinkerUseQuotes"))
932 else if (swi ==
wxT(
"forceCompilerUseQuotes"))
934 else if (swi ==
wxT(
"needDependencies"))
936 else if (swi ==
wxT(
"logging"))
938 if (value ==
wxT(
"full"))
940 else if (value ==
wxT(
"simple"))
942 else if (value ==
wxT(
"none"))
947 else if (swi ==
wxT(
"libPrefix"))
949 else if (swi ==
wxT(
"libExtension"))
951 else if (swi ==
wxT(
"linkerNeedsLibPrefix"))
953 else if (swi ==
wxT(
"linkerNeedsLibExtension"))
955 else if (swi ==
wxT(
"linkerNeedsPathResolved"))
957 else if (swi ==
wxT(
"supportsPCH"))
959 else if (swi ==
wxT(
"PCHExtension"))
961 else if (swi ==
wxT(
"UseFlatObjects"))
963 else if (swi ==
wxT(
"UseFullSourcePaths"))
965 else if (swi ==
wxT(
"includeDirSeparator") && !value.
IsEmpty())
967 else if (swi ==
wxT(
"libDirSeparator") && !value.
IsEmpty())
969 else if (swi ==
wxT(
"objectSeparator") && !value.
IsEmpty())
971 else if (swi ==
wxT(
"statusSuccess") && !value.
IsEmpty())
977 else if (swi ==
wxT(
"Use83Paths"))
994 category =
wxT(
"General");
1000 exclusive = (exclu ?
wxT(
"true") :
wxT(
"false"));
1008 exclusive ==
wxT(
"true"));
1018 if (cmd ==
wxT(
"CompileObject"))
1020 else if (cmd ==
wxT(
"GenDependencies"))
1022 else if (cmd ==
wxT(
"CompileResource"))
1024 else if (cmd ==
wxT(
"LinkExe"))
1026 else if (cmd ==
wxT(
"LinkConsoleExe"))
1028 else if (cmd ==
wxT(
"LinkDynamic"))
1030 else if (cmd ==
wxT(
"LinkStatic"))
1032 else if (cmd ==
wxT(
"LinkNative"))
1036 bool assigned =
false;
1038 for (
size_t i = 0; i < tools.size(); ++i)
1040 if (tools[i].extensions == tool.extensions)
1048 tools.push_back(tool);
1073 while (!node->
GetNext() && depth > 0)
1100 const wxString fn =
wxT(
"compilers/options_") + name +
wxT(
".xml");
1101 if (globalPrecedence)
1119 if (!options.
Load(doc))
1148 else if (node->
GetName() == wxT(
"RegEx"))
1152 if (tp == wxT(
"warning"))
1154 else if (tp == wxT(
"error"))
1156 else if (tp == wxT(
"info"))
1165 else if (node->
GetName() == wxT(
"Common"))
1168 globalPrecedence, recursion + 1);
1170 while (!node->
GetNext() && depth > 0)
1185 if (test ==
wxT(
"windows"))
1186 val = platform::windows;
1187 else if (test ==
wxT(
"macosx"))
1188 val = platform::macosx;
1189 else if (test ==
wxT(
"linux"))
1190 val = platform::Linux;
1191 else if (test ==
wxT(
"freebsd"))
1192 val = platform::freebsd;
1193 else if (test ==
wxT(
"netbsd"))
1194 val = platform::netbsd;
1195 else if (test ==
wxT(
"openbsd"))
1196 val = platform::openbsd;
1197 else if (test ==
wxT(
"darwin"))
1198 val = platform::darwin;
1199 else if (test ==
wxT(
"solaris"))
1200 val = platform::solaris;
1201 else if (test ==
wxT(
"unix"))
1202 val = platform::Unix;
1222 for (
size_t i = 0; i < extraPaths.
GetCount(); ++i)
1223 path.
Prepend(extraPaths[i] + wxPATH_SEP);
1225 path.
Prepend(masterPath + wxPATH_SEP + masterPath + wxFILE_SEP_PATH +
wxT(
"bin") + wxPATH_SEP);
1231 if ( !cmd[0].IsEmpty() )
1234 #if wxCHECK_VERSION(3, 0, 0) 1252 for (
size_t i = 0; i < cmd.
GetCount(); ++i)
1273 if (name ==
wxT(
"C"))
1275 else if (name ==
wxT(
"CPP"))
1277 else if (name ==
wxT(
"LD"))
1279 else if (name ==
wxT(
"LIB"))
1281 else if (name ==
wxT(
"WINDRES"))
1283 else if (name ==
wxT(
"MAKE"))
static wxString CommandTypeDescriptions[ctCount]
Get the command type descriptions (used in advanced compiler options)
bool linkerNeedsLibExtension
wxString F(const wxChar *msg,...)
sprintf-like function
DLLIMPORT wxArrayString GetArrayFromString(const wxString &text, const wxString &separator=DEFAULT_ARRAY_SEP, bool trimSpaces=true)
CompilerLoggingType logging
bool EvalXMLCondition(const wxXmlNode *node)
bool wxGetEnv(const wxString &var, wxString *value)
CompilerPrograms Programs
Data folder in user's dir.
wxArrayString m_CmdsBefore
CompilerSwitches Switches
static wxArrayString m_CompilerIDs
virtual void SetResourceCompilerOptions(const wxArrayString &resourceCompilerOpts)
static const CompilerLoggingType defaultLogging
bool wxIsspace(const wxUniChar &c)
CompilerLoggingType
Helper enum for type of compiler logging.
Generate command-lines needed to produce a build.
ConfigManager * GetConfigManager(const wxString &name_space) const
wxXmlNode * GetRoot() const
int ReadInt(const wxString &name, int defaultVal=0)
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
bool GetAttribute(const wxString &attrName, wxString *value) const
bool wxFileExists(const wxString &filename)
void LogWarning(const wxString &msg, int i=app_log)
virtual void SetLibDirs(const wxArrayString &libDirs)
Link console executable command, e.g. "$linker $libdirs -o $exe_output $link_objects $libs"...
bool ReadBool(const wxString &name, bool defaultVal=false)
Generate dependencies command.
wxArrayString m_ResIncludeDirs
wxString MakeInvalidCompilerMessages() const
Returns messages which might be useful to the use for debugging why the compiler is invalid...
wxString m_SortOptions[2]
bool Matches(const wxString &text, int flags=0) const
static int GetCompilerIndex(const wxString &id)
virtual void Reset()
Reset settings to defaults.
bool wxIsdigit(const wxUniChar &c)
virtual void ReloadOptions()
Reload option flags (for copied compilers).
DLLIMPORT wxString GetStringFromArray(const wxArrayString &array, const wxString &separator=DEFAULT_ARRAY_SEP, bool SeparatorAtEnd=true)
wxXmlNode * GetParent() const
const wxString & GetCPPOnlyFlags()
Compile object command, e.g. "$compiler $options $includes -c $file -o $object".
#define wxICON_INFORMATION
CompilerPrograms m_Programs
void SetCPPOnlyFlags(const wxString &flags)
wxString & Remove(size_t pos)
virtual void SetLinkLibs(const wxArrayString &linkLibs)
const wxString & GetName() const
wxArrayString ReadArrayString(const wxString &name)
static wxString LocateDataFile(const wxString &filename, int search_dirs=sdAllKnown)
Locate a file in an installation- and platform-independent way.
virtual const wxString & GetCommand(CommandType ct, const wxString &fileExtension=wxEmptyString) const
Get a command based on CommandType.
CompilerLineType
Enum categorizing compiler's output line as warning/error/info/normal.
#define wxICON_EXCLAMATION
CompilerToolsVector m_Commands[ctCount]
virtual void LoadSettings(const wxString &baseKey)
Load settings.
const wxString CompilerSettingsVersion
wxXmlNode * GetNext() const
virtual void SetCompilerOptions(const wxArrayString &compilerOpts)
virtual void Init(cbProject *project)
Initialize for use with the specified project.
wxUSE_UNICODE_dependent wxChar
wxArrayString m_CompilerOptions
const wxString & GetID() const
Get this compiler's unique ID.
void Write(const wxString &name, const wxString &value, bool ignoreEmpty=false)
DLLIMPORT wxString UnixFilename(const wxString &filename, wxPathFormat format=wxPATH_NATIVE)
virtual bool IsValid()
Check if the compiler is actually valid (installed).
Represents a Code::Blocks project.
const wxString & wxGetTranslation(const wxString &string, const wxString &domain=wxEmptyString)
const wxString & GetCOnlyFlags()
Link dynamic (dll) lib command, e.g. "$linker -shared -Wl,--output-def=$def_output -Wl...
wxArrayString ResIncludeDirs
wxArrayString EnumerateSubPaths(const wxString &path)
wxArrayString m_ResourceCompilerOptions
bool Exists(const wxString &name)
wxArrayString m_LinkerOptions
size_t Replace(const wxString &strOld, const wxString &strNew, bool replaceAll=true)
const wxString EmptyString
wxChar includeDirSeparator
bool GetMatch(size_t *start, size_t *len, size_t index=0) const
wxXmlNode * GetChildren() const
LogManager * GetLogManager() const
wxString Read(const wxString &key, const wxString &defaultVal=wxEmptyString)
virtual void SetIncludeDirs(const wxArrayString &includeDirs)
wxString GetExecName(const wxString &name)
virtual void SetCommandsBeforeBuild(const wxArrayString &commands)
This is a base class for all classes needing compilation parameters.
static wxUniChar GetPathSeparator(wxPathFormat format=wxPATH_NATIVE)
const wxStringCharType * wx_str() const
void MirrorCurrentSettings()
Link executable command, e.g. "$linker $libdirs -o $exe_output $link_objects $libs -mwindows"...
DLLIMPORT wxArrayString MakeUniqueArray(const wxArrayString &array, bool caseSens)
CompilerToolsVector Commands[ctCount]
virtual void LoadDefaultRegExArray(bool globalPrecedence=false)
Load the default (preset) array of regexes used in errors/warnings recognition.
MacrosManager * GetMacrosManager() const
const wxString & _(const wxString &string)
wxString & Trim(bool fromRight=true)
void ReplaceMacros(wxString &buffer, ProjectBuildTarget *target=nullptr, bool subrequest=false)
wxArrayString LinkerOptions
wxArrayString ResourceCompilerOptions
int wxAtoi(const wxString &str)
CommandType
Helper enum to retrieve compiler commands.
bool wxIsalnum(const wxUniChar &c)
CompilerOptions m_Options
void LoadRegExArray(const wxString &name, bool globalPrecedence=false, int recursion=0)
bool ToLong(long *val, int base=10) const
Compile Win32 resources command, e.g. "$rescomp -i $file -J rc -o $resource_output -O coff $includes"...
Abstract base class for compilers.
virtual void SetLinkerOptions(const wxArrayString &linkerOpts)
wxString & Append(const char *psz)
void DeleteSubPath(const wxString &strPath)
virtual CompilerLineType CheckForWarningsAndErrors(const wxString &line)
Check if the supplied string is a compiler warning/error.
bool forceLinkerUseQuotes
void LoadDefaultOptions(const wxString &name, int recursion=0)
void AddOption(CompOption *coption, int index=-1)
virtual bool SetVar(const wxString &key, const wxString &value, bool onlyIfExists=false)
void Log(const wxString &msg, int i=app_log, Logger::level lv=Logger::info)
const wxString & GetParentID() const
Get this compiler's parent's unique ID.
void DebugLog(const wxString &msg, Logger::level lv=Logger::info)
wxString & Prepend(const wxString &str)
virtual void SetResourceIncludeDirs(const wxArrayString &resIncludeDirs)
wxArrayString IncludeDirs
DLLIMPORT wxString MakeUniqueString(const wxString &text, const wxString &separator=DEFAULT_ARRAY_SEP, bool caseSens=true)
size_t Add(const wxString &str, size_t copies=1)
bool StartsWith(const wxString &prefix, wxString *rest=NULL) const
wxString GetRegExString() const
bool linkerNeedsLibPrefix
bool Compile(const wxString &pattern, int flags=wxRE_DEFAULT)
virtual void SaveSettings(const wxString &baseKey)
Save settings.
virtual bool Load(const wxString &filename, const wxString &encoding="UTF-8", int flags=wxXMLDOC_NONE)
Link native binary command.
wxUniChar GetChar(size_t n) const
wxArrayString m_CmdsAfter
Link static lib command, e.g. "ar -r $output $link_objects\n\tranlib $static_output".
wxArrayString CompilerOptions_
const wxRegEx & GetRegEx() const
bool wxSetEnv(const wxString &var, const wxString &value)
int Printf(const wxString &pszFormat,...)
wxString Format(const wxString &format=wxDefaultDateTimeFormat, const TimeZone &tz=Local) const
virtual void SetVersionString()
Set the compiler version string.
virtual const StringHash & GetAllVars() const
wxArrayString EnumerateKeys(const wxString &path)
bool forceCompilerUseQuotes
wxArrayString m_IncludeDirs
bool IsUniqueID(const wxString &ID)
wxString GetNodeContent() const
virtual void UnsetAllVars()
virtual void SetCommandsAfterBuild(const wxArrayString &commands)
static wxString Format(const wxString &format,...)
DLLIMPORT int cbMessageBox(const wxString &message, const wxString &caption=wxEmptyString, int style=wxOK, wxWindow *parent=NULL, int x=-1, int y=-1)
wxMessageBox wrapper.
void SetCOnlyFlags(const wxString &flags)
bool linkerNeedsPathResolved
long wxExecute(const wxString &command, int flags=wxEXEC_ASYNC, wxProcess *callback=NULL, const wxExecuteEnv *env=NULL)
CompilerSwitches m_Switches
virtual CompilerCommandGenerator * GetCommandGenerator(cbProject *project)
This is to be overridden, if compiler needs to alter the default command line generation.
Compiler(const wxString &name, const wxString &ID, const wxString &parentID=wxEmptyString, int weight=50)