Skip to content

Commit

Permalink
Refactorisations
Browse files Browse the repository at this point in the history
  • Loading branch information
onurulgen committed Jun 1, 2024
1 parent f680bce commit 43c39fa
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 59 deletions.
103 changes: 52 additions & 51 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ project(NiftyReg)
#-----------------------------------------------------------------------------
# Set C++ standard version
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
#-----------------------------------------------------------------------------
if(APPLE)
set(CMAKE_MACOSX_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
Expand Down Expand Up @@ -45,8 +46,7 @@ add_definitions(-DNR_VERSION="${NR_VERSION}")
find_package(Git)
if(GIT_FOUND)
message(STATUS "Found Git")
file(COPY "${CMAKE_SOURCE_DIR}/update_version_hook" DESTINATION "${CMAKE_SOURCE_DIR}/.git/hooks" USE_SOURCE_PERMISSIONS)
file(RENAME "${CMAKE_SOURCE_DIR}/.git/hooks/update_version_hook" "${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit")
execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/update_version_hook" "${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit")
endif(GIT_FOUND)
#-----------------------------------------------------------------------------
if(MSVC)
Expand All @@ -55,7 +55,7 @@ if(MSVC)
endif(MSVC)
#-----------------------------------------------------------------------------
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_definitions(-fPIC)
add_definitions(-fPIC)
endif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
#-----------------------------------------------------------------------------
option(BUILD_ALL_DEP "All the dependencies are build" OFF)
Expand All @@ -71,69 +71,69 @@ option(USE_NRRD "To use the NRRD file format" OFF)
mark_as_advanced(USE_NRRD)
#-----------------------------------------------------------------------------
if(WIN32)
set(BUILD_ALL_DEP ON CACHE BOOL "All the dependencies are build" FORCE)
set(BUILD_ALL_DEP ON CACHE BOOL "All the dependencies are build" FORCE)
endif(WIN32)
#-----------------------------------------------------------------------------
# All dependencies are build to create the 3DSlicer package
if(BUILD_NR_SLICER_EXT)
set(BUILD_ALL_DEP ON)
mark_as_advanced(FORCE BUILD_ALL_DEP)
set(BUILD_ALL_DEP ON)
mark_as_advanced(FORCE BUILD_ALL_DEP)
else(BUILD_NR_SLICER_EXT)
mark_as_advanced(CLEAR BUILD_ALL_DEP)
mark_as_advanced(CLEAR BUILD_ALL_DEP)
endif(BUILD_NR_SLICER_EXT)
#-----------------------------------------------------------------------------
# Z library
# Try first to find the z library on the system and built is from the sources if it can not be find
if(NOT BUILD_ALL_DEP)
find_package(ZLIB)
if(ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIR})
message(STATUS "Found zlib - the z library will not be built")
else(ZLIB_FOUND)
include_directories(${CMAKE_SOURCE_DIR}/reg-io/zlib)
message(STATUS "zlib not found - the z library will be built")
endif(ZLIB_FOUND)
find_package(ZLIB)
if(ZLIB_FOUND)
include_directories(SYSTEM ${ZLIB_INCLUDE_DIR})
message(STATUS "Found zlib - the z library will not be built")
else(ZLIB_FOUND)
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/reg-io/zlib)
message(STATUS "zlib not found - the z library will be built")
endif(ZLIB_FOUND)
else(NOT BUILD_ALL_DEP)
include_directories(${CMAKE_SOURCE_DIR}/reg-io/zlib)
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/reg-io/zlib)
endif(NOT BUILD_ALL_DEP)
#-----------------------------------------------------------------------------
# Try to find the png library and header on the system
if(NOT BUILD_ALL_DEP)
## PNG support - First try to find the PNG library on the system and build it if it is not found
## I did not use the FindPNG.cmake here as the zlib is also included into the project
if(CYGWIN)
if(NOT BUILD_SHARED_LIBS)
set (PNG_DEFINITIONS -DPNG_STATIC)
endif(NOT BUILD_SHARED_LIBS)
endif(CYGWIN)
set(PNG_NAMES ${PNG_NAMES} png libpng png15 libpng15 png15d libpng15d png14 libpng14 png14d libpng14d png12 libpng12 png12d libpng12d)
find_library(PNG_LIBRARY NAMES ${PNG_NAMES})
find_path(PNG_INCLUDE_DIR png.h
/usr/local/include/libpng
/sw/include
)
# If the png library and header can not be found, it is build from the sources
if(NOT PNG_LIBRARY OR NOT PNG_INCLUDE_DIR)
message(STATUS "libpng not found - the png library will be built")
set(PNG_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/reg-io/png/lpng)
set(PNG_LIBRARY png)
set(BUILD_INTERNAL_PNG true)
else(NOT PNG_LIBRARY OR NOT PNG_INCLUDE_DIR)
message(STATUS "Found libpng - the png library will not be built")
set(BUILD_INTERNAL_PNG false)
endif(NOT PNG_LIBRARY OR NOT PNG_INCLUDE_DIR)
else(NOT BUILD_ALL_DEP)
# PNG support - First try to find the PNG library on the system and build it if it is not found
# I did not use the FindPNG.cmake here as the zlib is also included into the project
if(CYGWIN)
if(NOT BUILD_SHARED_LIBS)
set(PNG_DEFINITIONS -DPNG_STATIC)
endif(NOT BUILD_SHARED_LIBS)
endif(CYGWIN)
set(PNG_NAMES ${PNG_NAMES} png libpng png15 libpng15 png15d libpng15d png14 libpng14 png14d libpng14d png12 libpng12 png12d libpng12d)
find_library(PNG_LIBRARY NAMES ${PNG_NAMES})
find_path(PNG_INCLUDE_DIR png.h
/usr/local/include/libpng
/sw/include
)
# If the png library and header can not be found, it is build from the sources
if(NOT PNG_LIBRARY OR NOT PNG_INCLUDE_DIR)
message(STATUS "libpng not found - the png library will be built")
set(PNG_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/reg-io/png/lpng)
set(PNG_LIBRARY png)
set(BUILD_INTERNAL_PNG true)
else(NOT PNG_LIBRARY OR NOT PNG_INCLUDE_DIR)
message(STATUS "Found libpng - the png library will not be built")
set(BUILD_INTERNAL_PNG false)
endif(NOT PNG_LIBRARY OR NOT PNG_INCLUDE_DIR)
else(NOT BUILD_ALL_DEP)
set(PNG_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/reg-io/png/lpng)
set(PNG_LIBRARY png)
endif(NOT BUILD_ALL_DEP)
include_directories(${CMAKE_SOURCE_DIR}/reg-io/png)
include_directories(${PNG_INCLUDE_DIR})
include_directories(SYSTEM ${PNG_INCLUDE_DIR})
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/reg-io/png)
#-----------------------------------------------------------------------------
include_directories(${CMAKE_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/reg-io)
include_directories(${CMAKE_SOURCE_DIR}/reg-lib)
include_directories(${CMAKE_SOURCE_DIR}/reg-lib/cpu)
include_directories(${CMAKE_SOURCE_DIR}/third-party)
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/third-party)
#-----------------------------------------------------------------------------
if(USE_OPENCL)
# Find the OpenCL package
Expand All @@ -143,8 +143,8 @@ if(USE_OPENCL)
message(SEND_ERROR "OpenCL not found. The USE_OPENCL flag is turned OFF")
else(NOT OpenCL_FOUND)
message(STATUS "Found OpenCL")
include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
include_directories(${CMAKE_SOURCE_DIR}/reg-lib/cl)
include_directories(${OpenCL_INCLUDE_DIRS})
add_definitions(-DUSE_OPENCL)
endif(NOT OpenCL_FOUND)
endif(USE_OPENCL)
Expand All @@ -159,8 +159,8 @@ if(USE_CUDA)
set(USE_CUDA OFF CACHE BOOL "To use the CUDA platform" FORCE)
message(SEND_ERROR "CUDA not found. The USE_CUDA flag is turned OFF")
else(NOT CMAKE_CUDA_COMPILER)
include_directories(SYSTEM ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
include_directories(${CMAKE_SOURCE_DIR}/reg-lib/cuda)
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
add_definitions(-DUSE_CUDA)
endif(NOT CMAKE_CUDA_COMPILER)
endif(USE_CUDA)
Expand All @@ -183,19 +183,20 @@ if(USE_OPENMP)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
if (OpenMP_C_INCLUDE_DIRS)
include_directories(${OpenMP_C_INCLUDE_DIRS})
include_directories(SYSTEM ${OpenMP_C_INCLUDE_DIRS})
endif(OpenMP_C_INCLUDE_DIRS)
if (OpenMP_CXX_INCLUDE_DIRS)
include_directories(${OpenMP_CXX_INCLUDE_DIRS})
include_directories(SYSTEM ${OpenMP_CXX_INCLUDE_DIRS})
endif(OpenMP_CXX_INCLUDE_DIRS)
link_libraries(${OpenMP_CXX_LIBRARIES})
endif(NOT OPENMP_FOUND)
endif(USE_OPENMP)
#-----------------------------------------------------------------------------
if(BUILD_SHARED_LIBS)
if(USE_CUDA)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build the libraries as shared." FORCE)
message(WARNING "CUDA is not compatible with shared libraries. Forcing BUILD_SHARED_LIBS to OFF")
set(NIFTYREG_LIBRARY_TYPE STATIC)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build the libraries as shared." FORCE)
message(WARNING "CUDA is not compatible with shared libraries. Forcing BUILD_SHARED_LIBS to OFF")
set(NIFTYREG_LIBRARY_TYPE STATIC)
else(USE_CUDA)
set(NIFTYREG_LIBRARY_TYPE SHARED)
endif(USE_CUDA)
Expand All @@ -219,7 +220,7 @@ endif(BUILD_TESTING)
# add a target to generate API documentation with Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(DOXY_EXCLUDED_PATTERNS "")
set(DOXY_EXCLUDED_PATTERNS "*/build/* */reg-io/RNifti/*")
if(NOT BUILD_TESTING)
set(DOXY_EXCLUDED_PATTERNS "${DOXY_EXCLUDED_PATTERNS} */reg-test/*")
endif(NOT BUILD_TESTING)
Expand Down
7 changes: 7 additions & 0 deletions Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,13 @@ FILTER_SOURCE_FILES = YES

FILTER_SOURCE_PATTERNS =

# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that
# is part of the input, its contents will be placed on the main page
# (index.html). This can be useful if you have a project on for instance GitHub
# and want to reuse the introduction page also for the doxygen output.

USE_MDFILE_AS_MAINPAGE = README.md

#---------------------------------------------------------------------------
# configuration options related to source browsing
#---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion niftyreg_build_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
422
423
1 change: 1 addition & 0 deletions reg-io/RNifti/NiftiImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,7 @@ class NiftiImage
if (image == nullptr)
return;
switch (dim) {
case Dim::NDim: break;
case Dim::X:
image->pixdim[1] = image->dx = value;
break;
Expand Down
14 changes: 7 additions & 7 deletions reg-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ endif(NOT Catch2_FOUND)
# Build the coverage test
option(WITH_COVERAGE "Set up the C, CXX and linker flags to run the coverage test" OFF)
if(WITH_COVERAGE)
if(NOT MSVC)
if(UNIX)
# Check prerequisites
find_program(LCOV lcov REQUIRED)
find_program(GENHTML genhtml REQUIRED)
Expand Down Expand Up @@ -53,7 +53,7 @@ if(WITH_COVERAGE)
add_custom_target(clean_coverage
COMMAND ${LCOV} --directory . --zerocounters
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
else(NOT MSVC)
else(UNIX)
# Check prerequisites
find_program(OPENCPPCOVERAGE OpenCppCoverage REQUIRED)

Expand All @@ -76,7 +76,7 @@ if(WITH_COVERAGE)
# Gather data only for the reg-lib directory
COMMAND ${OPENCPPCOVERAGE} --sources=${COVERAGE_SOURCE} --cover_children -- ctest -C Debug
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif(NOT MSVC)
endif(UNIX)
endif(WITH_COVERAGE)
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
Expand All @@ -94,14 +94,14 @@ endif(USE_CUDA)
if(USE_OPENCL)
set(CTEST_BUILD_NAME "${CTEST_BUILD_NAME}_opencl")
endif(USE_OPENCL)
if(NOT MSVC)
if(UNIX)
unset(BUILDNAME CACHE)
unset(BUILDNAME)
set(BUILDNAME ${CTEST_BUILD_NAME} CACHE STRING "Build name variable for CDash" FORCE)
else(MSVC)
else(UNIX)
set(BUILDNAME ${CTEST_BUILD_NAME} CACHE STRING "Build name variable for CDash")
message(STATUS "The buildname might need manual editing")
endif(NOT MSVC)
message(STATUS "The build name might need manual editing")
endif(UNIX)
mark_as_advanced(BUILDNAME)
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
Expand Down

0 comments on commit 43c39fa

Please sign in to comment.