The Allegro Wiki is migrating to github at https://github.com/liballeg/allegro_wiki/wiki

MSVC Project Files

From Allegro Wiki
Jump to: navigation, search

Overview

As of Allegro 4.2.1, it is not possible to build Allegro exclusively with MSVC, mainly because of incompatible assembler code. Work is currently in progress to remedy this. Patches to allow a C-only build of Allegro have been applied and will appear in versions 4.2.2 and 4.9.2.

Matthew Leverton is currently working on creating MSVC project files. The plan is to include project files for MSVC 6, 7, and 8 with the Allegro distribution. They will be capable of building the library, the demo, tools, and examples.

Status

MSVC 6

The following projects have been created:

  • Allegro (split into DLL / LIB due to MSVC 6 limitations)
  • Demo
  • Examples
  • Tests
  • Tools

See Build/MSVC_6#Project_File for a working example based on the 4.9.1 release.

The project files are plain text in a psuedo makefile format. Most of the options are stored via comments. It's ugly, but easy to automatically generate. The automation scripts are nearly completed.

Limitations

  • Due to MSVC 6 bugs, it takes two or three builds to complete. (First it may fail to see a lib, then it may fail to link against it.)

MSVC 7 and 8

MSVC 7 and 8 use the same basic project file type. Unlike MSVC 6, the same project can build both Lib and DLL targets.

The following projects are automatically generated:

  • Allegro
  • Demo
  • Examples
  • Tests
  • Tools

Untested on VC 2005 Express.


Automation Process

The automation process is handled via a PHP script. This will allow anyone to generate the project files without needing to have access to any version of Visual Studio or Windows. The script is hard coded to build the following projects:

  • Allegro (Library)
  • Demo
  • Examples
  • Tests
  • Tools

However, almost everything is dynamically configured. A single configuration file lists which files need to be included. Wildcards are supported, so only a little upkeep will be necessary.

File Layout

The main script just reads through the configuration file to figure out which projects to build. The actual work is done by several objects. The layout currently looks like:

  • class
    • ProjectWriter
      • MSVC6.class.php
      • MSVC8.class.php
    • SolutionWriter
      • MSVC6.class.php
      • MSVC8.class.php
    • Project.class.php
    • ProjectWriter.class.php
    • Solution.class.php
    • SolutionWriter.class.php
    • Target.class.php
  • projects
    • msvc6
    • msvc8
  • make.php
  • files.php

Sample

<highlightSyntax language="php3">

  1. The Solution holds one or more projects.

$solution = new Solution("My Game");

  1. The project can contain one or more targets

$project = new Project("My Game"); $project->addFile("include/game.h"); $project->addFile("src/game.c");

  1. The target is a certain build configuration (eg: Debug or Release)

$target = new Target; $target->mode = "release"; $target->output_dir = "bin"; $target->working_dir = "obj"; $target->filename = "game.exe";

  1. associate everything with each other

$solution->addProject($project); $project->addTarget($target);

  1. create the project files

$solution->save(new SolutionWriter_MSVC6); $solution->save(new SolutionWriter_MSVC8); </highlightSyntax>

Justification

Creating project files is a boring task, and therefore no one will want to maintain them. So hopefully this process won't have to change with Allegro. A simpler, one-off script most likely would have to be continuously hacked as Allegro changes; in the long term, it could be more trouble than its worth.

This format is very flexible. For example, one could write classes to handle saving to an XCode project file or even a Makefile. It also doesn't have to be limited to Allegro. It could obviously be used to create project files for your own projects.