Code::Blocks  SVN r11506
compileoptionsbase.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3  * http://www.gnu.org/licenses/lgpl-3.0.html
4  *
5  * $Revision: 10833 $
6  * $Id: compileoptionsbase.cpp 10833 2016-04-17 21:31:25Z jenslody $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/sdk/compileoptionsbase.cpp $
8  */
9 
10 #include "sdk_precomp.h"
11 
12 #ifndef CB_PRECOMP
13  #include "compileoptionsbase.h"
14  #include "sdk_events.h"
15  #include "manager.h"
16  #include "macrosmanager.h"
17 #endif
18 
19 namespace { static const bool s_case_sensitive = platform::windows ? false : true; }
20 
22  : m_Platform(spAll),
23  m_Modified(false),
24  m_AlwaysRunPostCmds(false)
25 {
26  //ctor
27 }
28 
30 {
31  //dtor
32 }
33 
35 {
36  if (m_Platform & platform)
37  return;
38  m_Platform |= platform;
39  SetModified(true);
40 }
41 
43 {
44  if (!(m_Platform & platform))
45  return;
46  m_Platform &= ~platform;
47  SetModified(true);
48 }
49 
51 {
52  if (m_Platform == platforms)
53  return;
54  m_Platform = platforms;
55  SetModified(true);
56 }
57 
59 {
60  return m_Platform;
61 }
62 
64 {
65  if(platform::windows)
66  return m_Platform & spWindows;
67  if(platform::Unix)
68  return m_Platform & spUnix;
69  if(platform::macosx)
70  return m_Platform & spMac;
71 
72  return false;
73 }
74 
76 {
77  if (m_LinkerOptions == linkerOpts)
78  return;
79  m_LinkerOptions = linkerOpts;
80  SetModified(true);
81 }
82 
84 {
85  return m_LinkerOptions;
86 }
87 
89 {
90  if (m_LinkLibs == linkLibs)
91  return;
92  m_LinkLibs = linkLibs;
93  SetModified(true);
94 }
95 
97 {
98  return m_LinkLibs;
99 }
100 
102 {
103  if (m_CompilerOptions == compilerOpts)
104  return;
105  m_CompilerOptions = compilerOpts;
106  SetModified(true);
107 }
108 
110 {
111  return m_CompilerOptions;
112 }
113 
115 {
116  if (m_ResourceCompilerOptions == resourceCompilerOpts)
117  return;
118  m_ResourceCompilerOptions = resourceCompilerOpts;
119  SetModified(true);
120 }
121 
123 {
125 }
126 
128 {
129  if (m_IncludeDirs == includeDirs)
130  return;
131 
132  // make sure we don't have duplicate entries
133  // that's why we don't assign the array but rather copy it entry by entry...
134 
136  for (size_t i = 0; i < includeDirs.GetCount(); ++i)
137  {
138  wxString entry = UnixFilename(includeDirs[i]);
139  if (m_IncludeDirs.Index(entry, s_case_sensitive) == wxNOT_FOUND)
140  m_IncludeDirs.Add(entry);
141  }
142  SetModified(true);
143 }
144 
146 {
147  return m_IncludeDirs;
148 }
149 
151 {
152  if (m_ResIncludeDirs == resIncludeDirs)
153  return;
154 
155  // make sure we don't have duplicate entries
156  // that's why we don't assign the array but rather copy it entry by entry...
157 
159  for (size_t i = 0; i < resIncludeDirs.GetCount(); ++i)
160  {
161  wxString entry = UnixFilename(resIncludeDirs[i]);
162  if (m_ResIncludeDirs.Index(entry, s_case_sensitive) == wxNOT_FOUND)
163  m_ResIncludeDirs.Add(entry);
164  }
165  SetModified(true);
166 }
167 
169 {
170  return m_ResIncludeDirs;
171 }
172 
174 {
175  if (m_LibDirs == libDirs)
176  return;
177 
178  // make sure we don't have duplicate entries
179  // that's why we don't assign the array but rather copy it entry by entry...
180 
181  m_LibDirs.Clear();
182  for (size_t i = 0; i < libDirs.GetCount(); ++i)
183  {
184  wxString entry = UnixFilename(libDirs[i]);
185  if (m_LibDirs.Index(entry, s_case_sensitive) == wxNOT_FOUND)
186  m_LibDirs.Add(entry);
187  }
188  SetModified(true);
189 }
190 
192 {
193  return m_LibDirs;
194 }
195 
197 {
198  if (m_Scripts == scripts)
199  return;
200 
201  // make sure we don't have duplicate entries
202  // that's why we don't assign the array but rather copy it entry by entry...
203 
204  m_Scripts.Clear();
205  for (size_t i = 0; i < scripts.GetCount(); ++i)
206  {
207  wxString entry = UnixFilename(scripts[i]);
208  if (m_Scripts.Index(entry, s_case_sensitive) == wxNOT_FOUND)
209  m_Scripts.Add(entry);
210  }
211  SetModified(true);
212 }
213 
215 {
216  return m_Scripts;
217 }
218 
220 {
221  if (m_CmdsBefore == commands)
222  return;
223  m_CmdsBefore = commands;
224  SetModified(true);
225 }
226 
228 {
229  return m_CmdsBefore;
230 }
231 
233 {
234  if (m_CmdsAfter == commands)
235  return;
236  m_CmdsAfter = commands;
237  SetModified(true);
238 }
239 
241 {
242  return m_CmdsAfter;
243 }
244 
246 {
247  return m_AlwaysRunPostCmds;
248 }
249 
251 {
252  if (m_AlwaysRunPostCmds == always)
253  return;
254  m_AlwaysRunPostCmds = always;
255  SetModified(true);
256 }
257 
259 {
260  return m_Modified;
261 }
262 
264 {
265  m_Modified = modified;
266 }
267 
269 {
270  if (m_LinkerOptions.Index(option, s_case_sensitive) == wxNOT_FOUND)
271  {
272  m_LinkerOptions.Add(option);
273  SetModified(true);
274  }
275 }
276 
278 {
279  if (m_LinkLibs.Index(option, s_case_sensitive) == wxNOT_FOUND)
280  {
281  m_LinkLibs.Add(option);
282  SetModified(true);
283  }
284 }
285 
287 {
288  if (m_CompilerOptions.Index(option, s_case_sensitive) == wxNOT_FOUND)
289  {
290  m_CompilerOptions.Add(option);
291  SetModified(true);
292  }
293 }
294 
296 {
297  if (m_ResourceCompilerOptions.Index(option, s_case_sensitive) == wxNOT_FOUND)
298  {
300  SetModified(true);
301  }
302 }
303 
305 {
306  wxString entry = UnixFilename(option);
307  if (m_IncludeDirs.Index(entry, s_case_sensitive) == wxNOT_FOUND)
308  {
309  m_IncludeDirs.Add(entry);
310  SetModified(true);
311  }
312 }
313 
315 {
316  wxString entry = UnixFilename(option);
317  if (m_ResIncludeDirs.Index(entry, s_case_sensitive) == wxNOT_FOUND)
318  {
319  m_ResIncludeDirs.Add(entry);
320  SetModified(true);
321  }
322 }
323 
325 {
326  wxString entry = UnixFilename(option);
327  if (m_LibDirs.Index(entry, s_case_sensitive) == wxNOT_FOUND)
328  {
329  m_LibDirs.Add(entry);
330  SetModified(true);
331  }
332 }
333 
335 {
336  m_CmdsBefore.Add(command);
337  SetModified(true);
338 }
339 
341 {
342  m_CmdsAfter.Add(command);
343  SetModified(true);
344 }
345 
347 {
348  wxString envopt = UnixFilename(script);
349  if (m_Scripts.Index(envopt, s_case_sensitive) == wxNOT_FOUND)
350  {
351  m_Scripts.Add(envopt);
352  SetModified(true);
353  }
354 }
355 
356 void CompileOptionsBase::ReplaceLinkerOption(const wxString& option, const wxString& new_option)
357 {
358  int idx = m_LinkerOptions.Index(option, s_case_sensitive);
359  if (idx != wxNOT_FOUND)
360  {
361  m_LinkerOptions.Item(idx) = new_option;
362  SetModified(true);
363  }
364 }
365 
366 void CompileOptionsBase::ReplaceLinkLib(const wxString& option, const wxString& new_option)
367 {
368  int idx = m_LinkLibs.Index(option, s_case_sensitive);
369  if (idx != wxNOT_FOUND)
370  {
371  m_LinkLibs.Item(idx) = new_option;
372  SetModified(true);
373  }
374 }
375 
376 void CompileOptionsBase::ReplaceCompilerOption(const wxString& option, const wxString& new_option)
377 {
378  int idx = m_CompilerOptions.Index(option, s_case_sensitive);
379  if (idx != wxNOT_FOUND)
380  {
381  m_CompilerOptions.Item(idx) = new_option;
382  SetModified(true);
383  }
384 }
385 
387 {
388  int idx = m_ResourceCompilerOptions.Index(option, s_case_sensitive);
389  if (idx != wxNOT_FOUND)
390  {
391  m_ResourceCompilerOptions.Item(idx) = new_option;
392  SetModified(true);
393  }
394 }
395 
396 void CompileOptionsBase::ReplaceIncludeDir(const wxString& option, const wxString& new_option)
397 {
398  int idx = m_IncludeDirs.Index(option, s_case_sensitive);
399  if (idx != wxNOT_FOUND)
400  {
401  m_IncludeDirs.Item(idx) = new_option;
402  SetModified(true);
403  }
404 }
405 
407 {
408  int idx = m_ResIncludeDirs.Index(option, s_case_sensitive);
409  if (idx != wxNOT_FOUND)
410  {
411  m_ResIncludeDirs.Item(idx) = new_option;
412  SetModified(true);
413  }
414 }
415 
416 void CompileOptionsBase::ReplaceLibDir(const wxString& option, const wxString& new_option)
417 {
418  int idx = m_LibDirs.Index(option, s_case_sensitive);
419  if (idx != wxNOT_FOUND)
420  {
421  m_LibDirs.Item(idx) = new_option;
422  SetModified(true);
423  }
424 }
425 
427 {
428  int idx = m_LinkerOptions.Index(option, s_case_sensitive);
429  if (idx != wxNOT_FOUND)
430  {
432  SetModified(true);
433  }
434 }
435 
437 {
438  int idx = m_LinkLibs.Index(option, s_case_sensitive);
439  if (idx != wxNOT_FOUND)
440  {
441  m_LinkLibs.RemoveAt(idx);
442  SetModified(true);
443  }
444 }
445 
447 {
448  int idx = m_CompilerOptions.Index(option, s_case_sensitive);
449  if (idx != wxNOT_FOUND)
450  {
452  SetModified(true);
453  }
454 }
455 
457 {
458  int idx = m_ResourceCompilerOptions.Index(option, s_case_sensitive);
459  if (idx != wxNOT_FOUND)
460  {
462  SetModified(true);
463  }
464 }
465 
467 {
468  wxString entry = UnixFilename(option);
469  int idx = m_IncludeDirs.Index(entry, s_case_sensitive);
470  if (idx != wxNOT_FOUND)
471  {
472  m_IncludeDirs.RemoveAt(idx);
473  SetModified(true);
474  }
475 }
476 
478 {
479  wxString entry = UnixFilename(option);
480  int idx = m_ResIncludeDirs.Index(entry, s_case_sensitive);
481  if (idx != wxNOT_FOUND)
482  {
484  SetModified(true);
485  }
486 }
487 
489 {
490  wxString entry = UnixFilename(option);
491  int idx = m_LibDirs.Index(entry, s_case_sensitive);
492  if (idx != wxNOT_FOUND)
493  {
494  m_LibDirs.RemoveAt(idx);
495  SetModified(true);
496  }
497 }
498 
500 {
501  m_CmdsBefore.Remove(command);
502  SetModified(true);
503 }
504 
506 {
507  m_CmdsAfter.Remove(command);
508  SetModified(true);
509 }
510 
512 {
513  wxString envopt = UnixFilename(script);
514  int idx = m_Scripts.Index(envopt, s_case_sensitive);
515  if (idx != wxNOT_FOUND)
516  {
517  m_Scripts.RemoveAt(idx);
518  SetModified(true);
519  }
520 }
521 
522 bool CompileOptionsBase::SetVar(const wxString& key, const wxString& value, bool onlyIfExists)
523 {
524  if (onlyIfExists)
525  {
526  StringHash::iterator it = m_Vars.find(key);
527  if (it == m_Vars.end())
528  return false;
529  it->second = value;
530  return true;
531  }
532 
533  m_Vars[key] = value;
534  SetModified(true);
535  return true;
536 }
537 
539 {
540  StringHash::iterator it = m_Vars.find(key);
541  if (it != m_Vars.end())
542  {
543  m_Vars.erase(it);
544  SetModified(true);
545  return true;
546  }
547  return false;
548 }
549 
551 {
552  m_Vars.clear();
553 }
554 
555 bool CompileOptionsBase::HasVar(const wxString& key) const
556 {
557  StringHash::const_iterator it = m_Vars.find(key);
558  if (it != m_Vars.end())
559  return true;
560 
561  return false;
562 }
563 
565 {
566  StringHash::const_iterator it = m_Vars.find(key);
567  if (it != m_Vars.end())
568  return it->second;
569 
570  static wxString emptystring = wxEmptyString;
571  return emptystring;
572 }
573 
574 const StringHash& CompileOptionsBase::GetAllVars() const
575 {
576  return m_Vars;
577 }
virtual bool UnsetVar(const wxString &key)
void Remove(const wxString &sz)
wxArrayString m_LinkLibs
wxArrayString m_CmdsBefore
virtual void SetResourceCompilerOptions(const wxArrayString &resourceCompilerOpts)
virtual bool SupportsCurrentPlatform() const
virtual void AddCommandsAfterBuild(const wxString &command)
virtual void SetLibDirs(const wxArrayString &libDirs)
virtual void ReplaceLinkLib(const wxString &option, const wxString &new_option)
int Index(const wxString &sz, bool bCase=true, bool bFromEnd=false) const
Definition: globals.h:157
virtual void RemoveCompilerOption(const wxString &option)
wxArrayString m_ResIncludeDirs
virtual void RemoveIncludeDir(const wxString &option)
virtual void AddBuildScript(const wxString &script)
virtual const wxArrayString & GetCompilerOptions() const
virtual void RemovePlatform(int platform)
virtual void AddIncludeDir(const wxString &option)
virtual void AddPlatform(int platform)
virtual int GetPlatforms() const
virtual void RemoveLibDir(const wxString &option)
virtual void SetLinkLibs(const wxArrayString &linkLibs)
virtual const wxArrayString & GetBuildScripts() const
#define wxNOT_FOUND
virtual void SetPlatforms(int platforms)
virtual void ReplaceLinkerOption(const wxString &option, const wxString &new_option)
virtual void RemoveLinkLib(const wxString &option)
virtual void SetCompilerOptions(const wxArrayString &compilerOpts)
wxArrayString m_CompilerOptions
virtual void AddResourceIncludeDir(const wxString &option)
virtual void ReplaceResourceCompilerOption(const wxString &option, const wxString &new_option)
DLLIMPORT wxString UnixFilename(const wxString &filename, wxPathFormat format=wxPATH_NATIVE)
Definition: globals.cpp:228
virtual const wxArrayString & GetResourceIncludeDirs() const
virtual const wxArrayString & GetLinkerOptions() const
virtual void AddLinkLib(const wxString &option)
virtual void AddCommandsBeforeBuild(const wxString &command)
virtual const wxArrayString & GetLinkLibs() const
virtual void AddCompilerOption(const wxString &option)
wxArrayString m_ResourceCompilerOptions
virtual void AddLibDir(const wxString &option)
virtual const wxArrayString & GetResourceCompilerOptions() const
wxArrayString m_LinkerOptions
virtual void SetModified(bool modified)
wxString & Item(size_t nIndex)
virtual void SetIncludeDirs(const wxArrayString &includeDirs)
virtual void SetCommandsBeforeBuild(const wxArrayString &commands)
virtual const wxArrayString & GetCommandsAfterBuild() const
virtual void AddResourceCompilerOption(const wxString &option)
wxString wxEmptyString
virtual void SetAlwaysRunPostBuildSteps(bool always)
virtual void RemoveLinkerOption(const wxString &option)
virtual const wxArrayString & GetIncludeDirs() const
virtual void ReplaceIncludeDir(const wxString &option, const wxString &new_option)
virtual void SetLinkerOptions(const wxArrayString &linkerOpts)
virtual void ReplaceLibDir(const wxString &option, const wxString &new_option)
virtual void RemoveBuildScript(const wxString &script)
virtual bool GetAlwaysRunPostBuildSteps() const
virtual const wxArrayString & GetLibDirs() const
virtual bool SetVar(const wxString &key, const wxString &value, bool onlyIfExists=false)
virtual void RemoveResourceIncludeDir(const wxString &option)
virtual bool HasVar(const wxString &key) const
virtual void SetResourceIncludeDirs(const wxArrayString &resIncludeDirs)
size_t Add(const wxString &str, size_t copies=1)
virtual void ReplaceCompilerOption(const wxString &option, const wxString &new_option)
virtual void RemoveCommandsAfterBuild(const wxString &command)
size_t GetCount() const
virtual const wxString & GetVar(const wxString &key) const
wxArrayString m_CmdsAfter
virtual void AddLinkerOption(const wxString &option)
void RemoveAt(size_t nIndex, size_t count=1)
virtual void RemoveCommandsBeforeBuild(const wxString &command)
virtual void ReplaceResourceIncludeDir(const wxString &option, const wxString &new_option)
virtual const StringHash & GetAllVars() const
virtual bool GetModified() const
wxArrayString m_IncludeDirs
virtual void SetBuildScripts(const wxArrayString &scripts)
virtual void UnsetAllVars()
virtual void SetCommandsAfterBuild(const wxArrayString &commands)
Definition: globals.h:161
virtual void RemoveResourceCompilerOption(const wxString &option)
virtual const wxArrayString & GetCommandsBeforeBuild() const