Skip to content

Commit

Permalink
Provide option to specify local dependencies folder
Browse files Browse the repository at this point in the history
- Developers can now specify an optional local folder containing that
points to the sources of eigen, json for modern c++ and half. This can
be useful in offline environments without network access.

- Dependency handling code is moved into a separate CMake module.

- Half is directly fetched from sourceforge.net

- FetchContent now downloads source repos in PROJECT_SOURCE_DIR/_deps to
avoid downloading repos again for separate build directories.
  • Loading branch information
daljit46 committed Jul 10, 2024
1 parent 4825a4e commit ccd437e
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 4,887 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ build/
CMakeLists.txt.user
testing/data/tmp*
testing/data/*-tmp-*
_deps/
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ option(MRTRIX_USE_PCH "Use precompiled headers" ON)
option(MRTRIX_PYTHON_SOFTLINK "Build directory softlink to Python source code rather than copying" ON)
option(MRTRIX_BUILD_NON_CORE_STATIC "Build MRtrix's non-core code as a static library" OFF)

set(MRTRIX_DEPENDENCIES_DIR "" CACHE PATH
"An optional local directory containing thirdparty dependencies:\n \
- Eigen3 https://gitlab.com/libeigen/eigen\n \
- Json for Modern C++ https://github.com/nlohmann/json\n \
- Half https://half.sourceforge.net/\n"
)

if(MRTRIX_BUILD_TESTS)
if(CMAKE_VERSION VERSION_GREATER 3.17)
list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
Expand Down Expand Up @@ -68,6 +75,7 @@ include(LinkerSetup)
include(FindFFTW)
include(CompilerCache)
include(ECMEnableSanitizers)
include(Dependencies)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
include(MacOSBundle)
endif()
Expand Down
73 changes: 73 additions & 0 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
include(FetchContent)

set(FETCHCONTENT_BASE_DIR ${PROJECT_SOURCE_DIR}/_deps)

message(STATUS "${MRTRIX_DEPENDENCIES_DIR}")
if(NOT ${MRTRIX_DEPENDENCIES_DIR} STREQUAL "")
message(STATUS "Using local dependencies at ${MRTRIX_DEPENDENCIES_DIR}")
set(MRTRIX_LOCAL_DEPENDENCIES ON)
else()
set(MRTRIX_LOCAL_DEPENDENCIES OFF)
endif()

# Eigen
if(MRTRIX_LOCAL_DEPENDENCIES)
FetchContent_Declare(
eigen3
SOURCE_DIR ${MRTRIX_DEPENDENCIES_DIR}/eigen
UPDATE_DISCONNECTED ON
)
else()
FetchContent_Declare(
eigen3
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3.4.0
PATCH_COMMAND git apply --ignore-space-change --ignore-whitespace ${PROJECT_SOURCE_DIR}/thirdparty/eigen.patch
UPDATE_DISCONNECTED ON
)
endif()
FetchContent_MakeAvailable(eigen3)


# Json for Modern C++
if(MRTRIX_LOCAL_DEPENDENCIES)
FetchContent_Declare(
json
SOURCE_DIR ${MRTRIX_DEPENDENCIES_DIR}/json
UPDATE_DISCONNECTED ON
)
else()
FetchContent_Declare(json
DOWNLOAD_EXTRACT_TIMESTAMP ON
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
)
endif()
FetchContent_MakeAvailable(json)


# Half-precision floating-point library
if(MRTRIX_LOCAL_DEPENDENCIES)
FetchContent_Declare(
half
SOURCE_DIR ${MRTRIX_DEPENDENCIES_DIR}/half
UPDATE_DISCONNECTED ON
)
else()
FetchContent_Declare(
half
DOWNLOAD_EXTRACT_TIMESTAMP ON
URL "https://sourceforge.net/projects/half/files/half/2.1.0/half-2.1.0.zip/download"
)
endif()

FetchContent_MakeAvailable(half)

add_library(half INTERFACE)
add_library(half::half ALIAS half)
target_include_directories(half INTERFACE "${half_SOURCE_DIR}/include")


# Nifti headers
add_library(nifti INTERFACE)
add_library(nifti::nifti ALIAS nifti)
target_include_directories(nifti INTERFACE "${PROJECT_SOURCE_DIR}/thirdparty/nifti")
1 change: 1 addition & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ target_link_libraries(mrtrix-core PUBLIC
${FFTW_LIBRARIES}
nlohmann_json::nlohmann_json
nifti::nifti
half::half
)

target_include_directories(mrtrix-core PUBLIC
Expand Down
Loading

0 comments on commit ccd437e

Please sign in to comment.