The main program typically simply starts wx.Build.BuildProject.Build(string[]). This method interprets command line options as described in the documentation of class wx.Build.CommandLineOptions.
Some excerpts from the wx.NET build program may exemplify this.
First, you need a class defining the projects as static properties.
public class BuildProgram {
wx-c.dll
, or ELF library libwx-c.so
respectively. static wx.Build.Cxx.DynamicLibraryProject _wxCProject = null; public static Cxx.DynamicLibraryProject WxCProject { get { if (_wxCProject == null) { _wxCProject = new Cxx.DynamicLibraryProject(ProjectPreference.Default, "wx-c", ".", "wx-c", "The native code of the wx.NET project."); _wxCProject.AddStaticLibrary(wxProject.CreateRefToFileProject()); // Reference to the project providing the wxWidgets libraries _wxCProject.AddCPlusPlusSources(new FileSelector(ContentType.CPlusPlusCode, "../Src/wx-c", "*.cxx", "wx.NET C++ sources.")); _wxCProject.AddHeaderFiles(new FileSelector(ContentType.CCPlusPlusInclude, "../Src/wx-c", "*.h", "wx.NET C++ includes.")); _wxCProject.AddRCFile(new ContentFile(ContentType.RCFile, "../Src/wx-c/windows.rc")); } return _wxCProject; } }
Projects may depend on each other. The wx-c.dll
depends on the wxWidgets libraries. The next project will build the wx.NET.dll providing the managed part of the wx.NET project. Thsi project is of the second important type for building managed code from C# sources.
static wx.Build.Net.CSharpAssemblyProject _wxNetProject=null; public static Net.CSharpAssemblyProject WxNetProject { get { if (_wxNetProject==null) { _wxNetProject = new Net.CSharpAssemblyProject(ProjectPreference.Default, "wx.NET", "wx.NET.dll", "The managed part of the wx.NET implementation."); _wxNetProject.CSharpSources = new FileSelector(ContentType.CSharpCode, "../Src/wx.NET", "*.cs", "wx.NET C# source files."); _wxNetProject.ReferencesAssemblies = new ContentFiles(ContentType.DotNetDll, ContentFileLocation.GlobalAssemblyCache, "System.dll", "System.Drawing.dll", "System.Xml.dll"); _wxNetProject.PInvokeDependencies = WxCProject.CreateRefToSingleFileProject(); _wxNetProject.Signature = new ContentFile(ContentType.SnKeys, "../Src/wx.NET/keys.snk"); _wxNetProject.Features.Add(new FeatureEntry("Styled Text Control", "Enables namespace wx.StyledText", "WXNET_STYLEDTEXTCTRL"), true); _wxNetProject.Features.Add(new FeatureEntry("Display Access", "Enables class wx.Display", "WXNET_DISPLAY"), true); } return _wxNetProject; } }
This project exhibits some features: Services of the resulting program that are optional.
The next step is usually the definition of at least one project building a program. The wx.NET provides several programs - samples as well as utilities. The following sniplet will define the project to build the controls.exe
program demonstrating the contained controls.
public static .Net.CSharpAssemblyProject SampleControls { get { Net.CSharpAssemblyProject project = new Net.CSharpAssemblyProject(ProjectPreference.Default, "Controls Demo", "controls.exe", "wx.NET sample program on controls."); project.CSharpSources = new FileSelector(ContentType.CSharpCode, "../Samples/Controls", "*.cs", "C# Sources of controls.exe."); project.ReferencesAssemblies = new FileProducts(ContentType.DotNetDll, new ContentFiles(ContentType.DotNetDll, ContentFileLocation.GlobalAssemblyCache, "System.dll", "System.Drawing.dll"), WxNetProject.CreateRefToFileProject()); project.Signature = new ContentFile(ContentType.SnKeys, "../Src/wx.NET/keys.snk"); project.WinIcon = new ContentFile(ContentType.ICO, "../Src/wx.NET/mondrian.ico"); ICollection<ResourceDesignator> externalResources = ResourceDesignator.SelectExternalResources(ContentType.XPM, "../Samples/Controls/Icons", "*.xpm", "../Samples/Controls/Icons"); externalResources.Add(new ResourceDesignator(ContentType.PNG, "../Samples/Controls/mondrian.png", "../Samples/Controls/mondrian.png")); project.ExternalResources = externalResources; #region Additionally, we want the soruces to be copied project.AddExternalResources(ResourceDesignator.SelectExternalResources(ContentType.CSharpCode, "../Samples/Controls", "*.cs", "../Samples/Controls")); #endregion } }
Finally, you will need a main function running the actual build program. wx.Build provides some static functions with class wx.Build.BuildProject to build all projects defined in an assembly. These functions will enumerate all classes defined by these assemblies and look for static properties providing instances of class wx.Build.BuildProject. The properties, that we defined above, provide such build projects since wx.Build.Net.CSharpAssemblyProject and wx.Build.Cxx.DynamicLibraryProject extend this class. You can enable the user to configre the build using options provided in the argument list of the build program and environment variables. wx.Build provides a standard parser for program options by class wx.Build.CommandLineOptions. Refer to the remarks on this class for the options that cen be parsed. Another class wx.Build.BuildConfig is meant to manage configurations of the build process. Such configurations can be named. Two configurations are predefined: "Release" (default) and "Debug". Another important property of this class is wx.Build.BuildConfig.PathRootVariable
. This variable defines the name of an environment variable that holds the base path of the build program. The base path is tha path that will be used to complete all relative paths that occur in the parameters of build projects. out build program will user this parser. Therefore, we will use a static functions of wx.Build.BuildProject that expects program options as arguments and will conduct the build process.
public static int Main(string[] args) { BuildConfig.PathRootVariable = "wxNetBase"; return BuildProject.Build(args); } } }
That's all. Now we can compile this program let's say into a program "wxSampleBuild.exe"
and start a build process e.g. using the following call within a command shell:
> wxSampleBuild.exe /log=aLogFileName