Differences between revisions 43 and 108 (spanning 65 versions)
Revision 43 as of 2014-05-16 16:54:03
Size: 5064
Editor: ZekeKaufman
Comment:
Revision 108 as of 2018-02-08 15:44:21
Size: 8498
Editor: MartinReuter
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from freesurfer_mac_developers page
Line 3: 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 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:
This page is targeted at those who wish to develop and build the freesurfer source code on their Mac OSX platform. These instructions have been tested for Mac OSX 10.6, 10.7, and 10.8 (Snow Leopard, Lion, and Mountain Lion). As of the writing of this document, a build on OSX 10.9 (Mavericks) has not been completed. Please download and install the following prerequisite software required for building the freesurfer source code:

 *[[http://gcc.gnu.org/wiki/GFortranBinaries#MacOS|gfortran]]
 *[[ftp://surfer.nmr.mgh.harvard.edu/pub/dist/fs_supportlibs/prebuilt/lion/qt-mac-opensource-4.7.4.dmg|Qt]]
 *Xcode 4.x Command Line Tools ([[ftp://surfer.nmr.mgh.harvard.edu/pub/dist/fs_supportlibs/prebuilt/lion/xcode462_cltools_10_76938260a.dmg|Lion]], [[ftp://surfer.nmr.mgh.harvard.edu/pub/dist/fs_supportlibs/prebuilt/lion/xcode462_cltools_10_86938259a.dmg|Mountain Lion]])


'''''IMPORTANT:''''' Do to a Qt bug, after you install Qt you must delete line 320 from the file {{{/Library/Frameworks/QtCore.framework/Headers/qglobal.h}}} (Removing the line that says '#warning "This version of Mac OS X is unsupported"')

## '''''IMPORTANT:''' CVS no longer ships with OSX 10.8 Command Line Tools and higher. To get CVS working on later versions of Mac OSX follow the directions [[http://apple.stackexchange.com/questions/108240/cvs-on-os-x-mavericks|on this page]].''
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 16: Line 6:
Line 19: Line 8:
==== (Martinos Users) ==== The Freesurfer source code can be cloned from the official [[https://github.com/freesurfer/freesurfer|Freesurfer github page]]:
Line 21: Line 10:
Users who have an account at the Martinos Center can download the source code from the local CVS repository using the following commands:
Line 23: Line 11:
# Local access
export CVSROOT=/space/repo/1/dev
cvs checkout -P dev

# Or, for remote access:
export CVSROOT=:ext:USER@door.nmr.mgh.harvard.edu:/space/repo/1/dev
cvs checkout -P dev
git clone https://github.com/freesurfer/freesurfer.git
Line 32: Line 14:
==== (non Martinos Users) ====
Users who do NOT have an account at the Martinos Center can first [[https://surfer.nmr.mgh.harvard.edu/opensourcereg.html|register to receive the password to the CVS repository]], and then download the source code using the following commands:
==== 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.

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:
Line 36: Line 27:
cvs -d :pserver:anonymous@fsvm.nmr.mgh.harvard.edu:/usr/fscvsroot login
# Type in password
cvs -d :pserver:anonymous@fsvm.nmr.mgh.harvard.edu:/usr/fscvsroot checkout -P dev
git annex get <filename>
Line 41: Line 30:
The above commands will check out the 'trunk' (most up to date) version of the source code. If you want a particular release (i.e. release 5.3), use the "-r release_5_3_0" flag when issuing the checkout command. For example:
{{{
cvs -d :pserver:anonymous@fsvm.nmr.mgh.harvard.edu:/usr/fscvsroot checkout -P -r release_5_3_0 dev
}}}

=== Get the Libraries ===

You will need to download and install the prepackaged bundle of open-sourced libraries ([[ftp://surfer.nmr.mgh.harvard.edu/pub/dist/fs_supportlibs/prebuilt/snowleopard/MacOSX_SnowLeopard_Packages.tar.gz| Snow Leopard]], [[ftp://surfer.nmr.mgh.harvard.edu/pub/dist/fs_supportlibs/prebuilt/mountain_lion/MacOSX_Lion_Packages.tar.gz| Lion, Mountain Lion]]) on your system. To install the prepackaged bundle of open-source libraries, execute the following command after downloading it:
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:
Line 51: Line 33:
mkdir -p /usr/pubsw/packages
tar -C /usr/pubsw/packages -xzvf MacOSX_*_Packages.tar.gz
## 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 56: Line 44:
=== Install Build Tools ===
Line 57: Line 46:
=== Set Your Path === 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. To do so:
Line 59: Line 48:
export PATH=/usr/pubsw/packages/autotools/bin:$PATH sudo rm -Rf /usr/local/*
sudo rm -Rf /opt/local
Line 61: Line 51:
=== Setup, Configure, Make ===
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 {{{/Users/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.)
Line 64: Line 52:
If your on Mac OSX 10.6 (Snow Leopard): This has been safely done (once) 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):
{{{
/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
}}}

There may be gcc tools installed in /usr/bin, so you will want to make sure that the gcc 4.9 installed by Homebrew is used, so first run this in bash:
{{{

VER=4.9
LN_APPS="c++-$VER cpp-$VER g++-$VER gcc-$VER gcc-ar-$VER gcc-nm-$VER gcc-ranlib-$VER gcov-$VER gfortran-$VER"

cd /usr/local/bin
for app in $LN_APPS
do
 LN_NAME=$(echo $app | sed 's/\(.*\)-4.9/\1/')
 echo "ln -s $app $LN_NAME"
 sudo ln -s $app $LN_NAME
done

sudo ln -s glibtool libtool
sudo ln -s glibtoolize libtoolize

sudo mkdir -p /opt/local/bin
cd /opt/local/bin
sudo ln -s /usr/local/bin/libtool
sudo ln -s /usr/local/bin/libtoolize
sudo ln -s /usr/local/bin/glibtool
sudo ln -s /usr/local/bin/glibtoolize

}}}

Note that gcc-ar, gcc-nm and gcc-ranlib exist in the Homebrew gcc 4.9 install, but it seems that linking these to ar, nm and ranlib creates build problems, so those three tools will use the system default in /usr/bin. The linking of libtool in /opt/local/bin is because it seems that automake (when configure is run) looks for libtool there, and if it's not found, then later at link time of a freesurfer binary, it complains about mismatched libtool versions.

Then make sure that /usr/local/bin is first in your default path. Put this (for tsch) in your .cshrc:
{{{
setenv USR_LOCAL /usr/local
if (-e $USR_LOCAL) then
  setenv PATH "$USR_LOCAL/bin":"$PATH"
endif
}}}

You should now be setup with the gnu tools to build freesurfer.

=== 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.

==== 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 67: Line 119:
cd dev 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
}}}

==== Build from source ====

TBD

=== Setup, Configure, Make ===

First, we setup the environment, and we'll run the default configure:

{{{
Line 69: Line 135:
./configure \
      --prefix=/Users/USER/freesurfer \
      --with-vtk-cocoa-dir=/usr/pubsw/packages/vtk/5.6.1_cocoa
./configure

.
.
.
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 --with-pkgs-dir="$HOME/osx-lion-packages"

.
.
.

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 --with-pkgs-dir=$PKGS --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 --with-pkgs-dir=/Users/USERNAME/osx-lion-packages --disable-GUI-build --prefix=/Users/username/fs_install
Line 76: Line 190:
If your on Mac OSX 10.7 or 10.8 (Lion or Mountain Lion):

{{{
cd dev
./setup_configure
./configure \
      --prefix=/Users/USER/freesurfer \
      --with-vtk-cocoa-dir=/usr/pubsw/packages/vtk/5.6.1_cocoa \
      --disable-tcltk-apps \
      --with-qt=/usr/bin \
      --with-Mac32-GUIs \
      --without-cuda

make -j4
make install
}}}
Line 94: Line 192:
--------
Line 96: Line 193:
=== Troubleshooting ===
 * If you are building the '''5.3 release''' than you will need to do the following:
  * Add [[ftp://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/5.3.0-patch/unwarpGradientNonlinearity.c|unwarpGradientNonlinearity.c]] to the {{{dev/utils}}} directory.
  * Add [[ftp://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/5.3.0-patch/unwarpGradientNonlinearity.h|unwarpGradientNonlinearity.h]] to the {{{dev/include}}} directory.
  * Add the contents of [[ftp://surfer.nmr.mgh.harvard.edu/pub/dist/fs_supportlibs/prebuilt/lion|tcltktixblt.tar.gz]] to the {{{/usr/pubsw/packages}}} directory.
=== Contributing Changes ===
Users who with 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:
Line 102: Line 196:
--------   https://surfer.nmr.mgh.harvard.edu/fswiki/Freesurfer_github
Line 104: Line 198:
Send your comments/questions/feedback to zkaufman@nmr.mgh.harvard.edu  ----
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. 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

1.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 .

2. 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. To do so:

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

This has been safely done (once) 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):

/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

There may be gcc tools installed in /usr/bin, so you will want to make sure that the gcc 4.9 installed by Homebrew is used, so first run this in bash:

VER=4.9
LN_APPS="c++-$VER cpp-$VER g++-$VER gcc-$VER gcc-ar-$VER gcc-nm-$VER gcc-ranlib-$VER gcov-$VER gfortran-$VER"

cd /usr/local/bin
for app in $LN_APPS
do
        LN_NAME=$(echo $app | sed 's/\(.*\)-4.9/\1/')
        echo "ln -s $app $LN_NAME"
        sudo ln -s $app $LN_NAME
done

sudo ln -s glibtool libtool
sudo ln -s glibtoolize libtoolize

sudo mkdir -p /opt/local/bin
cd /opt/local/bin
sudo ln -s /usr/local/bin/libtool
sudo ln -s /usr/local/bin/libtoolize
sudo ln -s /usr/local/bin/glibtool
sudo ln -s /usr/local/bin/glibtoolize

Note that gcc-ar, gcc-nm and gcc-ranlib exist in the Homebrew gcc 4.9 install, but it seems that linking these to ar, nm and ranlib creates build problems, so those three tools will use the system default in /usr/bin. The linking of libtool in /opt/local/bin is because it seems that automake (when configure is run) looks for libtool there, and if it's not found, then later at link time of a freesurfer binary, it complains about mismatched libtool versions.

Then make sure that /usr/local/bin is first in your default path. Put this (for tsch) in your .cshrc:

setenv USR_LOCAL  /usr/local
if (-e $USR_LOCAL) then
  setenv PATH      "$USR_LOCAL/bin":"$PATH"
endif

You should now be setup with the gnu tools to build freesurfer.

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. 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

TBD

4. Setup, Configure, Make

First, we setup the environment, and we'll run the default configure:

./setup_configure
./configure

.
.
.
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 --with-pkgs-dir="$HOME/osx-lion-packages"

.
.
.

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 --with-pkgs-dir=$PKGS --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 --with-pkgs-dir=/Users/USERNAME/osx-lion-packages --disable-GUI-build --prefix=/Users/username/fs_install
make -j4
make install

Done!

5. Contributing Changes

Users who with 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