Skip to content

Commit

Permalink
Merge branch 'upstream-nifti' into nifticlib3.0
Browse files Browse the repository at this point in the history
# By NIFTI Upstream
* upstream-nifti:
  nifti 2020-08-07 (96b9954f)
  • Loading branch information
gdevenyi committed Jul 8, 2021
2 parents 68221fd + 9c2c9fa commit faa754c
Show file tree
Hide file tree
Showing 27 changed files with 16,928 additions and 0 deletions.
273 changes: 273 additions & 0 deletions Modules/ThirdParty/NIFTI/src/nifti/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)

set(NIFTI_MAX_VALIDATED_CMAKE_VERSION "3.13.1")
if("${CMAKE_VERSION}" VERSION_LESS_EQUAL "${NIFTI_MAX_VALIDATED_CMAKE_VERSION}")
# As of 2018-12-04 NIFTI has been validated to build with cmake version 3.13.1 new policies.
# Set and use the newest cmake policies that are validated to work
set(NIFTI_CMAKE_POLICY_VERSION "${CMAKE_VERSION}")
else()
set(NIFTI_CMAKE_POLICY_VERSION "${NIFTI_MAX_VALIDATED_CMAKE_VERSION}")
endif()
cmake_policy(VERSION ${NIFTI_CMAKE_POLICY_VERSION})

set(NIFTI_HOMEPAGE_URL "https://nifti-imaging.github.io")
execute_process(COMMAND git "describe" "--tags"
OUTPUT_VARIABLE GIT_REPO_VERSION_UNCLEANED
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

#Extract the GIT_REPO_VERSION as composed of non-negative integer components,
# i.e. <major>[.<minor>[.<patch>[.<tweak>]]]
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+((beta.*)?(alpha.*)?\\.[0-9]+(\\.g[0-9a-f]+)?)?"
GIT_REPO_VERSION "${GIT_REPO_VERSION_UNCLEANED}")

if( NOT GIT_REPO_VERSION )
message(NOTE "Invalid git tag does not match required regular expression, "
"can not extract version information from '${GIT_REPO_VERSION_UNCLEANED}'")
# NOTE: cmake -DGIT_REPO_VERSION:STRING=<major>[.<minor>[.<patch>[.<tweak>]]] can be used
# to set the repo string for non-git repos.
set(GIT_REPO_VERSION "0.0.0.0") #Manually set the version string for testing purposes
endif()
project(NIFTI
VERSION ${GIT_REPO_VERSION}
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)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
include(nifti_macros)

set_property(GLOBAL PROPERTY nifti_installed_targets)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
include(CMakeDependentOption)

if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.13")
set(CMAKE_VER_AT_LEAST_3_13 1 CACHE BOOL "Is set for cmake >=3.13")
endif()

# add option to build shared libraries. The default is OFF to maintain the
# current build behavior
option( BUILD_SHARED_LIBS "Toggle building shared libraries." OFF)

# Include executables as part of the build
option(NIFTI_BUILD_APPLICATIONS "Build various utility tools" ON)
mark_as_advanced(NIFTI_BUILD_APPLICATIONS)

#When including nifti as a subpackage, a prefix is often needed to avoid conflicts with sytem installed libraries.
set_if_not_defined(NIFTI_PACKAGE_PREFIX "")
set(PACKAGE_NAME ${NIFTI_PACKAGE_PREFIX}NIFTI)
set_if_not_defined(NIFTI_INSTALL_EXPORT_NAME ${PACKAGE_NAME}Targets)

# Set default shared library version
# This library version will be applied to all libraries in the package
# unless it is not explicitely for a certain lib.
set(NIFTI_SHAREDLIB_VERSION ${GIT_REPO_VERSION} )
if(BUILD_SHARED_LIBS AND NOT NIFTI_LIBRARY_PROPERTIES)
set(NIFTI_LIBRARY_PROPERTIES ${DEFAULT_SHARED_LIBS}
BUILD_SHARED_LIBS TRUE POSITION_INDEPENDENT_CODE TRUE
)
endif()

set_if_not_defined(NIFTI_INSTALL_RUNTIME_DIR bin)
set_if_not_defined(NIFTI_INSTALL_LIBRARY_DIR lib)
set_if_not_defined(NIFTI_INSTALL_ARCHIVE_DIR ${NIFTI_INSTALL_LIBRARY_DIR})
set_if_not_defined(NIFTI_INSTALL_INCLUDE_DIR include/nifti)
set_if_not_defined(NIFTI_INSTALL_MAN_DIR share/man/man1)
set_if_not_defined(NIFTI_INSTALL_DOC_DIR share/doc/${PROJECT_NAME})
set_if_not_defined(NIFTI_ZLIB_LIBRARIES "")
set_if_not_defined(ZNZ_COMPILE_DEF "")
if(NOT NIFTI_ZLIB_LIBRARIES) # If using a custom zlib library, skip the find package
### USE AS STAND ALONE PACKAGE
find_package(ZLIB REQUIRED)
set(NIFTI_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
endif()
#message(STATUS "---------------------ZLIB -${NIFTI_ZLIB_LIBRARIES}--")
add_definitions(-DHAVE_ZLIB)

set_if_not_defined(NIFTI_INSTALL_NO_DOCS TRUE)

# Include test to verify linking in installed executables
# The test should only be added when applications are built, and no prefix string is set.
cmake_dependent_option(
TEST_INSTALL "Add a test to check that linking to SO libraries occurs correctly during installation." ON
"${NIFTI_PACKAGE_PREFIX};${NIFTI_BUILD_APPLICATIONS};${BUILD_SHARED_LIBS};${NIFTI_BUILD_TESTING}" OFF
)

# Add a default attempt at setting the run path correctly for binaries
if(NOT CMAKE_SKIP_INSTALL_RPATH)
file(
RELATIVE_PATH
relDir
${CMAKE_INSTALL_PREFIX}/${NIFTI_INSTALL_RUNTIME_DIR}
${CMAKE_INSTALL_PREFIX}/${NIFTI_INSTALL_LIBRARY_DIR}
)
if(APPLE)
set_if_not_defined(CMAKE_INSTALL_RPATH "@loader_path/${relDir}")
else()
set_if_not_defined(CMAKE_INSTALL_RPATH "\$ORIGIN/${relDir}")
endif()
endif()

if(NOT NIFTI_INSTALL_NO_DOCS)
find_program(HELP2MAN help2man REQUIRED)
set(MAN_DIR ${PROJECT_BINARY_DIR}/manpages)
file(MAKE_DIRECTORY ${MAN_DIR})
endif()
#######################################################################

set_if_not_defined(BUILD_TESTING ON)
set_if_not_defined(NIFTI_BUILD_TESTING ${BUILD_TESTING})
if (NIFTI_BUILD_TESTING )
include(CTest)
enable_testing()
#Needs an if clause and more work before testing can take place.
option(
DOWNLOAD_TEST_DATA
"Allow download of data used for some tests. Can be used in conjunction with ctest label filter '-LE NEEDS_DATA'"
ON
)
set_if_not_defined(NIFTI_SHELL_SCRIPT_TESTS "ON")
if(DOWNLOAD_TEST_DATA)
if ( CMAKE_VERSION VERSION_LESS 3.11.0 )
# CMAKE VERSION 3.11.0 needed for fetching data with cmake
message(FATAL_ERROR "ERROR: The testing framework for nifti_clib requires CMake version 3.11.0 or greater")
endif()

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 <downloaded tarball>).
FetchContent_Declare( fetch_testing_data
URL https://github.com/NIFTI-Imaging/nifti-test-data/archive/v3.0.2.tar.gz
URL_HASH SHA256=5dafec078151018da7aaf3c941bd31f246f590bc34fa3fef29ce77a773db16a6
)
FetchContent_GetProperties(fetch_testing_data)
if(NOT fetch_testing_data_POPULATED)
set(FETCHCONTENT_QUIET OFF)
FetchContent_Populate( fetch_testing_data )
endif()
endif()
endif()

#######################################################################
# Find unix math libraries
if(NOT WIN32)
find_library(NIFTI_SYSTEM_MATH_LIB m)
else()
set(NIFTI_SYSTEM_MATH_LIB "")
endif()
#######################################################################
add_subdirectory(znzlib)
add_subdirectory(niftilib)

option(USE_NIFTICDF_CODE "Build nifticdf library and tools" ON)
mark_as_advanced(USE_NIFTICDF_CODE)
if(USE_NIFTICDF_CODE)
add_subdirectory(nifticdf)
endif()

option(USE_NIFTI2_CODE "Build the nifti2 library and tools" ON)
mark_as_advanced(USE_NIFTI2_CODE)
cmake_dependent_option(USE_CIFTI_CODE "Build the cifti library and tools" OFF "USE_NIFTI2_CODE" OFF)
mark_as_advanced(USE_CIFTI_CODE)

if( USE_NIFTI2_CODE )
add_subdirectory(nifti2)
if( USE_CIFTI_CODE )
add_subdirectory(cifti)
endif()
endif()

option(USE_FSL_CODE "If OFF, The copyright of this code is questionable for inclusion with nifti." OFF)
mark_as_advanced(USE_FSL_CODE)
# the order of add_subdirectory is important! fsliolob has to preceed examples
# as otherwise FSLIOLIB_SOURCE_DIR is undefined and hence the examples
# will fail to compile
if(USE_FSL_CODE)
add_subdirectory(fsliolib)
endif()

# Allow an uninstall (with some risk of messiness)

if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY
)

add_custom_target(
uninstall COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)
endif()

# Report installed targets
get_property(nifti_installed_targets GLOBAL PROPERTY nifti_installed_targets)
message("nifti_installed_targets: ${nifti_installed_targets}")

if(CMAKE_VER_AT_LEAST_3_13)
# Target installation for CMake versions >=3.13
foreach(targ ${nifti_installed_targets})
install_nifti_target(${targ})
endforeach()
endif()

if(NOT NIFTI_INSTALL_NO_DOCS)
install(
DIRECTORY ${MAN_DIR}/
DESTINATION ${NIFTI_INSTALL_MAN_DIR}
FILES_MATCHING REGEX ".*.1.gz"
PERMISSIONS OWNER_READ WORLD_READ
)
install(
FILES ${PROJECT_SOURCE_DIR}/README.md
DESTINATION ${NIFTI_INSTALL_DOC_DIR}
)
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/real_easy/
DESTINATION ${NIFTI_INSTALL_DOC_DIR}/examples
)
endif()

if(NIFTI_INSTALL_EXPORT_NAME STREQUAL "NIFTITargets")
#######################################################################
# CMake itself and can use some CMake facilities for creating the package files.
# This allows for find_package(NIFTI 2.1.0 NO_MODULE) to work for pulling in
# NIFTI libraries into an external project
include(CMakePackageConfigHelpers)
set(CONFIG_SETUP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME})
set(ConfigPackageLocation share/cmake/${PACKAGE_NAME})

write_basic_package_version_file(
${CONFIG_SETUP_DIR}/${PACKAGE_NAME}ConfigVersion.cmake
VERSION ${GIT_REPO_VERSION}
COMPATIBILITY AnyNewerVersion
)

configure_file(cmake/NIFTIConfig.cmake
${CONFIG_SETUP_DIR}/${PACKAGE_NAME}Config.cmake
COPYONLY
)


install(EXPORT ${NIFTI_INSTALL_EXPORT_NAME}
FILE NIFTITargets.cmake
NAMESPACE ${PACKAGE_NAME}::
DESTINATION ${ConfigPackageLocation}
COMPONENT Development
)

install(FILES
${CONFIG_SETUP_DIR}/${PACKAGE_NAME}Config.cmake
${CONFIG_SETUP_DIR}/${PACKAGE_NAME}ConfigVersion.cmake
COMPONENT Development
DESTINATION ${ConfigPackageLocation}
)
endif()

#######################################################################
## Add the cpack configuration settings last
option(NIFTI_USE_PACKAGING "Configure the packaging options for NIFTI" OFF)
mark_as_advanced(NIFTI_USE_PACKAGING)
if(NIFTI_USE_PACKAGING)
include(cmake/NIFTICPackConfig.cmake)
endif()
15 changes: 15 additions & 0 deletions Modules/ThirdParty/NIFTI/src/nifti/CTestConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## This file should be placed in the root directory of your project.
## Then modify the CMakeLists.txt file in the root directory of your
## project to incorporate the testing dashboard.
##
## # The following are required to submit to the CDash dashboard:
## enable_testing()
## include(CTest)

set(CTEST_PROJECT_NAME "NIFTI")
set(CTEST_NIGHTLY_START_TIME "00:00:00 EST")

set(CTEST_DROP_METHOD "https")
set(CTEST_DROP_SITE "my.cdash.org")
set(CTEST_DROP_LOCATION "/submit.php?project=nifti_clib")
set(CTEST_DROP_SITE_CDASH TRUE)
9 changes: 9 additions & 0 deletions Modules/ThirdParty/NIFTI/src/nifti/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Niftilib has been developed by members of the NIFTI DFWG and volunteers in the
neuroimaging community and serves as a reference implementation of the nifti-1
file format.

http://nifti.nimh.nih.gov/

Nifticlib code is released into the public domain, developers are encouraged to
incorporate niftilib code into their applications, and, to contribute changes
and enhancements to niftilib.
94 changes: 94 additions & 0 deletions Modules/ThirdParty/NIFTI/src/nifti/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# NIFTI C Libraries

`Nifti_clib` is a set of i/o libraries for reading and writing files in the nifti-1,
nifti-2, and (to some degree) cifti file formats. These libraries provide api's
for binary file format for storing medical image data, e.g. magnetic resonance
image (MRI) and functional MRI (fMRI) brain images.

This repository contains the C implementations. ( See other repositories at
[github](https://github.com/NIFTI-Imaging) for Java, MATLAB, and Python libraries).

`Nifti_clib` has been developed by members of the NIFTI DFWG and volunteers in the
neuroimaging community and serves as a reference implementation of the nifti-1
and nifti-2 file formats. In addition to being a reference implementation, we
hope it is also a useful i/o library.

`Nifti_clib` code is released into the public domain,
developers are encouraged to incorporate niftilib code into their applications,
and, to contribute changes and enhancements to niftilib. Please contact us if
you would like to contribute additonal functionality to the i/o library.

The main webpage for this project is [hosted on github](https://nifti-imaging.github.io/).
This web site provde historical information. Additional informaiton from the [NIFTI DFWG](http://nifti.nimh.nih.gov)

The testing dashboard for monitoring the health of the libraries is at
[my.cdash.org](https://my.cdash.org/index.php?project=nifti_clib).


## Nifti-2 C libraries
coming soon.

## Cifti C libraries
Introductory, coming soon.

## Nifti-1 C libraries

* Version 2.0.0 beta release Jul 2010
* Version 1.1.0 beta release Aug 2008
* Version 1.0.0 beta release Dec 2007
* Version 0.6 beta release Aug 2007
* Version 0.5 beta release May 2007
* Version 0.4 beta release Sept. 2006
* Version 0.3 beta release April 2006
* Version 0.2 beta release August 12, 2005
* Version 0.1 beta release March 11, 2005

niftilib code is released into the public domain.


## Library directories

directory | description
----------|-------------
znzlib | low level library for handling read/write of compressed files.
niftilib | core i/o routines for reading and writing nifti-1 format files. Primarily routines to read/write and manipulate the header field information, including orientation matrices. Volume-wise, timecourse-wise, access to image data.
nifti2 | core i/o routines for reading and writing nifti-2 format files.
nifticdf | functions to compute cumulative distributions and their inverses
fsliolib | i/o routines for reading and writing nifti-1 format files, higher level than niftilib, includes routines for reading the data blob by volume, timecourse, etc., and, addresses image orientation issues. `work in progress, subject to significant revision.....`
cifti | very basic routines for reading cifti format files

## Destination directories

directory | description
----------|------------
bin | destination directory for installed programs
include | destination directory for library header files
lib | destination directory for compiled libraries
docs | destination directory Doxygen html (created via "make doc")


## Example directories

directory | description
------------|-------------
`real_easy` | simple code snippets, some using ref. libs., some not


## Other directories

directory | description
------------|------------
Testing | directory containing code to test the libraries
packaging | spec file for building RPMs, and template package description for Dev-Cpp (http://www.bloodshed.net/devcpp.html)



## Instructions to build

command | description
------------|-------------
"make all" | results will be left in the directories: bin/ include/ lib/
"make help" | will show more build options

![NIFTI ICON](https://avatars0.githubusercontent.com/u/45666806?s=200&v=4)

Loading

0 comments on commit faa754c

Please sign in to comment.