Differences between revisions 74 and 112 (spanning 38 versions)
Revision 74 as of 2016-06-15 15:41:59
Size: 3798
Editor: ZekeKaufman
Comment:
Revision 112 as of 2018-02-17 13:16:39
Size: 8516
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
This page is targeted at those who wish to develop and build the freesurfer source code on their OSX platform. These instructions have been tested for OS X 10.7, 10.9, 10.11 (Lion, Mavericks, El Capitan). This page is targeted at those who wish to develop and build the freesurfer source code on their OSX platform. These instructions have been tested for 10.13 (High Sierra). See the [[freesurfer_linux_developers_page|linux build page]] for instructions on how to build on linux platform.
Line 4: Line 4:
Those who wish to add a binary to the freesurfer software suite should consult the 'Adding a new binary to the tree' section of the [[https://surfer.nmr.mgh.harvard.edu/fswiki/DevelopersGuide#Addinganewbinarytothetree|Developers Guide]]. Those who wish to add a binary to the FreeSurfer software suite should consult the 'Adding a new binary to the tree' section of the [[https://surfer.nmr.mgh.harvard.edu/fswiki/DevelopersGuide#Addinganewbinarytothetree|Developers Guide]].
Line 6: Line 6:

=== Install Build Tools ===

In order to build Freesurfer, the following prerequisite software will need to be downloaded and installed on your OSX system. Homebrew is preferred over !MacPorts. Homebrew needs to be installed first. However, if your Mac is polluted with various stuff in /usr/local and /opt/local, and you think you can live without whatever is there, a recommendation is to delete those directories entirely, so that debugging strange build issues is not confounded by overlap with old tools in those directories. Make sure you first check what is in those directories (e.g. docker and other packages could have files there). If you really want to start fresh, do:
{{{
sudo rm -Rf /usr/local/*
sudo rm -Rf /opt/local
}}}

This has been safely done on Mac High Sierra. Reboot once this is done, then to install Homebrew, open a Terminal, then type 'bash' (if that is not your default already):
{{{
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
}}}

Test it:
{{{
brew install wget
brew postinstall wget
wget --help
}}}

You should get wget help instructions, which means Homebrew is working. The brew install may output some error-looking stuff, but if wget --help works, then your set. Now use it to install autoconf, automake, libtool, and gcc v4.9:
{{{
brew install libtool
brew install automake
brew postinstall automake
brew install gcc49
brew postinstall gcc49
brew install git-annex
}}}

You should now be setup with the gnu tools to build freesurfer, so let's get the source and libraries.

Line 8: Line 42:
Users can download Freesurfer source code via the read-only git repo. A simple clone of the repo (187 Megs) is enough to perform a build of all freesurfer binaries. However, if a user wishes to perform full Freesurfer installation locally, he/she will need [[https://git-annex.branchable.com/ | git-annex]] in order to download all the data files required for a full installation (6.6 Gigs).
The Freesurfer source code can be cloned from the official [[https://github.com/freesurfer/freesurfer|Freesurfer github page]]:
Line 12: Line 45:
## Get the source code
$> git clone http://freesurfer.net/anonftp/pub/dist/freesurfer/repo/freesurfer.git

## Get data files (only required for full installation)
$> cd freesurfer
$> git annex get .
git clone https://github.com/freesurfer/freesurfer.git
Line 20: Line 48:
=== Install System Libraries === ==== Get the Data Files (optional) ====
The Freesurfer repository contains a large number data files which are not included with a default {{{git clone}}} of the repo. Instead, these data files are distributed via the [[https://git-annex.branchable.com/|git-annex]] software. Users who only want the repository for the purposes of compiling binaries and/or inspecting source code, the {{{git clone}}} command from above is all you need to do. Users who want to run build time checks, or perform a full local installation, or just want all the contents of the repository, will need to add a special data store remote repository in order to retrieve these files.
Line 22: Line 51:
In order to build Freesurfer, the following prerequisite software will need to be downloaded and installed on your OSX system: To add the data store repository (this only needs to be done once):
{{{
cd freesurfer
git remote add datasrc https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/repo/annex.git
git fetch datasrc
}}}
Line 24: Line 58:
 * [[http://xquartz.macosforge.org/downloads/SL/XQuartz-2.7.5.dmg|XQuartz 2.7.5]] (OSX versions 10.9 and lower)
 * [[http://xquartz.macosforge.org/downloads/SL/XQuartz-2.7.6.dmg|XQuartz 2.7.6]] (OSX versions 10.10 and higher)
 * [[http://gcc.gnu.org/wiki/GFortranBinaries#MacOS|gfortran 4.8.2]]
 * [[https://www.macports.org/install.php|MacPorts]]

Once !MacPorts is installed, use it to install autoconf, automake, libtool, and gcc44:
And to retrieve data files:
Line 32: Line 61:
$> sudo port install autoconf
$> sudo port install automake
$> sudo port install libtool
$> sudo port install gcc44

## Set gcc44 to be the default compiler
$> sudo port select --set gcc mp-gcc44
$> gcc --version
gcc (MacPorts gcc44 4.4.7_10) 4.4.7
git annex get <filename>
Line 43: Line 64:
As of the writing of this document (June 2016) freeview is unable to build on OSX 10.11 platforms (El Capitan). This is due to an incompatibility between qt4.7 and OSX 10.11. If you are building on a pre-OSX 10.11 platform, and want to build freeeview, you will need to download and install [[https://download.qt.io/archive/qt/4.7/qt-mac-opensource-4.7.4.dmg|Qt 4.7.4]].''IMPORTANT: After you install Qt, you must delete line 320 from the file'' {{{/Library/Frameworks/QtCore.framework/Headers/qglobal.h}}}'', the line that says "#warning "This version of Mac OS X is unsupported""''. Next, install Xcode Command Line Tools my typing the following on the command line: The data files have been broken down into categories, those being required for build time checks, those required for a local installation, and everything else. Use one of the following commands depending on your needs:

{{{
## Get only the data files required for build time checks (1.9 GB)
git annex get --metadata fstags=makecheck .

## Get only the data files required for local installation (4.3 GB)
git annex get --metadata fstags=makeinstall .

## Just give me everything! Not Recommended (6.8 GB)
git annex get .
}}}
Line 47: Line 80:
In order to compile freesurfer, you will need to download and install our prebuilt bundle of 3rd party dependancies. Download the package and extract its content. Remember the extraction location as you will need to pass that directory to the {{{configure}}} script.  In order to compile freesurfer, you will need to install the 3rd party lib dependencies. There are two options: use a prebuilt bundle (which may not be guaranteed to work with newer versions of gcc and Mac OS versions), or you can build each library independently.

==== Download Prebuilts ====
To download and install our prebuilt bundle of
3rd party dependencies, download the package and extract its content. Remember the extraction location as you will need to pass that directory to the {{{configure}}} script.
Line 50: Line 86:
$> cd ~
$> curl -O ftp://surfer.nmr.mgh.harvard.edu/pub/dist/fs_supportlibs/prebuilt/OSX/osx-lion-packages.tar.gz
$> tar -xzvf osx-lion-packages.tar.gz
mkdir ~/osx-lion-packages
cd ~/osx-lion-packages
curl -O ftp://surfer.nmr.mgh.harvard.edu/pub/dist/fs_supportlibs/prebuilt/OSX/osx-lion-packages.tar.gz
tar -xzvf osx-lion-packages.tar.gz
Line 55: Line 92:
==== Build from source ====

WORK IN PROGRESS

The packages directory in the freesurfer source tree contains scripts that pull the source for the various 3rd-party libs that freesurfer needs to build. The intent is to run these scripts to build a needed package, and configure will automatically find it.
Line 56: Line 99:
Determine the location you want Freesurfer to be installed. For example, in case case we will assume the user wants freesurfer to be installed in {{{/home/USER/freesurfer}}}. Type the following commands in the top-level Freesurfer directory (the directory that contains configure.in and all the mri_* and mris_* directories.):
First, we setup the environment, and we'll run the configure, telling it where to find our compilers and allowing it to have warnings:
Line 59: Line 103:
$> cd ~/freesurfer
$> ./setup_configure
$> ./configure --with-pkgs-dir=/Users/username/osx-lion-packages --prefix=/Users/username/fs_install
$> make -j4
$> make install
./setup_configure
./configure F77=/usr/local/bin/gfortran-4.9 CC=/usr/local/bin/gcc-4.9 CXX=/usr/local/bin/g++-4.9 --disable-Werror

.
.
.
checking for main in -lvnl... no
configure: error: FATAL: vnl lib not found. Set LDFLAGS or --with-vxl-dir.
Line 66: Line 113:
Done! This indicates it could not find the first dependency, the VXL libs. Let's point configure at the pre-built package dir:
Line 68: Line 115:
Send your comments/questions/feedback to zkaufman@nmr.mgh.harvard.edu {{{
./configure F77=/usr/local/bin/gfortran-4.9 CC=/usr/local/bin/gcc-4.9 CXX=/usr/local/bin/g++-4.9 \
            --with-pkgs-dir="$HOME/osx-lion-packages" --disable-Werror

.
.
.

checking for main in -lKWWidgets... no
configure: error: FATAL: KWWidgets lib not found. Set LDFLAGS or --with-KWWidgets-dir.
}}}

Oops! Looks like KWWidgets is not in the packages directory. It turns out that building the GUI apps in freesurfer (freeview, tk*, qdec) is a great big hassle due to the many 3rd-party libs. So for now, lets just not build those:
{{{
./configure F77=/usr/local/bin/gfortran-4.9 CC=/usr/local/bin/gcc-4.9 CXX=/usr/local/bin/g++-4.9 \
            --with-pkgs-dir=$HOME/osx-lion-packages --disable-Werror --disable-GUI-build

.
.
.
FreeSurfer is now configured for x86_64-apple-darwin17.3.0

  Source directory: .
  Build directory: /Users/nicks/dev/freesurfer
  Install directory: /Applications/freesurfer

  C compiler: gcc -g -O3 -msse2 -mfpmath=sse -Wall -Wno-unused-but-set-variable -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fopenmp -DHAVE_OPENMP -m64 -DDarwin -DANSI -DUSE_LOCAL_MINC
  C++ compiler: g++ -g -O3 -msse2 -mfpmath=sse -Wall -Wno-unused-but-set-variable -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fopenmp -DHAVE_OPENMP -m64 -DDarwin -DANSI -DUSE_LOCAL_MINC
  Fortran: gfortran -g -O3 -msse2 -mfpmath=sse -m64
  Linker: /usr/bin/ld -fopenmp -dead_strip -L/Users/nicks/dev/pkgs/vxl/current/lib
  Libs: -lz -lm -ldl -lpthread -lvnl_algo -lvnl -lvcl -lnetlib -lv3p_netlib

}}}


Now we're ready to build.

Determine the location you want Freesurfer to be installed. For example, in this case we will assume the user wants Freesurfer to be installed in {{{/home/USER/freesurfer}}}. Type the following commands in the top-level Freesurfer directory (the directory that contains configure.in and all the mri_* and mris_* directories.):

{{{
./setup_configure
./configure F77=/usr/local/bin/gfortran-4.9 CC=/usr/local/bin/gcc-4.9 CXX=/usr/local/bin/g++-4.9 \
            --with-pkgs-dir=$HOME/osx-lion-packages --disable-Werror --disable-GUI-build \
            --prefix=$HOME/fsdev_install
make -j 8
make install
}}}

Done! (Only make install if you downloaded the necessary binaries from git-annex above).

Note: you can spare yourself from some typing by including vars for F77, CC and CXX in your startup .cshrc (or similar):
{{{
setenv G49BIN /usr/local/bin
if (-e $G49BIN/gcc-4.9) then
    setenv F77 $G49BIN/gfortran-4.9
    setenv CC $G49BIN/gcc-4.9
    setenv CXX $G49BIN/g++-4.9
endif
}}}


=== Contributing Changes ===
Users who wish to make contributions to the Freesurfer code base should see the following page which describes how to fork the Freesurfer repository and submit pull requests:

  https://surfer.nmr.mgh.harvard.edu/fswiki/Freesurfer_github

----
Send your comments/questions/feedback to ahoopes@mgh.harvard.edu

This page is targeted at those who wish to develop and build the freesurfer source code on their OSX platform. These instructions have been tested for 10.13 (High Sierra). See the linux build page for instructions on how to build on linux platform.

Those who wish to add a binary to the FreeSurfer software suite should consult the 'Adding a new binary to the tree' section of the Developers Guide.

1. Install Build Tools

In order to build Freesurfer, the following prerequisite software will need to be downloaded and installed on your OSX system. Homebrew is preferred over MacPorts. Homebrew needs to be installed first. However, if your Mac is polluted with various stuff in /usr/local and /opt/local, and you think you can live without whatever is there, a recommendation is to delete those directories entirely, so that debugging strange build issues is not confounded by overlap with old tools in those directories. Make sure you first check what is in those directories (e.g. docker and other packages could have files there). If you really want to start fresh, do:

sudo rm -Rf /usr/local/*
sudo rm -Rf /opt/local

This has been safely done on Mac High Sierra. Reboot once this is done, then to install Homebrew, open a Terminal, then type 'bash' (if that is not your default already):

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Test it:

brew install wget
brew postinstall wget
wget --help

You should get wget help instructions, which means Homebrew is working. The brew install may output some error-looking stuff, but if wget --help works, then your set. Now use it to install autoconf, automake, libtool, and gcc v4.9:

brew install libtool
brew install automake
brew postinstall automake
brew install gcc49
brew postinstall gcc49
brew install git-annex

You should now be setup with the gnu tools to build freesurfer, so let's get the source and libraries.

2. Get the Source Code

The Freesurfer source code can be cloned from the official Freesurfer github page:

git clone https://github.com/freesurfer/freesurfer.git

2.1. Get the Data Files (optional)

The Freesurfer repository contains a large number data files which are not included with a default git clone of the repo. Instead, these data files are distributed via the git-annex software. Users who only want the repository for the purposes of compiling binaries and/or inspecting source code, the git clone command from above is all you need to do. Users who want to run build time checks, or perform a full local installation, or just want all the contents of the repository, will need to add a special data store remote repository in order to retrieve these files.

To add the data store repository (this only needs to be done once):

cd freesurfer
git remote add datasrc  https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/repo/annex.git
git fetch datasrc

And to retrieve data files:

git annex get <filename>

The data files have been broken down into categories, those being required for build time checks, those required for a local installation, and everything else. Use one of the following commands depending on your needs:

## Get only the data files required for build time checks (1.9 GB)
git annex get --metadata fstags=makecheck .

## Get only the data files required for local installation (4.3 GB)
git annex get --metadata fstags=makeinstall .

## Just give me everything! Not Recommended (6.8 GB)
git annex get .

3. Library Dependencies

In order to compile freesurfer, you will need to install the 3rd party lib dependencies. There are two options: use a prebuilt bundle (which may not be guaranteed to work with newer versions of gcc and Mac OS versions), or you can build each library independently.

3.1. Download Prebuilts

To download and install our prebuilt bundle of 3rd party dependencies, download the package and extract its content. Remember the extraction location as you will need to pass that directory to the configure script.

mkdir ~/osx-lion-packages
cd ~/osx-lion-packages
curl -O ftp://surfer.nmr.mgh.harvard.edu/pub/dist/fs_supportlibs/prebuilt/OSX/osx-lion-packages.tar.gz
tar -xzvf osx-lion-packages.tar.gz

3.2. Build from source

WORK IN PROGRESS

The packages directory in the freesurfer source tree contains scripts that pull the source for the various 3rd-party libs that freesurfer needs to build. The intent is to run these scripts to build a needed package, and configure will automatically find it.

4. Setup, Configure, Make

First, we setup the environment, and we'll run the configure, telling it where to find our compilers and allowing it to have warnings:

./setup_configure
./configure F77=/usr/local/bin/gfortran-4.9 CC=/usr/local/bin/gcc-4.9 CXX=/usr/local/bin/g++-4.9 --disable-Werror 

.
.
.
checking for main in -lvnl... no
configure: error: FATAL: vnl lib not found. Set LDFLAGS or --with-vxl-dir.

This indicates it could not find the first dependency, the VXL libs. Let's point configure at the pre-built package dir:

./configure F77=/usr/local/bin/gfortran-4.9 CC=/usr/local/bin/gcc-4.9 CXX=/usr/local/bin/g++-4.9 \
            --with-pkgs-dir="$HOME/osx-lion-packages" --disable-Werror 

.
.
.

checking for main in -lKWWidgets... no
configure: error: FATAL: KWWidgets lib not found.   Set LDFLAGS or --with-KWWidgets-dir.

Oops! Looks like KWWidgets is not in the packages directory. It turns out that building the GUI apps in freesurfer (freeview, tk*, qdec) is a great big hassle due to the many 3rd-party libs. So for now, lets just not build those:

./configure F77=/usr/local/bin/gfortran-4.9 CC=/usr/local/bin/gcc-4.9 CXX=/usr/local/bin/g++-4.9 \
            --with-pkgs-dir=$HOME/osx-lion-packages --disable-Werror --disable-GUI-build

.
.
.
FreeSurfer is now configured for x86_64-apple-darwin17.3.0

  Source directory:  .
  Build directory:   /Users/nicks/dev/freesurfer
  Install directory: /Applications/freesurfer

  C compiler:   gcc -g -O3 -msse2 -mfpmath=sse -Wall  -Wno-unused-but-set-variable -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fopenmp -DHAVE_OPENMP -m64 -DDarwin -DANSI  -DUSE_LOCAL_MINC
  C++ compiler: g++ -g -O3 -msse2 -mfpmath=sse -Wall  -Wno-unused-but-set-variable -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fopenmp -DHAVE_OPENMP -m64 -DDarwin -DANSI  -DUSE_LOCAL_MINC
  Fortran:      gfortran -g -O3 -msse2 -mfpmath=sse -m64
  Linker:       /usr/bin/ld  -fopenmp -dead_strip    -L/Users/nicks/dev/pkgs/vxl/current/lib
  Libs:            -lz -lm  -ldl -lpthread      -lvnl_algo -lvnl -lvcl -lnetlib -lv3p_netlib

Now we're ready to build.

Determine the location you want Freesurfer to be installed. For example, in this case we will assume the user wants Freesurfer to be installed in /home/USER/freesurfer. Type the following commands in the top-level Freesurfer directory (the directory that contains configure.in and all the mri_* and mris_* directories.):

./setup_configure
./configure F77=/usr/local/bin/gfortran-4.9 CC=/usr/local/bin/gcc-4.9 CXX=/usr/local/bin/g++-4.9 \
            --with-pkgs-dir=$HOME/osx-lion-packages --disable-Werror --disable-GUI-build \
            --prefix=$HOME/fsdev_install
make -j 8
make install

Done! (Only make install if you downloaded the necessary binaries from git-annex above).

Note: you can spare yourself from some typing by including vars for F77, CC and CXX in your startup .cshrc (or similar):

setenv G49BIN  /usr/local/bin
if (-e $G49BIN/gcc-4.9) then
    setenv F77 $G49BIN/gfortran-4.9
    setenv CC $G49BIN/gcc-4.9
    setenv CXX $G49BIN/g++-4.9
endif

5. Contributing Changes

Users who wish to make contributions to the Freesurfer code base should see the following page which describes how to fork the Freesurfer repository and submit pull requests:


Send your comments/questions/feedback to ahoopes@mgh.harvard.edu