FreeSurfer Dev Guide

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.