Skip to content

Build the bundled NIfTI with Ninja - #154

Open
gdevenyi wants to merge 2 commits into
BIC-MNI:develop-1.9.18from
gdevenyi:nifti-ninja
Open

gdevenyi wants to merge 2 commits into
BIC-MNI:develop-1.9.18from
gdevenyi:nifti-ninja

Conversation

@gdevenyi

Copy link
Copy Markdown
Contributor

Why

A standalone libminc build with the bundled NIfTI (LIBMINC_USE_NIFTI=ON) fails with the Ninja generator. There are three causes, and each one hides the next:

  1. bad $-escape (literal $ must be written as $$): the NIfTI ExternalProject installs with $(MAKE) install, which is Makefile syntax.
  2. '.../libniftiio.a', needed by 'libminc2.so.5.3.0', missing and no known rule to make it: minc2 links the two NIfTI archives, and Ninja needs a rule that makes each file it links.
  3. input_nifti.c: fatal error: nifti1.h: No such file or directory (shared builds only): minc2_static compiles input_nifti.c, but only minc2 waits for the NIfTI build.

What

  • cmake-modules/BuildNIFTI.cmake: install with cmake -E env DESTDIR=... cmake --build <BINARY_DIR> --target install. Declare libniftiio.a and libznz.a as BUILD_BYPRODUCTS (CMake 3.2; libminc requires 3.10).
  • CMakeLists.txt: minc2_static depends on the NIFTI target when that target exists.

Verification

On this branch, standalone, NIfTI on: Ninja (shared and static) and Unix Makefiles (shared and static) each configure, build and pass 59/59 tests. A second Ninja build has no work to do. CI has no Ninja job, so CI does not check this.

Notes

🤖 Generated with Claude Code

https://claude.ai/code/session_01RCrjXCD1KiTWLtah7wmySX

gdevenyi and others added 2 commits September 21, 2026 14:28
A standalone build with the bundled NIfTI failed with Ninja:

  ninja: error: build.ninja:2352: bad $-escape (literal $ must be written as $$)

The ExternalProject installed with `$(MAKE) install DESTDIR=...`, which is
Makefile syntax. It now runs `cmake --build <BINARY_DIR> --target install`
under `cmake -E env DESTDIR=...`; CMake's install scripts read DESTDIR from
the environment.

That alone moves Ninja to the next error:

  ninja: error: '.../libniftiio.a', needed by 'libminc2.so.5.3.0',
  missing and no known rule to make it

Make orders minc2 after the ExternalProject from add_dependencies() alone;
Ninja also wants a rule that names the file it links. libniftiio.a and
libznz.a are now declared as BUILD_BYPRODUCTS (CMake 3.2; libminc requires
3.10), and their paths are set before ExternalProject_Add to use them.

The minc-toolkit superbuild uses its own BuildNIFTI.cmake and is not
affected.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RCrjXCD1KiTWLtah7wmySX
With LIBMINC_BUILD_SHARED_LIBS, libminc also builds minc2_static from the
same sources, including input_nifti.c. Only minc2 depended on the NIFTI
ExternalProject, so nothing kept minc2_static from compiling before the
NIfTI headers were staged. Ninja does exactly that:

  input_nifti.c:13:10: fatal error: nifti1.h: No such file or directory

minc2_static now depends on NIFTI too, when that target exists. In the
minc-toolkit superbuild this repeats its own ADD_DEPENDENCIES(minc2_static).

Verified on develop-1.9.18 with the previous commit, standalone, NIfTI on:
Ninja (shared and static) and Unix Makefiles (shared and static) each
configure, build and pass 59/59 tests. A second Ninja build has no work
to do.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RCrjXCD1KiTWLtah7wmySX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant