From 8f120483d55d5e08b3cca4edc7e16445916b94a2 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Fri, 14 Aug 2026 20:46:49 -0400 Subject: [PATCH 1/2] COMP: Guard the CMP0169 policy setting so older CMake still configures CMakeLists.txt sets policy CMP0169 unconditionally, to keep using the deprecated FetchContent_Populate. CMP0169 was introduced in CMake 3.30, and cmake_policy(SET) on an unknown policy is a hard error, so any CMake older than that fails to configure at all: CMake Error at CMakeLists.txt:175 (cmake_policy): Policy "CMP0169" is not known to this version of CMake. That includes the CMake 3.28 shipped by Ubuntu 24.04, which is what the CI runners and the project's own Dockerfile use, and it sits well above the cmake_minimum_required(VERSION 3.10.2) the project advertises. Wrapping it in if(POLICY CMP0169) is the standard idiom. Verified configuring with both CMake 3.28.3 and 4.4.2. (cherry picked from commit 3aefe1b487195f04323b4ec4a8d3a1a2f7a92145) --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04b106ce..fd551f15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,7 +163,12 @@ if (NIFTI_BUILD_TESTING ) include(FetchContent) # fetch data a configure time to simplify tests # If new or changed data is needed, add that data to the https://github.com/NIFTI-Imaging/nifti-test-data repo # make a new release, and then update the URL and hash (shasum -a 256 ). - cmake_policy(SET CMP0169 OLD) + # CMP0169 (deprecating FetchContent_Populate) only exists from CMake 3.30; + # setting it unconditionally is a hard error on every earlier release, + # including the CMake 3.28 that Ubuntu 24.04 ships. + if(POLICY CMP0169) + cmake_policy(SET CMP0169 OLD) + endif() FetchContent_Declare( fetch_testing_data URL https://github.com/NIFTI-Imaging/nifti-test-data/archive/v3.0.2.tar.gz URL_HASH SHA256=5dafec078151018da7aaf3c941bd31f246f590bc34fa3fef29ce77a773db16a6 From fd0f7747484cb254740499a3b51b47bd9e5e6f9e Mon Sep 17 00:00:00 2001 From: "Gabriel A. Devenyi" Date: Fri, 14 Aug 2026 23:11:10 -0400 Subject: [PATCH 2/2] COMP: Build as ISO C11 with no compiler extensions The build never set a C standard, so it used the compiler default. Set CMAKE_C_STANDARD 11 with C_EXTENSIONS OFF. Two POSIX dependencies were being satisfied silently by the gnu default and now have to be requested: cifti/afni_xml.c strdup(), 3 uses. Without a declaration this was an implicit function declaration returning int assigned to char * -- an error in C99 onward. nifti1_io.c, popen()/pclose() in the optional PIGZ write path, nifti2_io.c only compiled with -DFSLSTYLE_PIGZ_SUPPORT=ON. Each file defines _POSIX_C_SOURCE 200809L ahead of its includes, so the dependency is visible where it is taken. (cherry picked from commit 49b48b49d9e91c955a2fa36958a8e454c5c5c864) --- CMakeLists.txt | 6 ++++++ cifti/afni_xml.c | 4 ++++ nifti2/nifti2_io.c | 3 +++ niftilib/nifti1_io.c | 3 +++ 4 files changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd551f15..92b9631b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,12 @@ project(NIFTI DESCRIPTION "Niftilib is a set of i/o libraries for reading and writing files in the nifti-1 data format. nifti-1 is a binary file format for storing medical image data, e.g. magnetic resonance image (MRI) and functional MRI (fMRI) brain images." LANGUAGES C) +# Sources needing POSIX interfaces (strdup, popen) request them with +# _POSIX_C_SOURCE at the top of the file. +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS OFF) + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) include(nifti_macros) diff --git a/cifti/afni_xml.c b/cifti/afni_xml.c index a9910a1b..781d0892 100644 --- a/cifti/afni_xml.c +++ b/cifti/afni_xml.c @@ -1,3 +1,7 @@ +/* strdup() is POSIX, not ISO C11; must precede every #include. + C23 adds it, so this define goes away once C23 is the floor. */ +#define _POSIX_C_SOURCE 200809L + #include #include #include diff --git a/nifti2/nifti2_io.c b/nifti2/nifti2_io.c index c8cc6b23..6bd74a8d 100644 --- a/nifti2/nifti2_io.c +++ b/nifti2/nifti2_io.c @@ -1,3 +1,6 @@ +/* popen()/pclose() in the PIGZ write path are POSIX, not ISO C11. */ +#define _POSIX_C_SOURCE 200809L + #define NIFTI2_IO_C #include diff --git a/niftilib/nifti1_io.c b/niftilib/nifti1_io.c index eb8887f3..502b76ab 100644 --- a/niftilib/nifti1_io.c +++ b/niftilib/nifti1_io.c @@ -1,3 +1,6 @@ +/* popen()/pclose() in the PIGZ write path are POSIX, not ISO C11. */ +#define _POSIX_C_SOURCE 200809L + #define NIFTI1_IO_C #include