<?xml version="1.0"?>
<document>
  <properties>
    <author email="dev@apr.apache.org">APR Developers</author>
    <title>Compiling APR for Microsoft Windows</title>
  </properties>
<body>

<section id="overview">
<title>Overview</title>

<p>APR can be built on Windows using a cmake-based build system or with Visual
Studio project files maintained by APR developers.  The cmake-based build system
directly supports more versions of Visual Studio but currently has considerable
functional limitations.</p>

</section>

<section id="vstudio">
<title>Building APR with the Included Visual Studio Project Files</title>

<section id="requirements">
<title>Requirements</title>

<p>Compiling apr, apr-iconv and/or apr-util requires the following environment 
   to be properly installed:</p>

<ul>

<li>A <a
    href="https://visualstudio.microsoft.com/">suitable Microsoft compiler</a>:
    such as: Microsoft Visual C++ 5.0 or higher; Microsoft Visual Studio .NET
    2002 or higher (with Visual C++ .NET compiler).  We have not yet tried
    the 'Express' versions of Visual Studio .NET 2005 and are unable to
    provide support for them.
</li>

<li>Follow the <a href="#layout">required directory layout</a>.</li>

</ul>

<p>APR can be built using the <a href="#commandline">command line tools</a>, or
from within the <a href="#workspace">graphical IDE</a> (Visual Studio IDE
Workbench or Microsoft Development Environment).</p>

<p class="note">
    <strong>Visual C++ 5.0 users only</strong>: The Windows Platform SDK.
    Visual C++ 5.0 developers need the updated Microsoft Windows Platform SDK
    to enable some APR features.  The Platform SDK files distributed with
    Visual C++ 6.0 and later are sufficient, so those users may skip this
    requirement.  The Windows Platform SDK update is required to enable all
    supported features with MSVC++ 5.0.  Without a current version, APR will
    issue warnings under MSVC++ 5.0 or fail to build entirely.  Look for the
    update on Microsoft's website - we are afraid they change the link too
    often to cite.
</p>

</section>

<section id="layout">
<title>Required Directory Layout</title>

<p>For a supported build, you must have apr, apr-iconv, and apr-util
   checked-out in parallel directories.  For example:</p>

<blockquote><pre>
C:\work\apr\
C:\work\apr-iconv\
C:\work\apr-util\
</pre></blockquote>

<p>For a release, unzipping the release files into this directory layout
should be sufficient.</p>

<p>To track development, please read the information on <a
href="anonsvn.html">checking out from Subversion</a>.  We recommend <a
href="https://tortoisesvn.net/">TortoiseSVN</a> on Win32 platforms.</p>

<p>Currently, the directories <strong>must</strong> be called apr, apr-iconv,
and apr-util.  No exceptions.</p>

</section>

<section id="workspace">
<title>Developer Studio Workspace/Microsoft Development Environment IDE Build</title>

<p>APR can be compiled using Visual C++'s graphical environment.
   To simplify this process, a complete Visual Studio workspace,
   <code>apr-util/aprutil.dsw</code>, is provided.  This workspace exposes the
   entire list of working .dsp projects that are required for the complete APR
   binary release.  It includes dependencies between the projects to assure
   that they are built in the appropriate order.</p>

<p>These workspaces are shipped in the Visual Studio 6.0 format - however,
   you can safely 'upgrade' them to your current Visual Studio release (i.e.
   Visual Studio 2003 .NET).  However, for compatibility and simplicity, we
   only distribute Visual Studio 6.0 workspaces.  See below for <a
   href="#convert5">converting the workspaces for Visual Studio 5.0</a>.</p>

<p>Open the apr-util/aprutil.dsw workspace, and choose either aprutil or
   libaprutil (for static or dynamic libraries) with the Release or Debug
   build as the Active Project.  aprutil.dsw causes all related projects to 
   be built.</p>

<p>You can then choose 'Build Solution' or 'Build Project' to build the
   libraries and the dependencies.</p>

<p>The apr test environment can be compiled using VC++'s Visual Studio
   development environment with the apr/test/aprtest.dsw project.
   This workspace exposes the apr/apr.dsp static library and the 
   apr/test/aprtest.dsp projects that allow the developer to assemble the
   entire test application suite.</p>

<p class="note">
   <strong>Historical Build Note</strong> (does not apply to releases after
   1.1.1):
   If you are doing a Visual Studio 5.0/6.0 Graphical build, it will only find
   awk.exe from the <u>T</u>ools menu <u>O</u>ptions... Directories settings
   for the Executable files.  Add the path for awk.exe to this list, as needed.
   For Visual Studio .NET 2003 and newer, you may need to copy awk to the
   Common7\Tools\Bin directory (i.e. where RC.exe is) - it no longer has the
   specific PATH options (as far as we can tell).
</p>

</section>

<section id="commandline">
<title>Command-Line Build</title>

<p>If you use the command line, you must configure it:</p>

<blockquote>
  <code>"C:\Program Files\DevStudio\VC\Bin\vcvars32.bat"</code>
</blockquote>

<p>If necessary, you will also need to prepare the Platform SDK environment:</p>

<blockquote>
  <code>"C:\Program Files\Platform SDK\setenv.bat"</code>
</blockquote>

<p>cd to the apr-util directory.  Now, simply use one of the following
   commands to compile the static or dynamic libraries, respectively, on
   Visual C++ 6.0 or later:</p>

<blockquote><pre>
msdev aprutil.dsw /MAKE \
  apriconv - Win32 Release" \
  apr - Win32 Release" \
  libapr - Win32 Release" \
  gen_uri_delims - Win32 Release" \
  xml - Win32 Release" \
  "aprutil - Win32 Release"

msdev aprutil.dsw /MAKE \
  libapr - Win32 Release" \
  libapriconv - Win32 Release" \
  gen_uri_delims - Win32 Release" \
  xml - Win32 Release" \
  libaprutil - Win32 Release"
</pre></blockquote>

<p>Either command will compile APR. The latter will build the libraries as
   .dll dynamic shared libraries, rather than static libraries.</p>

<p>Replace <code>Release</code> with <code>Debug</code> to include debugging
   information in the resulting files, making it easier to find bugs and
   track down problems.</p>

<p class="note">
   <strong>For Visual Studio C++ 5.0 command line users</strong>:
   Only the .dsp files are maintained within Subversion.  Win32 .mak
   files are NOT maintained in Subversion, due to the tremendous waste
   of reviewer's time.  Therefore, you cannot rely on the NMAKE
   commands above to build revised .dsp project files unless you then
   export all .mak files yourself from the project.
</p>

</section>
<section id="integrating">
<title>Integrating the Library</title>

<p>We should tell ya'll 'bout this, no?</p>

</section>

<section id="components">
<title>Library Components</title>

<p>The apr-util/aprutil.dsw workspace builds the .dsp projects of the 
   Apache server listed with dependent projects preceeding their
   dependencies:</p>

<ol>
   <li><code>apr-util\aprutil.dsp</code></li>
   <li><code>apr-util\libaprutil.dsp</code></li>
   <li><code>apr-util\uri\gen_uri_delims.dsp</code></li>
   <li><code>apr-util\xml\expat\lib\xml.dsp</code></li>
   <li><code>apr-iconv\apriconv.dsp</code></li>
   <li><code>apr-iconv\libapriconv.dsp</code></li>
   <li><code>apr\apr.dsp</code></li>
   <li><code>apr\libapr.dsp</code></li>
</ol>

<p>The libXXX projects create .dll targets, dynamic shared libraries.
   Their non-libXXX counterparts create static .lib targets.</p>

<p>To compile code for the libraries, the consuming compiliation must
   include the apr/include and apr-util/include directories in their
   include file search paths.  To target the static .lib versions of
   the library, the consuming compiliation must define the macros
   APR_DECLARE_STATIC and APU_DECLARE_STATIC.  This prevents the apr
   and apr-util symbols from being tagged as __declspec(dllimport),
   eliminating compiliation warnings and speeding up execution.</p>


</section>

<section id="convert5">
<title>Converting the Project for Visual C++ 5.0</title>

<p>The .dsp project files are distributed in Visual C++ 6.0 format.  Visual
   C++ 5.0 (97) will recognize them.  To quickly prepare the .dsp files in 
   the native Visual Studio 5.0 (97) format, you can run this command
   from the top-level apr directory (above apr, apr-util and apr-iconv):</p>
<blockquote>
  <code>perl apr\build\cvtdsp.pl -5</code>
</blockquote>

<p>You must type this command from the <em>top level</em> directory of the apr
source tree.  Every VC6 .dsp project file within the current directory and
below will be listed as it is converted.  If you contribute back a patch that
revises project files, please convert them back with the the -6 option instead
of -5, which returns the project files to Visual Studio 6.0 format.</p>

</section>
</section>

<section id="cmake">
<title>Building APR with cmake</title>

<p>The primary documentation for this build mechanism is in the 
<code>README.cmake</code> files in the APR and APR-util projects.  Refer to those
files for detailed instructions.</p>

<p>The primary limitations of the cmake-based build are shown below.  Other
considerations are described in <code>README.cmake</code>.</p>

<ul>
  <li>No cmake build for the APR-iconv subproject is available, and the
    APR-util cmake build cannot consume an existing APR-iconv build.</li>
  <li>The cmake build for the APR-util subproject does not support most of the
    optional DBM and DBD libraries supported by the included Visual Studio
    project files.</li>
</ul>

</section>

</body>
</document>
