<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.12: http://docutils.sourceforge.net/" />
<title>Bundling base components as zip files for the Windows build</title>
    
    <link rel="stylesheet" type="text/css" href="css/html4css1.css" />
    <link rel="stylesheet" type="text/css" href="css/stylesheet.css" />
    
  </head>
  <body>
    
    <div id="header">
      <a href="index.html">
        <img src="icons/phenix-logo-small.jpg" alt="PHENIX" />
        <span>
          <strong>P</strong>ython-based
          <strong>H</strong>ierarchical
          <strong>EN</strong>vironment
          for
          <strong>I</strong>ntegrated
          <strong>X</strong>tallography
        </span>
      </a>
    </div>
    
    <div class="document" id="bundling-base-components-as-zip-files-for-the-windows-build">
<h1 class="title">Bundling base components as zip files for the Windows build</h1>
<div class="contents topic" id="contents">
<p class="topic-title first">Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#introduction" id="id1">Introduction</a></li>
<li><a class="reference internal" href="#python-2-7" id="id2">Python 2.7</a><ul>
<li><a class="reference internal" href="#creating-the-python-bundle" id="id3">Creating the python bundle</a></li>
</ul>
</li>
<li><a class="reference internal" href="#hdf5-library" id="id4">HDF5 library</a><ul>
<li><a class="reference internal" href="#adapting-build-scripts-to-visual-studio-2008" id="id5">Adapting build scripts to Visual Studio 2008</a></li>
<li><a class="reference internal" href="#doing-the-actual-build" id="id6">Doing the actual build</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="introduction">
<h1><a class="toc-backref" href="#id1">Introduction</a></h1>
<p>This document details how to create zip file bundles of python and the HDF5 library used
for the bootstrap build on Windows of CCTBX as  <a class="reference external" href="CCTBXBuild.html">described here</a> and
other software relying on CCTBX such as Phenix or Dials.
Unless you want to replace the Python or HDF5 bundle described here with your own versions you do not
need to read this document. The bootstrap build will just download existing bundles from cci.lbl.gov.</p>
<p>The two base components are bundled as zip files to be downloaded when building for Windows.
This is possible because binary compatibility of executables
with Windows has been retained over successive
versions of Windows apart from the distinction between the 32 and 64 bit platforms.
Therefore these base components are necessary to build one time only. Zipped up bundles of these
builds are then stored on
<a class="reference external" href="http://cci.lbl.gov/cctbx_dependencies">http://cci.lbl.gov/cctbx_dependencies</a> from where <tt class="docutils literal">bootstrap.py</tt> will download them
during the <tt class="docutils literal">base</tt> stage of the build. This happens around
lines 136 - 165 in <tt class="docutils literal">cctbx_project\libtbx\auto_build\install_base_packages.py</tt>, as of
07 April 2017, git SHA-1: 6c494c2...
The bootstrap build will uncompress the python bundle into <tt class="docutils literal">base\bin\python</tt> and the HDF5 bundle
into <tt class="docutils literal"><span class="pre">base\HDF5-1.8.16</span></tt> relative to where the bootstrap build is
done. Unlike the directory structure on Unix the respective library and
header files of these two bundles are stored as sub directories within these directories and not
in common <tt class="docutils literal">base\include</tt> and <tt class="docutils literal">base\lib</tt> directories.</p>
</div>
<div class="section" id="python-2-7">
<h1><a class="toc-backref" href="#id2">Python 2.7</a></h1>
<p>The first base component bundled is Python 2.7.12 with installed modules such as matplotlib,
numpy, biopython, wxPython, etc. Version 2.7.9 is the minimum version that provides tools like
&quot;pip install&quot; which makes it much easier to enhance python with 3rd party modules from
<a class="reference external" href="https://pypi.python.org">https://pypi.python.org</a>.</p>
<div class="section" id="creating-the-python-bundle">
<h2><a class="toc-backref" href="#id3">Creating the python bundle</a></h2>
<p>The first step is to download and install python2.7.9 (or higher) to your PC. Unfortunately
the Python for Windows installer is too clever for its own good. It will try to overwrite any
existing Python installation on your PC as well as the registry key that specifies the
existing installation, <tt class="docutils literal">HKEY_CURRENT_USER\Software\Python\PythonCore\2.7\InstallPath</tt></p>
<p>To deal with this the easiest thing may be to either uninstall the existing python or to
make a backup of the registry key</p>
<pre class="literal-block">
HKEY_CURRENT_USER\Software\Python
</pre>
<p>and then delete it. After that, install Python into a folder containing no blank spaces in its name.</p>
<div class="warning">
<p class="first admonition-title">Warning</p>
<p class="last">Entering wrong values in the registry or accidentally
deleting values may render Windows bricked. Always ensure you have a recent &quot;System Restore&quot;
point in your Windows backup. This will allow you to boot Windows to
&quot;Last known good configuration&quot; if the registry gets corrupted.</p>
</div>
<p>Next we need to install wxPython package for the GUI. This is available as a binary installer
from <a class="reference external" href="http://www.wxpython.org">http://www.wxpython.org</a>. Get version 3.0.2 and install it into your python
installation. It should default to live in <tt class="docutils literal">&lt;your python <span class="pre">folder&gt;\\Lib\\site-packages</span></tt>.</p>
<p>The list of additional 3rd party python modules and their versions necessary for
the python for Windows distributed with Phenix is:</p>
<pre class="literal-block">
Cython==0.22
PIL==1.1.7
Pillow==2.8.1
PyOpenGL==3.1.1a1
PyRTF==0.45
Pygments==2.1.3
biopython==1.65
comtypes==1.1.1
docutils==0.12
h5py==2.5.0
libsvm==3.20
matplotlib==1.4.3
numpy==1.9.2
psutil==2.2.1
py2exe==0.6.9
pyparsing==2.0.3
python-dateutil==2.4.2
pytz==2015.2
reportlab==3.1.44
scipy==0.15.1
six==1.9.0
jinja2==2.8
</pre>
<p>These can be added to your python installation as follows: In a command prompt change
directory to the toplevel directory of your python installation and type:</p>
<pre class="literal-block">
python -m pip install moduleXYZ
</pre>
<p>where &quot;moduleXYZ&quot; is one of the above. Modules not found through the online database of python
modules or those which have not been compiled with Visual C++ 2008 may be found on
<a class="reference external" href="http://www.lfd.uci.edu/~gohlke/pythonlibs/">Christoph Gohlke's site</a>. Make sure that the
python version and compiler version of the modules matches 2.7 and Visual Studio 2008
respectively.</p>
<p>Now your customised python is ready to be bundled into a zip file. Open Windows Explorer,
locate the folder above your python, right-click on your python folder and select
&quot;Send to Compressed (zipped) Folder&quot;. This will create a zip file named python.zip
which contains everything in your customised python. Depending on the platform you are
targetting rename this file to python2.7.9_x86_64_plus_relocatable.zip or
python2.7.9_x86_32_plus_relocatable.zip. If you want to use make this zip bundle available
to others then upload it to <a class="reference external" href="http://cci.lbl.gov/cctbx_dependencies">http://cci.lbl.gov/cctbx_dependencies</a> . When a boostrap build is
started <tt class="docutils literal">bootstrap.py</tt> will download it during the <tt class="docutils literal">base</tt> stage and uncompress it in the
base subdirectory of your build location.</p>
</div>
</div>
<div class="section" id="hdf5-library">
<h1><a class="toc-backref" href="#id4">HDF5 library</a></h1>
<p>The second base component bundled is the HDF5 library which is necesary for Dials and Xia2.
On Windows the build tool CMake from <a class="reference external" href="https://cmake.org/">https://cmake.org/</a> must be installed first.</p>
<p>On this occassion it seems to be necessary to have the full Visual Studio 2008
installed. The free version of the compiler in the Windows 7 SDK seems to confuse CMake if
other and newer Visual Studio compilers are present. This leads to error messages when
attempting to build the library.</p>
<p>HDF5 can be downloaded from <a class="reference external" href="http://www.hdfgroup.org/ftp/HDF5/current/src/">http://www.hdfgroup.org/ftp/HDF5/current/src/</a> such as a zipped
file like CMake-hdf5-1.8.16.zip. Uncompress it on your PC.</p>
<div class="section" id="adapting-build-scripts-to-visual-studio-2008">
<h2><a class="toc-backref" href="#id5">Adapting build scripts to Visual Studio 2008</a></h2>
<p>In the folder CMake-hdf5-1.8.16 there
should be cmd scripts such as build-VS2012-32.bat, build-VS2013-32.bat etc. but none targetting
Visual Studio 2008, i.e. with &quot;VS2008&quot; as part of the filename. We need to adapt HDF5 to
build with Visual Studio 2008. To do this open one of the existing cmd scripts such as
build-VS2012-32.bat and replace the line</p>
<div id="Layer1" style=
"position:relative; width:90%; height:40px;  left: 4px; top: 0px; overflow: auto; background: #eee;">
<pre class="code">
ctest -S HDF518config.cmake,BUILD_GENERATOR=VS2012 -C Release -V -O hdf518.log
</pre>
</div><p>with</p>
<div id="Layer1" style=
"position:relative; width:90%; height:40px;  left: 4px; top: 0px; overflow: auto; background: #eee;">
<pre class="code">
ctest -S HDF518config.cmake,BUILD_GENERATOR=VS2008 -C Release -V -O hdf518.log
</pre>
</div><p>Save this file with the name &quot;build-VS2008-32.bat&quot;. Now open the file &quot;HDF518config.cmake&quot;.
Locate the section:</p>
<div id="Layer1" style=
"position:relative; width:90%; height:200px;  left: 4px; top: 0px; overflow: auto; background: #eee;">
<pre class="code">
# build generator must be defined
if(NOT DEFINED BUILD_GENERATOR)
  message(FATAL_ERROR "BUILD_GENERATOR must be defined - Unix, VS200864, VS2013, VS201364, VS2012, or VS201264")
else()
  if(${BUILD_GENERATOR} STREQUAL "Unix")
    set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
  elseif(${BUILD_GENERATOR} STREQUAL "VS2015")
    set(CTEST_CMAKE_GENERATOR "Visual Studio 14 2015")
  elseif(${BUILD_GENERATOR} STREQUAL "VS201564")
    set(CTEST_CMAKE_GENERATOR "Visual Studio 14 2015 Win64")
  elseif(${BUILD_GENERATOR} STREQUAL "VS2013")
    set(CTEST_CMAKE_GENERATOR "Visual Studio 12 2013")
  elseif(${BUILD_GENERATOR} STREQUAL "VS201364")
    set(CTEST_CMAKE_GENERATOR "Visual Studio 12 2013 Win64")
  elseif(${BUILD_GENERATOR} STREQUAL "VS2012")
    set(CTEST_CMAKE_GENERATOR "Visual Studio 11 2012")
  elseif(${BUILD_GENERATOR} STREQUAL "VS201264")
    set(CTEST_CMAKE_GENERATOR "Visual Studio 11 2012 Win64")
  else()
    message(FATAL_ERROR "Invalid BUILD_GENERATOR must be - Unix, VS2013, VS201364, VS2012, or VS201264")
  endif()
endif()
</pre>
</div><p>and add entries for VS2008 like:</p>
<div id="Layer1" style=
"position:relative; width:90%; height:200px;  left: 4px; top: 0px; overflow: auto; background: #eee;">
<pre class="code">
# build generator must be defined
if(NOT DEFINED BUILD_GENERATOR)
  message(FATAL_ERROR "BUILD_GENERATOR must be defined - Unix, VS2008, VS200864, VS2013, VS201364, VS2012, or VS201264")
else()
  if(${BUILD_GENERATOR} STREQUAL "Unix")
    set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
  elseif(${BUILD_GENERATOR} STREQUAL "VS2015")
    set(CTEST_CMAKE_GENERATOR "Visual Studio 14 2015")
  elseif(${BUILD_GENERATOR} STREQUAL "VS201564")
    set(CTEST_CMAKE_GENERATOR "Visual Studio 14 2015 Win64")
  elseif(${BUILD_GENERATOR} STREQUAL "VS2013")
    set(CTEST_CMAKE_GENERATOR "Visual Studio 12 2013")
  elseif(${BUILD_GENERATOR} STREQUAL "VS201364")
    set(CTEST_CMAKE_GENERATOR "Visual Studio 12 2013 Win64")
  elseif(${BUILD_GENERATOR} STREQUAL "VS2012")
    set(CTEST_CMAKE_GENERATOR "Visual Studio 11 2012")
  elseif(${BUILD_GENERATOR} STREQUAL "VS201264")
    set(CTEST_CMAKE_GENERATOR "Visual Studio 11 2012 Win64")
  elseif(${BUILD_GENERATOR} STREQUAL "VS2008")
    set(CTEST_CMAKE_GENERATOR "Visual Studio 9 2008")
  elseif(${BUILD_GENERATOR} STREQUAL "VS200864")
    set(CTEST_CMAKE_GENERATOR "Visual Studio 9 2008 Win64")
  else()
    message(FATAL_ERROR "Invalid BUILD_GENERATOR must be - Unix, VS2013, VS201364, VS2012, or VS201264")
  endif()
endif()
</pre>
</div><p>Now locate the section:</p>
<div id="Layer1" style=
"position:relative; width:90%; height:200px;  left: 4px; top: 0px; overflow: auto; background: #eee;">
<pre class="code">
#########       Following describes compiler           ############
if(WIN32)
  set(SITE_OS_NAME "Windows")
  set(SITE_OS_VERSION "WIN7")
  if(${BUILD_GENERATOR} STREQUAL "VS201564")
    set(SITE_OS_BITS "64")
    set(SITE_COMPILER_NAME "vs2015")
    set(SITE_COMPILER_VERSION "14")
  elseif(${BUILD_GENERATOR} STREQUAL "VS2015")
    set(SITE_OS_BITS "32")
    set(SITE_COMPILER_NAME "vs2015")
    set(SITE_COMPILER_VERSION "14")
  elseif(${BUILD_GENERATOR} STREQUAL "VS201364")
    set(SITE_OS_BITS "64")
    set(SITE_COMPILER_NAME "vs2013")
    set(SITE_COMPILER_VERSION "12")
  elseif(${BUILD_GENERATOR} STREQUAL "VS2013")
    set(SITE_OS_BITS "32")
    set(SITE_COMPILER_NAME "vs2013")
    set(SITE_COMPILER_VERSION "12")
  elseif(${BUILD_GENERATOR} STREQUAL "VS201264")
    set(SITE_OS_BITS "64")
    set(SITE_COMPILER_NAME "vs2012")
    set(SITE_COMPILER_VERSION "11")
  elseif(${BUILD_GENERATOR} STREQUAL "VS2012")
    set(SITE_OS_BITS "32")
    set(SITE_COMPILER_NAME "vs2012")
    set(SITE_COMPILER_VERSION "11")
  endif()
##  Set the following to unique id your computer  ##
</pre>
</div><p>and add entries for the VS2008 compiler like:</p>
<div id="Layer1" style=
"position:relative; width:90%; height:200px;  left: 4px; top: 0px; overflow: auto; background: #eee;">
<pre class="code">
#########       Following describes compiler           ############
if(WIN32)
  set(SITE_OS_NAME "Windows")
  set(SITE_OS_VERSION "WIN7")
  if(${BUILD_GENERATOR} STREQUAL "VS201564")
    set(SITE_OS_BITS "64")
    set(SITE_COMPILER_NAME "vs2015")
    set(SITE_COMPILER_VERSION "14")
  elseif(${BUILD_GENERATOR} STREQUAL "VS2015")
    set(SITE_OS_BITS "32")
    set(SITE_COMPILER_NAME "vs2015")
    set(SITE_COMPILER_VERSION "14")
  elseif(${BUILD_GENERATOR} STREQUAL "VS201364")
    set(SITE_OS_BITS "64")
    set(SITE_COMPILER_NAME "vs2013")
    set(SITE_COMPILER_VERSION "12")
  elseif(${BUILD_GENERATOR} STREQUAL "VS2013")
    set(SITE_OS_BITS "32")
    set(SITE_COMPILER_NAME "vs2013")
    set(SITE_COMPILER_VERSION "12")
  elseif(${BUILD_GENERATOR} STREQUAL "VS201264")
    set(SITE_OS_BITS "64")
    set(SITE_COMPILER_NAME "vs2012")
    set(SITE_COMPILER_VERSION "11")
  elseif(${BUILD_GENERATOR} STREQUAL "VS2012")
    set(SITE_OS_BITS "32")
    set(SITE_COMPILER_NAME "vs2012")
    set(SITE_COMPILER_VERSION "11")
  elseif(${BUILD_GENERATOR} STREQUAL "VS200864")
    set(SITE_OS_BITS "64")
    set(SITE_COMPILER_NAME "vs2008")
    set(SITE_COMPILER_VERSION "9")
  elseif(${BUILD_GENERATOR} STREQUAL "VS2008")
    set(SITE_OS_BITS "32")
    set(SITE_COMPILER_NAME "vs2008")
    set(SITE_COMPILER_VERSION "9")
  endif()
##  Set the following to unique id your computer  ##
</pre>
</div><p>Finally due to licensing terms of the optionally compiled SZIP library as detailed here:
<a class="reference external" href="https://www.hdfgroup.org/doc_resource/SZIP/">https://www.hdfgroup.org/doc_resource/SZIP/</a> this needs to be excluded from builds. To do that
find the lines:</p>
<div id="Layer1" style=
"position:relative; width:90%; height:110px;  left: 4px; top: 0px; overflow: auto; background: #eee;">
<pre class="code">
### disable ext libs building
#set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=OFF")
#set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=OFF")
#set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_ENCODING:BOOL=OFF")
</pre>
</div><p>and uncomment them:</p>
<div id="Layer1" style=
"position:relative; width:90%; height:110px;  left: 4px; top: 0px; overflow: auto; background: #eee;">
<pre class="code">
### disable ext libs building
set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=OFF")
set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=OFF")
set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_ENCODING:BOOL=OFF")
</pre>
</div></div>
<div class="section" id="doing-the-actual-build">
<h2><a class="toc-backref" href="#id6">Doing the actual build</a></h2>
<p>The configuration is now good to build. Open a command prompt and change directory to
the CMake-hdf5-1.8.16 folder with the amended build script files. Initialise the compilers
environment variables by running</p>
<pre class="literal-block">
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat
</pre>
<p>or</p>
<pre class="literal-block">
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat
</pre>
<p>according to the platform you are targetting. CMake installed earlier
may not be in the executable path in which case you can add it temporarily to your
command prompt by entering:</p>
<pre class="literal-block">
set PATH=%PATH%;C:\Program Files\CMake\bin
</pre>
<p>Then run the build script by entering:</p>
<pre class="literal-block">
build-VS2008-32.bat
</pre>
<p>This should build the library, bundle it into a compressed zip file located in
CMake-hdf5-1.8.16\build and named HDF5-1.8.16-win32.zip or HDF5-1.8.16-win64.zip depending
on the platform. As with the python bundles these files should be uploaded to
<a class="reference external" href="http://cci.lbl.gov/cctbx_dependencies">http://cci.lbl.gov/cctbx_dependencies</a> so that bootstrap.py may fetch it during the <tt class="docutils literal">base</tt> stage
of the build.</p>
</div>
</div>
</div>
    
  </body>
</html>
