Differences between revisions 11 and 190 (spanning 179 versions)
Revision 11 as of 2005-03-30 16:57:10
Size: 4857
Editor: KevinTeich
Comment:
Revision 190 as of 2023-09-13 15:46:41
Size: 3992
Editor: JacksonNolan
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
#pragma section-numbers on #acl LcnGroup:read,write,delete,revert All:read
Line 3: Line 3:
[[Navigation(children)]] = FreeSurfer Dev Guide =
Line 5: Line 5:
'''Index'''  * Visit the BuildGuide for instructions on building and installing freesurfer manually.
 * Visit the GitHub page for an introduction to the github workflow.
 * Visit the GitAnnex page for detailed instructions on using git annex for storing and retrieving large data files in the repository.
Line 7: Line 9:
[[TableOfContents]] == File Size Limitations ==
Line 9: Line 11:
=== Medical Image Format FAQ ===
[http://www.dclunie.com/medical-image-faq/html Medical Image Format FAQ]
Any files '''larger than 50MB''' should be stored in the GitAnnex, following the hyperlinked instructions, and properly linked to your utility.
Line 12: Line 13:
=== CVS Checkout === == Adding a New C Program ==
Line 14: Line 15:
You can checkout the FreeSurfer source code from the NMR center using local CVS access or remotely by using SSH as the CVS remote connection method.

==== Local CVS Access ====

The CVS repository is /space/repo/1/dev. Use this as your CVSROOT. You can either set it as an environment variable:

{{{setenv CVSROOT /space/repo/1/dev}}}

or specify it in the checkout command with the -d option. Note that the CVS root is cached in a CVS checkout directory, so if you choose to use the -d method, you will only have to do it once during your first checkout.

Check out the code with the CVS checkout command. The archive name is dev.

{{{cvs checkout dev}}}

or

{{{cvs -d /space/repo/1/dev checkout dev}}}

This will copy the entire archive to your directory, creating a
directory called dev/. Now set up your environment to use this dev
directory by running the script in dev/:

{{{cd dev
source set_dev_env_to_here.csh}}}

==== Remote CVS Access ====

Tell CVS to use SSH to access the archive by setting the following environment variable:

{{{setenv CVS_RSH ssh}}}

Use the following string as your CVS root:

{{{:ext:USER@MACHINE.nmr.mgh.harvard.edu:/space/repo/1/dev}}}

Where USER is your username and MACHINE is one of the NMR machines visible to the outside, i.e. gate, entry, or door. Then use the CVS commands normally.

Note that using this method makes an SSH connection for every CVS command, and you will be required to enter your password every time. You may want to look into a utility to automatically authenticate SSH connections, such as SSH agent.

=== Building ===

==== Adding a new binary to the tree ====

Assuming that you have a source file {{{MYPROG.c}}} that compiles into MYPROG and want to add it to the FreeSurfer tree:

1) Make the directory in dev and copy the source file there. Name the directory MYPROG and the source file {{{MYPROG.c}}}.
If you'd like to add a new program to the tree, you should create a new subdirectory with the title of your tool. As an example, let's create a new c++ program called `mri_process`. First, we'll create a top-level subdirectory that contains our new c++ file and an empty `CMakeLists.txt` file:
Line 62: Line 18:
mkdir dev/MYPROG
cp MYPROG.c dev/MYPROG
freesurfer/
    mri_process/
        CMakeLists.txt
        mri_process.cpp
Line 66: Line 24:
2) Tell the autotools to build your program when you type {{{make}}} from the top dir.

a) Modify {{{dev/configure.in}}} to add {{{MYPROG/Makefile}}} to the list at the end of the file in the definition of {{{AC_OUTPUT}}}. Be sure to add a backslash at the end of line:
In order to configure our new code, we should add the following to the empty `CMakeLists.txt` file.
Line 71: Line 27:
AC_OUTPUT( \
... other files ...
MYPROG/Makefile \
)
project(mri_process)

include_directories(${FS_INCLUDE_DIRS})

add_executable(mri_process mri_process.cpp)
target_link_libraries(mri_process utils)

install(TARGETS mri_process DESTINATION bin)
Line 77: Line 37:
b) Modify {{{dev/Makefile.am}}} to add {{{MYPROG}}} to the {{{SUBDIRS}}} definition. (You can also alternatively it to the end of {{{MRISUBDIRS}}} or {{{MRISSUBDIRS}}} if more appropriate.) This will compile `mri_process.cpp`, link it against the `utils` freesurfer library, and copy the executable to the `$FREESURFER_HOME/bin` directory during install. To include this subdirectory in the main freesurfer build, make sure to modify the top-level `CMakeLists.txt` by adding `mri_process` to the long list of included directories at the bottom of the file. Now, after reconfiguring your build, you can run `make` in the `mri_process` directory of your build tree to successfully compile the new program. If you're having trouble configuring and building freesurfer, be sure to visit the BuildGuide for step-by-step instructions.

== Adding a New Python Program ==

Adding a new python program is similar to adding a new c++ program, with an additional step of creating a bash wrapper to be installed in `$FREESURFER_HOME/bin`.
 * Note: Make sure all paths in the Bash wrapper that reference files in the FreeSurfer file tree are defined relative to `$FREESURFER_HOME`, to ensure they are found regardless of the install location

As an example, let’s add a program called `mri_process` to the FreeSurfer tree, where the main functionality is in a python script called `mri_process.py`, and has a dependency on a model called `process_model.h5`.

First, we’ll create a directory containing the scripts, dependencies, and `CMakeLists.txt`:
Line 80: Line 49:
SUBDIRS= ... other directories ... MYPROG freesurfer/
 mri_process/
  CMakeLists.txt
  mri_process.sh # shell wrapper to install in bin/
  process_model.h5 # model dependency stored in the annex
  python/ # dir containing the python code
   mri_process.py # python script called by shell wrapper
Line 83: Line 58:
c) Copy {{{dev/dummy/Makefile.am}}} into {{{MYPROG/}}} and customize it, replacing 'dummy' with 'MYPROG'. Be sure to change: Now we’ll need to populate the empty `CMakeLists.txt` file. We need to achieve the following in this file:
 1. Give the utility a project name
 2. Link the python scripts to the location they are referenced by the Bash wrapper
 3. Install the wrapper script into `$FREESURFER_HOME/bin`
 4. Link any models to the proper location to be accessible to the python code
Line 85: Line 64:
An example `CMakeLists.txt`:
Line 86: Line 66:
bin_PROGRAMS = MYPROG project(mri_process)

install_symlinks(python/mri_process.py TYPE files DESTINATION python/scripts)

install_configured(mri_process.sh DESTINATION bin)

install_symlinks(process_model.h5 TYPE files DESTINATION models)
Line 89: Line 75:
d) Copy in the additional testing file {{{dev/dummy/myown.c}}}. You can customize it for your test program later.

3) Run {{{automake}}} from {{{dev/}}}. You should get no errors. If you do, make sure you followed the above instructions properly. Also try the AutoconfTroubleshooting page. Verify that this stepped work by checking if {{{MYPROG/Makefile.in}}} was created.

4) Run {{{autoconf}}} to generate a new {{{configure}}} script that now includes your new MYPROG directory.

5) Run {{{./configure}}} with the parameters you previously used. To check these out, run {{{head config.log}}} from {{{dev/}}}. The output should include the {{{./configure}}} line you used. Copy it, but leave out the {{{--no-create --no-recursion}}} options if present.

{{{
[dev/]$ head config.log
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by Freesurfer configure 0.1, which was
generated by GNU Autoconf 2.57. Invocation command line was

  $ ./configure --with-mni-dir=/usr/pubsw/packages/mni/current --prefix=/home/kteich/freesurfer/dev --no-create --no-recursion

## --------- ##
## Platform. ##
[dev/]$ ./configure --with-mni-dir=/usr/pubsw/packages/mni/current --prefix=/home/kteich/freesurfer/dev
}}}

Note: Do not just copy this example, use what's in your own {{{config.log}}} file!

6) Run {{{make}}} and verify that your binary program {{{MYPROG/MYPROG}}} was created.

7) Check in your changes.

{{{
[dev/] cvs ci -m "Added MYPROG" configure configure.in Makefile.am Makefile.in
[dev/] cvs add MYPROG
[dev/] cd MYPROG
[MYPROG/] cvs add Makefile.am Makefile.in MYPROG.c myown.c
[MYPROG/] cvs commit -m "First checkin." Makefile.am Makefile.in MYPROG.c myown.c
}}}

==== autoconf Troubleshooting ====

[AutoconfTroubleshooting]


=== RPM ===

[RpmInfo]
Finally, we need to add this directory to the list of included directories in the `CMakeLists.txt` located at the top level of the FreeSurfer file tree. To add your new utility to your build of FreeSurfer, reconfigure your build, and run make in the `mri_process` directory. You can also rebuild all of FreeSurfer with your new utility if needed. More information on building Freesurfer is located in the BuildGuide.

FreeSurfer Dev Guide

  • Visit the BuildGuide for instructions on building and installing freesurfer manually.

  • Visit the GitHub page for an introduction to the github workflow.

  • Visit the GitAnnex page for detailed instructions on using git annex for storing and retrieving large data files in the repository.

File Size Limitations

Any files larger than 50MB should be stored in the GitAnnex, following the hyperlinked instructions, and properly linked to your utility.

Adding a New C Program

If you'd like to add a new program to the tree, you should create a new subdirectory with the title of your tool. As an example, let's create a new c++ program called mri_process. First, we'll create a top-level subdirectory that contains our new c++ file and an empty CMakeLists.txt file:

freesurfer/
    mri_process/
        CMakeLists.txt
        mri_process.cpp

In order to configure our new code, we should add the following to the empty CMakeLists.txt file.

project(mri_process)

include_directories(${FS_INCLUDE_DIRS})

add_executable(mri_process mri_process.cpp)
target_link_libraries(mri_process utils)

install(TARGETS mri_process DESTINATION bin)

This will compile mri_process.cpp, link it against the utils freesurfer library, and copy the executable to the $FREESURFER_HOME/bin directory during install. To include this subdirectory in the main freesurfer build, make sure to modify the top-level CMakeLists.txt by adding mri_process to the long list of included directories at the bottom of the file. Now, after reconfiguring your build, you can run make in the mri_process directory of your build tree to successfully compile the new program. If you're having trouble configuring and building freesurfer, be sure to visit the BuildGuide for step-by-step instructions.

Adding a New Python Program

Adding a new python program is similar to adding a new c++ program, with an additional step of creating a bash wrapper to be installed in $FREESURFER_HOME/bin.

  • Note: Make sure all paths in the Bash wrapper that reference files in the FreeSurfer file tree are defined relative to $FREESURFER_HOME, to ensure they are found regardless of the install location

As an example, let’s add a program called mri_process to the FreeSurfer tree, where the main functionality is in a python script called mri_process.py, and has a dependency on a model called process_model.h5.

First, we’ll create a directory containing the scripts, dependencies, and CMakeLists.txt:

freesurfer/
        mri_process/
                CMakeLists.txt
                mri_process.sh          # shell wrapper to install in bin/
                process_model.h5        # model dependency stored in the annex
                python/                 # dir containing the python code
                        mri_process.py  # python script called by shell wrapper

Now we’ll need to populate the empty CMakeLists.txt file. We need to achieve the following in this file:

  1. Give the utility a project name
  2. Link the python scripts to the location they are referenced by the Bash wrapper
  3. Install the wrapper script into $FREESURFER_HOME/bin

  4. Link any models to the proper location to be accessible to the python code

An example CMakeLists.txt:

project(mri_process)

install_symlinks(python/mri_process.py TYPE files DESTINATION python/scripts)

install_configured(mri_process.sh DESTINATION bin)

install_symlinks(process_model.h5 TYPE files DESTINATION models)

Finally, we need to add this directory to the list of included directories in the CMakeLists.txt located at the top level of the FreeSurfer file tree. To add your new utility to your build of FreeSurfer, reconfigure your build, and run make in the mri_process directory. You can also rebuild all of FreeSurfer with your new utility if needed. More information on building Freesurfer is located in the BuildGuide.

DevelopersGuide (last edited 2023-09-13 15:46:41 by JacksonNolan)