NIfTI: treat nifti as the GIFTI dependency it actually is - #90
Conversation
Display never includes a nifti header directly. The only NIfTI symbols it uses -- NIFTI_INTENT_* and NIFTI_TYPE_* in input_files/ -- arrive through gifti_io.h, and every one of those uses already sits behind #if GIFTI_FOUND. The nifti include directory and library were nevertheless added unconditionally, so a build with GIFTI disabled pulled in an include path it never read and put a library on the link line it never called. Move both inside the existing GIFTI_FOUND guards and link the NIFTI::niftiio imported target rather than a bare path variable. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019katBUnczdvUS7WQ4RpVoa
There was a problem hiding this comment.
Pull request overview
This PR adjusts Display’s CMake configuration so NIfTI is treated as an implementation dependency of GIFTI (since Display only reaches NIfTI symbols through gifti_io.h when GIFTI_FOUND is enabled), avoiding unnecessary include/link references when GIFTI is disabled.
Changes:
- Moves NIfTI-related build wiring to be conditional on
GIFTI_FOUND. - Replaces unconditional
${NIFTI_LIBRARY}linkage with conditional linkage alongside${GIFTI_LIBRARY}. - Stops adding the NIfTI include directory unconditionally.
Suppressed comments (1)
CMakeLists.txt:437
- Same issue as above:
NIFTI::niftiiois appended whenGIFTI_FOUNDis true, but if the imported target is not defined by the toolchain/config packages, configuration will fail when linkingDisplay. Add an explicit target-existence check (or fallback) to keep GIFTI-enabled builds predictable.
# Only link GIFTI when it was found
IF(GIFTI_FOUND)
LIST(APPEND LINK_LIBRARIES ${GIFTI_LIBRARY} NIFTI::niftiio)
ENDIF(GIFTI_FOUND)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Only link GIFTI when it was found | ||
| IF(GIFTI_FOUND) | ||
| LIST(APPEND LINK_LIBRARIES ${GIFTI_LIBRARY}) | ||
| LIST(APPEND LINK_LIBRARIES ${GIFTI_LIBRARY} NIFTI::niftiio) | ||
| ENDIF(GIFTI_FOUND) |
There was a problem hiding this comment.
Correct, and already fixed in ea36767 (pushed shortly after this review).
This was a latent gap the PR exposed rather than created: Display has never found NIfTI itself, it relied on NIFTI_LIBRARY leaking in from an enclosing superbuild, and standalone that variable was simply empty so nothing complained. Referencing the target turns it into the hard error described.
It now finds the package at the point of use, which is the same place it becomes required:
IF(GIFTI_FOUND)
IF(NOT TARGET NIFTI::niftiio)
FIND_PACKAGE(NIFTI CONFIG REQUIRED)
ENDIF()
include_directories( ${GIFTI_INCLUDE_DIR} )
ENDIF(GIFTI_FOUND)REQUIRED gives the clear early failure you asked for, and the NOT TARGET guard leaves an enclosing superbuild alone. This covers both link sites (the 418 and 434 cases), since neither is reached without GIFTI_FOUND.
Display has never found NIfTI itself; it relied on NIFTI_LIBRARY leaking in from an enclosing superbuild, and standalone that variable was simply empty. Referencing the NIFTI::niftiio target instead makes that latent gap an error: a standalone build that does find GIFTI would fail at generate time with the target undefined. Find it at the point of use, which is the same place it becomes required. GIFTI's headers are what pull nifti1.h in, so nifti is needed exactly when GIFTI is. The NOT TARGET check leaves an enclosing superbuild alone, and standalone the package is found from the system or from any prefix on CMAKE_PREFIX_PATH. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019katBUnczdvUS7WQ4RpVoa
|
Added a second commit, fixing a gap the first one exposed. Display has never found NIfTI itself — it relied on So it now finds the package at the point of use, which is the same place it becomes required: IF(GIFTI_FOUND)
IF(NOT TARGET NIFTI::niftiio)
FIND_PACKAGE(NIFTI CONFIG REQUIRED)
ENDIF()
include_directories( ${GIFTI_INCLUDE_DIR} )
ENDIF(GIFTI_FOUND)The Verified: the full superbuild still configures and generates cleanly (GIFTI is disabled there, so the block is skipped), and the same find-and-link pattern compiles, links and runs against an installed system |
Why
Display never includes a nifti header directly. The only NIfTI symbols it uses are
NIFTI_INTENT_*andNIFTI_TYPE_*ininput_files/poly_formats.c,input_files/vertex_data.candinput_files/input_files.c— and all of them arrive throughgifti_io.h, behind#if GIFTI_FOUND.The nifti include directory and library were nevertheless added unconditionally, so a build with GIFTI disabled (the superbuild's current default —
build_gifti()is commented out) picked up an include path it never read and carried a library on the link line it never called.What
include_directories(${NIFTI_INCLUDE_DIR})moves inside the existingIF(GIFTI_FOUND)block, next to the GIFTI include.${NIFTI_LIBRARY}entries in the link lists are replaced byNIFTI::niftiioappended alongside${GIFTI_LIBRARY}in the twoIF(GIFTI_FOUND)guards — the imported target carries its own include directory and dependencies, so nothing else is needed.No functional change to a GIFTI-enabled build; a GIFTI-disabled build simply stops referencing nifti.
Verification
Configured through the full superbuild: Display generates, and with GIFTI off its link line no longer mentions nifti.
Ordering
NIFTI::niftiiois defined by the companion PR inBIC-MNI/minc-toolkit-v2. Since it is only referenced underIF(GIFTI_FOUND), and GIFTI is currently disabled there, this pin can move independently without breaking the build.🤖 Generated with Claude Code
https://claude.ai/code/session_019katBUnczdvUS7WQ4RpVoa