Integration of SBuild and Microsoft Visual Studio
|
Back to Command
line user |
Table of content
|
Overview Using your SBuild build script, you can generate Visual Studio project files. You can use those project files to fire an SBuild build without leaving Visual Studio or to fire a debugging session. Here is a very short overview:
Important warning: although it is possible to use SBuild through Visual Studio, that is fairly limited. Only the basic functionality is available in this way. For example, most features related to the C pre-processor and to the C parser included in SBuild are not surfaced, the parallel build is not possible, etc. The full power of SBuild is only available through the command line. |
The msdev action
SBuild implements an action, called msdev, to generate the Microsoft project files. For example, if you do build_something.py -b to build some application, then you use build_something.py action=msdev(...) to generate the project files that will cover the same build. Here are all the possibilities of this action with extensive explanations:
Note that -M, start8 and start are only provided for convenience. If ever the scanning of the registry fails, or starting the IDE fails, you can always and reliably use the init8 and init and then click on the generated files. init8 and init will generate the Microsoft project files even if no Visual Studio at all is installed on your machine. The generated project files have been tested with Visual Studio 2005 and with Visual Studio 6. They also work with Visual Studio 2008, although SBuild is not yet able to start it automatically. |
Inside the IDE Once you have the IDE started, you will notice a number of Visual Studio Project Configurations larger than what you use to have (you are likely used to see two of them, called "Debug" and "Release"). Now you will see 6 or more. The reason is that, within the IDE, you always start SBuild in the same way: by starting a build (shortcut F7). So you choose one Project Configuration to decide what SBuild will do for you. Here are the 6 configurations that SBuild puts in the generated .vcproj (the actual names are longer, this simplification for easier understanding):
The first 2 configurations are independent of the target platform that you build for. By contrast, the last configurations are dependent and they are duplicated for every target platform you specified to init8 or init. More precisely, they are duplicated for each and every pair of <tgtplatform>:<toolchain>. See also explanation further below. Take note that, among the configurations listed above, it only makes sense to hit F5 (to start a debugging session) for 2 configurations:
Other details:
|
Screen snapshots |
Despite the many limitations compared to command line SBuild, there are also some advantages. A few are the ones that you expect in any IDE. For example:
Beyond that, the one and only significant advantage is that you can build from within one Visual Studio using the compilers of other versions of Visual Studio and also Cygwin and MinGW. You need to provide a lengthy action=msdev(init,...) but it is well worth the effort. Here is the extended syntax of init8 and init, explained through examples:
As you may expect, during generation, SBuild prints out the capabilities of the generated project file. You may check in this way if your command line options have been understood as you expected. Note also that no space is allowed in your possibly long action=msdev(...), a limitation of the shell, not of SBuild. |
Limitations for Visual Studio 2005 The most important limitation is the fact that the generation is a one-shot operation, not a continuous one. While you work in the IDE, if you edit a build script so that new sources files are now part of the build, the File View (in the left pane of the IDE windows) will NOT be automatically updated. Note that the build will always be accurate, it is only the list of files in the left pane that is not automatic. There are two workarounds for that:
An important limitation is that you cannot distribute the generated .vcproj/.dsp files unless you also distribute the SBuild tool itself. That is because the generated Microsoft projects still use under the hood the SBuild build scripts for building and cleaning your software. It is theoretically possible to generate Microsoft project files that are completely independent of SBuild but extremely difficult to make the build the same (through IDE versus through command line). Another limitation is the fact that you can debug only one executable. You build script may well build hundred executables, hitting F5 will only start the first of them. That is why, when you intend to build and debug executables, we highly advice you to use tgt=<my_exec_target> together with action=msdev(...) on the command line when you generate the project files. That makes that only one executable is built and that removes any confusion about which one will start. Know also that, if you configured your build script so that -r runs the built executable with parameters (or several times with several sets of parameters), those parameters will not be used when you start a debugging session with F5. You can still run your executable with those parameters (by choosing a "run" Project Configuration and hitting F7). You can still debug your built executables with parameters but you have to fill them in by hand (Alt-F7). Another limitation is the fact that almost all command line options on the call with action=msdev(...) are either ignored or refused. The following 4 parameters may be provided and will be remembered by the generated Microsoft project files:
Another limitation is the fact that the source files are shown in the left pane in a flat list. There is no structure (for example, grouping by SBuild targets of the sources) and the order is chosen by Visual Studio. Related to that, also notice that SBuild generates one .vcproj (or .dsp) for one run. You can have as many generated .vcproj next to each other but SBuild will not assemble them into one larger .sln (or larger .dsw). You can do that easily by hand if you desire or with a script that calls several build scripts with action=msdev(...) and also writes the .sln at the end. Another limitation is that this action=msdev() is not compatible with advanced customization of the SBuild project. That is because the msdev action needs to know a priori all the target platforms and all the tool chains that will be used from within the IDE (in order to generate that set of Project Configurations). If your SBuild projects is setting the value of tgtplatform and/or toolchain by program, the msdev(init,...) action will likely get confused. Limitations for Visual Studio 6 For Visual Studio 6 all the limitations above apply and then some more. The reason is the fact that the .dsp files store less information than the .vcproj files. Most important, there cannot be any information about how to run your just built executables under the debugger. So F5 will not work (out of the box). The workaround is to fire the dialog Project Setting (Alt-F7) and to fill in by hand what you want (the executable, the arguments, the current dir). Visual Studio stores this in a .opt binary file and it will remember it when you re-open this project (until you regenerate it). Finally, note that in Visual Studio 6 you will see two more Project configurations
And you clean selecting them and using F7, which is a bit counter intuitive for old time users. Fortunately, the cleaning is extremely rarely used (because the incremental build is so accurate with SBuild). |
Back to Command
line user |