Differences between revisions 11 and 12
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
CMake replaces the `setup_configure` and `configure` build steps. A build can be initialized in the working directory by running `cmake </path/to/repo>`. So, assuming you have a freesurfer repository stored in `~/dev/freesurfer`, you could set up a simple in-source build with CMake replaces the `setup_configure` and `configure` build steps. A build can be initialized in the working directory by running `cmake </path/to/repo>`. So, assuming you have a freesurfer repository stored in `~/dev/freesurfer` (and you're developing on the Martinos filesystem), you could set up a simple in-source build with:
Line 12: Line 12:
or an out-of-source build with '''note:''' if this is your first time transitioning from an automake configuration, you might need to run `make clean` before building with cmake. Some of the previously generated freeview moc files might interfere with the configuration.
Line 14: Line 14:
{{{
cd ~/dev/fsbuild
cmake ~/dev/freesurfer
}}}

Alternatively, `ccmake` can be used instead of `cmake` to configure/edit cached variables in a terminal GUI.
Alternatively, `ccmake` can be used instead of `cmake` to configure/edit cached variables in a terminal GUI. Out-of-source builds are also possible with cmake.
Line 35: Line 30:
Aside from this initial configuration step (which really only needs to be run once) and fact that `make check` is now `make test`, the rest of the build process is pretty much the same. Aside from this initial configuration step (which really only needs to be run once) and fact that `make check` is now `make test`, the rest of the build process is exactly the same.
Line 38: Line 33:

== Adding a binary ==

All freesurfer binaries should contain a CMakeLists.txt file (replacing Makefile.am) in their corresponding subdirectory, and the name of the subdirectory should be added to the large list at the end of the top-level CMakeLists.txt. As an example, the CMakeLists.txt for a standard freesurfer executable (called my_program) that only links to the utils library would look something like this:

{{{
project(my_program)

include_directories(${FS_INCLUDE_DIRS})

add_executable(my_program my_program.c)
target_link_libraries(my_program utils)

install(TARGETS my_program DESTINATION bin)
}}}

A more complex CMakeLists.txt might be required for binaries that depend on other libraries. For example, [[https://github.com/freesurfer/freesurfer/blob/dev/mris_mesh_subdivide/CMakeLists.txt|here's the configuration file]] for mris_mesh_subdivide, which requires VTK.

FreeSurfer CMake

Configuring a Simple Build

CMake replaces the setup_configure and configure build steps. A build can be initialized in the working directory by running cmake </path/to/repo>. So, assuming you have a freesurfer repository stored in ~/dev/freesurfer (and you're developing on the Martinos filesystem), you could set up a simple in-source build with:

cd ~/dev/freesurfer
cmake .

note: if this is your first time transitioning from an automake configuration, you might need to run make clean before building with cmake. Some of the previously generated freeview moc files might interfere with the configuration.

Alternatively, ccmake can be used instead of cmake to configure/edit cached variables in a terminal GUI. Out-of-source builds are also possible with cmake.

Configuration Options

CMake variables are set on the command line with the -D flag. For example, the standard way to configure a build with an install path is

cmake . -DCMAKE_INSTALL_PREFIX="/path/to/install/destination"

You can define any variable on the command line this way, even if the variable is never used in the CMakeLists.txt scripts. Boolean variables added with the option() function can be turned on/off on the command line as well. For example, freesurfer GUI builds can be disabled by running

cmake . -DBUILD_GUIS=OFF

Aside from this initial configuration step (which really only needs to be run once) and fact that make check is now make test, the rest of the build process is exactly the same.

note: the make output is more condensed now, but make VERBOSE=1 will output everything.

Adding a binary

All freesurfer binaries should contain a CMakeLists.txt file (replacing Makefile.am) in their corresponding subdirectory, and the name of the subdirectory should be added to the large list at the end of the top-level CMakeLists.txt. As an example, the CMakeLists.txt for a standard freesurfer executable (called my_program) that only links to the utils library would look something like this:

project(my_program)

include_directories(${FS_INCLUDE_DIRS})

add_executable(my_program my_program.c)
target_link_libraries(my_program utils)

install(TARGETS my_program DESTINATION bin)

A more complex CMakeLists.txt might be required for binaries that depend on other libraries. For example, here's the configuration file for mris_mesh_subdivide, which requires VTK.

CMake (last edited 2021-03-03 01:25:26 by buildqa)