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 
6 #ifndef COMPILETARGETBASE_H
7 #define COMPILETARGETBASE_H
8 
9 #include "compileoptionsbase.h"
10 
11 /** Enum that defines the option's relation types */
12 enum OptionsRelationType
13 {
14     ortCompilerOptions = 0, /**< Compiler option */
15     ortLinkerOptions, /**< Linker option */
16     ortIncludeDirs, /**< Compiler include dir option */
17     ortLibDirs, /**< Linker include dir option */
18     ortResDirs, /**< Resource compiler include dir option */
19 
20     ortLast
21 };
22 
23 /** Option's relation */
24 enum OptionsRelation
25 {
26     orUseParentOptionsOnly = 0, /**< The option uses parent options only */
27     orUseTargetOptionsOnly, /**< The option uses target options only */
28     orPrependToParentOptions, /**< The option uses parent options appended to target options */
29     orAppendToParentOptions /**< The option uses target options appended to parent options */
30 };
31 
32 /** Enum to define the type of output the target produces */
33 enum TargetType
34 {
35     ttExecutable    = 0, /**< Target produces an executable */
36     ttConsoleOnly   = 1, /**< Target produces a console executable (without GUI) (distinction between ttExecutable and ttConsoleOnly happens only under Win32) */
37     ttStaticLib     = 2, /**< Target produces a static library */
38     ttDynamicLib    = 3, /**< Target produces a dynamic library */
39     ttCommandsOnly  = 4, /**< Target only runs commands in pre-build and/or post-build steps */
40     ttNative        = 5  /**< Target produces a native binary */
41 };
42 
43 enum MakeCommand
44 {
45     mcClean = 0,
46     mcDistClean,
47     mcBuild,
48     mcCompileFile,
49     mcAskRebuildNeeded,
50     mcSilentBuild,
51 
52     /// *Don't* use this. It's only used internally for enumerations...
53     mcLast
54 };
55 
56 /** A target's filename can either be auto-generated based on the running platform,
57   * or completely specified by the user. For more info, see
58   * CompileTargetBase::SetTargetFilenameGenerationPolicy.
59   */
60 enum TargetFilenameGenerationPolicy
61 {
62     tgfpPlatformDefault = 0, ///< Generate filename based on running platform defaults.
63     tgfpNone ///< No automatic generation; let the user specify the full filename.
64 };
65 
66 /**
67   * @brief Base class for build target classes
68   * Each Code::Blocks project
69   * consists of at least one target. Each target has different settings,
70   * e.g.:
71   * \li Build options,
72   * \li Output type,
73   * \li Execution parameters, etc.
74   * \n\n
75   * This class holds the settings of one build target.
76  */
77 class DLLIMPORT CompileTargetBase : public CompileOptionsBase
78 {
79     public:
80         CompileTargetBase();
81         ~CompileTargetBase() override;
82 
83         /** A target's filename can either be auto-generated based on the running platform,
84           * or completely specified by the user. Calling this function sets the
85           * filename generation method.
86           * @par The filename is divided in 4 parts. Let's see how "Debug/libSomeLib.a"
87           * is divided:
88           * @li the directory part: @c Debug,
89           * @li the filename's prefix: @c lib,
90           * @li the base name: @c SomeLib and
91           * @li the extension: @c a
92           * @par
93           * Calling this function defines if the prefix and extension are auto-generated
94           * or are left as the user specified. So, if the prefix is set to auto-generated
95           * (i.e. @c tgfpPlatformDefault), it would be set depending on the running
96           * platform and compiler, e.g.:
97           * @li Windows & GCC: @c lib
98           * @li Windows & MSVC: @c \<empty\>
99           * @li Linux & <*>: @c lib
100           * @par
101           * The default generation policy is @c tgfpPlatformDefault for both the prefix
102           * and the extension.
103           * @note The ProjectLoader detects old projects when loaded and, for those, it
104           * sets the default generation policy to @c tgfpNone (i.e. no auto-generation)
105           * for both the prefix and the extension. This is done so the user doesn't
106           * notice any unexpected behaviour...
107           */
108         virtual void SetTargetFilenameGenerationPolicy(TargetFilenameGenerationPolicy prefix,
109                                                         TargetFilenameGenerationPolicy extension);
110         virtual void GetTargetFilenameGenerationPolicy(TargetFilenameGenerationPolicy& prefixOut,
111                                                         TargetFilenameGenerationPolicy& extensionOut) const;
112 
113         virtual const wxString& GetFilename() const;
114         virtual const wxString& GetTitle() const; ///< Read the target's title
115         virtual void SetTitle(const wxString& title); ///< Set the target's title
116         virtual void SetOutputFilename(const wxString& filename); ///< Set the target's output filename
117         virtual void SetImportLibraryFilename(const wxString& filename); ///< Set the target's import library filename
118         virtual void SetDefinitionFileFilename(const wxString& filename); ///< Set the target's definition file filename
119         virtual void SetWorkingDir(const wxString& dirname); ///< Set the target's working dir on execution (valid only for executable targets)
120         virtual void SetObjectOutput(const wxString& dirname); ///< Set the target's objects output dir
121         virtual void SetDepsOutput(const wxString& dirname); ///< Set the target's dependencies output dir
122         virtual OptionsRelation GetOptionRelation(OptionsRelationType type) const; ///< Read the target's options relation for \c type
123         virtual void SetOptionRelation(OptionsRelationType type, OptionsRelation rel); ///< Set the target's options relation for \c type to \c rel
124         virtual wxString GetWorkingDir(); ///< Read the target's working dir for execution (valid only for executable targets)
125         virtual wxString GetObjectOutput() const; ///< Read the target's objects output dir
126         virtual wxString GetDepsOutput() const; ///< Read the target's dependencies output dir
127         virtual wxString GetOutputFilename() const; ///< Read the target's output filename
128         virtual wxString SuggestOutputFilename() const; ///< Suggest a filename based on the target's type
129         virtual wxString GetExecutableFilename() const; ///< Read the target's executable filename (produced if target type is ttExecutable)
130         virtual wxString GetDynamicLibFilename() const; ///< Read the target's dynamic library filename (produced if target type is ttDynamicLib)
131         virtual wxString GetDynamicLibImportFilename(); ///< Read the target's dynamic library import filename (produced if target type is ttDynamicLib)
132         virtual wxString GetDynamicLibDefFilename(); ///< Read the target's dynamic library definition file filename (produced if target type is ttDynamicLib)
133         virtual wxString GetStaticLibFilename() const; ///< Read the target's static library filename (produced if target type is ttStaticLib)
134         virtual wxString GetNativeFilename() const; ///< Read the target's native filename (produced if target type is ttNative)
135         virtual wxString GetBasePath() const; ///< Read the target's base path, e.g. if GetFilename() returns "/usr/local/bin/xxx", base path will return "/usr/local/bin"
136         virtual void SetTargetType(TargetType pt); ///< Set the target's type to \c pt
137         virtual TargetType GetTargetType() const; ///< Read the target's type
138         virtual const wxString& GetExecutionParameters() const; ///< Read the target's execution parameters
139         virtual void SetExecutionParameters(const wxString& params); ///< Set the target's execution parameters to \c params
140         virtual const wxString& GetHostApplication() const; ///< Read the target's host application
141         virtual void SetHostApplication(const wxString& app); ///< Set the target's host application to \c app
142         virtual bool GetRunHostApplicationInTerminal() const; ///< Get the flag if the host app should be run in terminal
143         virtual void SetRunHostApplicationInTerminal(bool in_terminal); ///! Set the flag if the host app should be run in terminal
144         virtual void SetCompilerID(const wxString& id); ///< Set the target's compiler
GetCompilerID()145         virtual const wxString& GetCompilerID() const { return m_CompilerId; } ///< Read the target's compiler
GetMakeCommandFor(MakeCommand cmd)146         virtual wxString GetMakeCommandFor(MakeCommand cmd) const { return m_MakeCommands[cmd]; } ///< Get the "make" command used for @c cmd
147         virtual void SetMakeCommandFor(MakeCommand cmd, const wxString& make); ///< Set the "make" command used for @c cmd
MakeCommandsModified()148         virtual bool MakeCommandsModified() const { return m_MakeCommandsModified; } ///< True if any of the "make" commands is modified.
149     protected:
150         friend class cbProject;
151 
152         mutable wxString m_Filename;
153         wxString m_Title;
154         mutable wxString m_OutputFilename;
155         wxString m_ImportLibraryFilename;
156         wxString m_DefinitionFileFilename;
157         wxString m_WorkingDir;
158         wxString m_ObjectOutput;
159         wxString m_DepsOutput;
160         wxString m_ExecutionParameters;
161         wxString m_HostApplication;
162         OptionsRelation m_OptionsRelation[ortLast];
163         TargetType m_TargetType;
164         wxString m_CompilerId;
165         wxString m_MakeCommands[mcLast];
166         bool m_MakeCommandsModified;
167         bool m_RunHostApplicationInTerminal;
168         TargetFilenameGenerationPolicy m_PrefixGenerationPolicy;
169         TargetFilenameGenerationPolicy m_ExtensionGenerationPolicy;
170     private:
171         void GenerateTargetFilename(wxString& filename) const;
172 };
173 
174 #endif // COMPILETARGETBASE_H
175