Skip to content

Commit

Permalink
Improve build parallelism by compiling mrregister and mrtransform first
Browse files Browse the repository at this point in the history
mrregister and mrtransform can take a long time to build. If their compilation starts towards the end of the build, Ninja may be compiling a single source file for quite sometime. This may result in suboptimal compilation times (due to part of the compilation not being multi-threaded).
This hack tries to avoid this by starting their compilation as soon as possible (atm there's no alternative nice way of doing this in Ninja or CMake).

See ninja-build/ninja#232
  • Loading branch information
daljit46 committed Apr 14, 2024
1 parent ac0f590 commit 6ff3dcd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ foreach(CMD ${HEADLESS_CMD_SRCS})
add_cmd(${CMD} FALSE)
endforeach(CMD)

# mrregister and mrtransform are the commands that take the longest to compile
# so we try to start their compilation as soon as possible by adding them as dependencies
# of a generated dummy file (which Ninja prioritises during compilation).
# This is hacky, but it increases build parallelism.
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "int main(){}")
add_executable(0_dummy ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
add_dependencies(0_dummy mrregister mrtransform)

if(MRTRIX_BUILD_GUI)
foreach(CMD ${GUI_CMD_SRCS})
add_cmd(${CMD} TRUE)
endforeach(CMD)
endif()
endif()

0 comments on commit 6ff3dcd

Please sign in to comment.