Skip to content

Commit

Permalink
Merge pull request #2630 from gdevenyi/nifticlib3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex authored Jul 9, 2021
2 parents 231ecb7 + faa754c commit cf3cea5
Show file tree
Hide file tree
Showing 62 changed files with 1,501 additions and 17,229 deletions.
5 changes: 2 additions & 3 deletions Modules/ThirdParty/NIFTI/UpdateFromUpstream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ readonly name="nifti"
readonly ownership="NIFTI Upstream <[email protected]>"
readonly subtree="Modules/ThirdParty/NIFTI/src/nifti"
readonly repo="https://github.com/NIFTI-Imaging/nifti_clib.git"
readonly tag="master"
readonly tag="v3.0.1"
readonly shortlog=false
readonly paths="
CMakeLists.txt
CTestConfig.cmake
LICENSE
README
README.md
cmake
znzlib
niftilib
nifti2
"

extract_source () {
Expand Down
1 change: 1 addition & 0 deletions Modules/ThirdParty/NIFTI/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(NIFTI_USE_PACKAGING OFF CACHE BOOL "Do not use packaging from nifti when inc
set(NIFTI_BUILD_APPLICATIONS OFF CACHE BOOL "Do not build applications provided by NIFTI" FORCE)
# Testing is not compatible with ITK at the moment
set(NIFTI_BUILD_TESTING OFF) # "Do not build nifit testing applications"
set(DOWNLOAD_TEST_DATA OFF) # Don't download testing data

add_definitions(-DITKZLIB)
set(NIFTI_INSTALL_EXPORT_NAME ${ITKNIFTI-targets}) # "Set the nifti package export target name"
Expand Down
229 changes: 155 additions & 74 deletions Modules/ThirdParty/NIFTI/src/nifti/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16.3 FATAL_ERROR)
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}")
Expand All @@ -11,106 +11,150 @@ 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 2.1.0
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)

macro(set_if_not_defined var defaultvalue)
# Macro allowing to set a variable to its default value if not already defined.
# The default value is set with:
# (1) if set, the value environment variable <var>.
# (2) if set, the value of local variable variable <var>.
# (3) if none of the above, the value passed as a parameter.
# Setting the optional parameter 'OBFUSCATE' will display 'OBFUSCATED' instead of the real value.
set(_obfuscate FALSE)
foreach(arg ${ARGN})
if(arg STREQUAL "OBFUSCATE")
set(_obfuscate TRUE)
endif()
endforeach()
if(DEFINED ENV{${var}} AND NOT DEFINED ${var})
set(_value "$ENV{${var}}")
if(_obfuscate)
set(_value "OBFUSCATED")
endif()
message(STATUS "Setting '${var}' variable with environment variable value '${_value}'")
set(${var} $ENV{${var}})
endif()
if(NOT DEFINED ${var})
set(_value "${defaultvalue}")
if(_obfuscate)
set(_value "OBFUSCATED")
endif()
message(STATUS "Setting '${var}' variable with default value '${_value}'")
set(${var} "${defaultvalue}")
endif()
endmacro()
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 ${NIFTI_VERSION_MAJOR}.${NIFTI_VERSION_MINOR}.${NIFTI_VERSION_PATCH} )
string( REGEX MATCH "^[0-9]+" NIFTI_SHAREDLIB_SOVERSION ${NIFTI_SHAREDLIB_VERSION})
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 VERSION ${NIFTI_SHAREDLIB_VERSION} SOVERSION ${NIFTI_SHAREDLIB_SOVERSION}
BUILD_SHARED_LIBS TRUE POSITION_INDEPENDENT_CODE TRUE
)
endif()

set_if_not_defined(NIFTI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_PREFIX}/bin")
set_if_not_defined(NIFTI_INSTALL_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/lib")
set_if_not_defined(NIFTI_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include/nifti")
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)
# Modern CMake install COMPONENTS is being considered in upstream NIFTI
# Setting NIFTI_INSTALL_NO_DEVELOPMENT & NIFTI_INSTALL_NO_LIBRARIES to
# FALSE to make explicit that the development and libraries
# can not be skipped for installation. Use the install COMPONENTS
# features instead.
set(NIFTI_INSTALL_NO_DEVELOPMENT FALSE)
set(NIFTI_INSTALL_NO_LIBRARIES FALSE)

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()
#######################################################################
enable_testing()
include(CTest)
#Needs an if clause and more work before testing can take place.

set_if_not_defined(BUILD_TESTING ON)
set_if_not_defined(NIFTI_BUILD_TESTING ${BUILD_TESTING})
if (NIFTI_BUILD_TESTING AND CMAKE_VERSION GREATER_EQUAL 3.11.0) # CMAKE VERSION 3.11.0 needed for fetching data with cmake
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.0.tar.gz
URL_HASH SHA256=8a22554ca196f707f7c8cdc102e1a30117cd67da41d269390952683076ffcac8
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)
if(NOT fetch_testing_data_POPULATED)
set(FETCHCONTENT_QUIET OFF)
message(STATUS "Downloading testing data... please wait")
FetchContent_Populate( fetch_testing_data )
message(STATUS "download complete.")
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)
Expand All @@ -121,12 +165,8 @@ if(USE_NIFTICDF_CODE)
add_subdirectory(nifticdf)
endif()

option(NIFTI_BUILD_APPLICATIONS "Build various utility tools" ON)
mark_as_advanced(NIFTI_BUILD_APPLICATIONS)

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

Expand All @@ -146,40 +186,81 @@ if(USE_FSL_CODE)
add_subdirectory(fsliolib)
endif()

set_if_not_defined(NIFTI_INSTALL_EXPORT_NAME "NIFTITargets")
if(NIFTI_INSTALL_EXPORT_NAME EQUAL "NIFTITargets")
# 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(
"${CMAKE_CURRENT_BINARY_DIR}/NIFTI/NIFTIConfigVersion.cmake"
VERSION ${NIFTI_VERSION}
${CONFIG_SETUP_DIR}/${PACKAGE_NAME}ConfigVersion.cmake
VERSION ${GIT_REPO_VERSION}
COMPATIBILITY AnyNewerVersion
)

export(EXPORT NIFTITargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/NIFTI/NIFTITargets.cmake"
NAMESPACE ${NIFTI_PACKAGE_PREFIX}NIFTI::
)
configure_file(cmake/NIFTIConfig.cmake
"${CMAKE_CURRENT_BINARY_DIR}/NIFTI/NIFTIConfig.cmake"
${CONFIG_SETUP_DIR}/${PACKAGE_NAME}Config.cmake
COPYONLY
)

set(ConfigPackageLocation lib/cmake/NIFTI)
install(EXPORT NIFTITargets
FILE NIFTITargets.cmake
NAMESPACE ${NIFTI_PACKAGE_PREFIX}NIFTI::

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

install(FILES
cmake/NIFTIConfig.cmake
"${CMAKE_CURRENT_BINARY_DIR}/NIFTI/NIFTIConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation}
${CONFIG_SETUP_DIR}/${PACKAGE_NAME}Config.cmake
${CONFIG_SETUP_DIR}/${PACKAGE_NAME}ConfigVersion.cmake
COMPONENT Development
DESTINATION ${ConfigPackageLocation}
)
endif()

Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/NIFTI/src/nifti/CTestConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
set(CTEST_PROJECT_NAME "NIFTI")
set(CTEST_NIGHTLY_START_TIME "00:00:00 EST")

set(CTEST_DROP_METHOD "http")
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)
Loading

0 comments on commit cf3cea5

Please sign in to comment.