From 43c39fa86e29e5e03c66e9317e23ac8ff0b34fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=9Clgen?= Date: Sun, 2 Jun 2024 00:37:46 +0100 Subject: [PATCH] Refactorisations --- CMakeLists.txt | 103 +++++++++++++++++++------------------ Doxyfile.in | 7 +++ niftyreg_build_version.txt | 2 +- reg-io/RNifti/NiftiImage.h | 1 + reg-test/CMakeLists.txt | 14 ++--- 5 files changed, 68 insertions(+), 59 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7d5e6c7..c8c0415d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -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) @@ -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) @@ -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 @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/Doxyfile.in b/Doxyfile.in index df013886..42344ddc 100644 --- a/Doxyfile.in +++ b/Doxyfile.in @@ -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 #--------------------------------------------------------------------------- diff --git a/niftyreg_build_version.txt b/niftyreg_build_version.txt index 8d73f938..57214136 100644 --- a/niftyreg_build_version.txt +++ b/niftyreg_build_version.txt @@ -1 +1 @@ -422 +423 diff --git a/reg-io/RNifti/NiftiImage.h b/reg-io/RNifti/NiftiImage.h index 26cffe98..991d2447 100644 --- a/reg-io/RNifti/NiftiImage.h +++ b/reg-io/RNifti/NiftiImage.h @@ -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; diff --git a/reg-test/CMakeLists.txt b/reg-test/CMakeLists.txt index 4bf3d667..26a5a825 100755 --- a/reg-test/CMakeLists.txt +++ b/reg-test/CMakeLists.txt @@ -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) @@ -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) @@ -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) #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- @@ -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) #----------------------------------------------------------------------------- #-----------------------------------------------------------------------------