Skip to content

Commit

Permalink
Merge pull request #2859 from MRtrix3/thirdparty
Browse files Browse the repository at this point in the history
Improve handling of external dependencies
  • Loading branch information
daljit46 authored Aug 15, 2024
2 parents cd0d42f + 287dcd9 commit d533879
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 30,060 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: install dependencies
run: |
sudo apt-get update
sudo apt-get install clang qt6-base-dev libglvnd-dev libeigen3-dev zlib1g-dev libfftw3-dev ninja-build python3-distutils python3-numpy
sudo apt-get install clang qt6-base-dev libglvnd-dev zlib1g-dev libfftw3-dev ninja-build python3-distutils python3-numpy
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
- name: install dependencies
run: |
sudo apt-get update
sudo apt-get install g++-9 qt6-base-dev libglvnd-dev libeigen3-dev zlib1g-dev libfftw3-dev ninja-build python3-numpy
sudo apt-get install g++-9 qt6-base-dev libglvnd-dev zlib1g-dev libfftw3-dev ninja-build python3-numpy
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
Expand Down Expand Up @@ -208,7 +208,6 @@ jobs:
${{env.MINGW_PACKAGE_PREFIX}}-bc
${{env.MINGW_PACKAGE_PREFIX}}-cmake
${{env.MINGW_PACKAGE_PREFIX}}-diffutils
${{env.MINGW_PACKAGE_PREFIX}}-eigen3
${{env.MINGW_PACKAGE_PREFIX}}-fftw
${{env.MINGW_PACKAGE_PREFIX}}-gcc
${{env.MINGW_PACKAGE_PREFIX}}-ninja
Expand Down Expand Up @@ -282,5 +281,4 @@ jobs:
extensions: 'h,cpp'
clangFormatVersion: 16
# Ignore third party headers
exclude: './core/file/json.h ./core/file/nifti1.h ./core/file/nifti2.h'

exclude: './thirdparty ./_deps'
2 changes: 1 addition & 1 deletion .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: ZedThree/[email protected]
id: review
with:
apt_packages: g++,qt6-base-dev,libqt6opengl6-dev,libglvnd-dev,libeigen3-dev,zlib1g-dev,libfftw3-dev,ninja-build
apt_packages: g++,qt6-base-dev,libqt6opengl6-dev,libglvnd-dev,zlib1g-dev,libfftw3-dev,ninja-build
config_file: .clang-tidy

- uses: ZedThree/clang-tidy-review/[email protected]
Expand Down
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
67 changes: 67 additions & 0 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
include(FetchContent)

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
# We avoid configuring the Eigen library via FetchContent_MakeAvaiable
# to avoid the verbosity of Eigen's CMake configuration output.
if(MRTRIX_LOCAL_DEPENDENCIES)
set(eigen_url ${MRTRIX_DEPENDENCIES_DIR}/eigen-3.4.0.tar.gz)
else()
set(eigen_url "https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz")
endif()

FetchContent_Declare(
eigen3
DOWNLOAD_EXTRACT_TIMESTAMP ON
URL ${eigen_url}
)
FetchContent_GetProperties(Eigen3)
if(NOT eigen3_POPULATED)
FetchContent_Populate(Eigen3)
add_library(Eigen3 INTERFACE)
add_library(Eigen3::Eigen ALIAS Eigen3)
target_include_directories(Eigen3 INTERFACE "${eigen3_SOURCE_DIR}")
endif()

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


# Half-precision floating-point library
if(MRTRIX_LOCAL_DEPENDENCIES)
set(half_url ${MRTRIX_DEPENDENCIES_DIR}/half-2.1.0.zip)
else()
set(half_url "https://sourceforge.net/projects/half/files/half/2.1.0/half-2.1.0.zip/download")
endif()
FetchContent_Declare(
half
DOWNLOAD_EXTRACT_TIMESTAMP ON
URL ${half_url}
)
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")
3 changes: 1 addition & 2 deletions cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ if(MRTRIX_USE_PCH)
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pch_cmd.cpp CONTENT "int main(){}")
add_executable(pch_cmd ${CMAKE_CURRENT_BINARY_DIR}/pch_cmd.cpp)
target_include_directories(pch_cmd PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../core)
find_package(Eigen3 REQUIRED)
target_link_libraries(pch_cmd PRIVATE Eigen3::Eigen mrtrix::common)
target_link_libraries(pch_cmd PRIVATE Eigen3::Eigen half::half mrtrix::common)
target_precompile_headers(pch_cmd PRIVATE
[["app.h"]]
[["image.h"]]
Expand Down
3 changes: 2 additions & 1 deletion cmd/mrinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@

#include "command.h"
#include "dwi/gradient.h"
#include "file/json.h"
#include "file/json_utils.h"
#include "header.h"
#include "image_io/pipe.h"
#include "phase_encoding.h"
#include "types.h"

#include <nlohmann/json.hpp>

using namespace MR;
using namespace App;

Expand Down
7 changes: 3 additions & 4 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ include(CheckSymbolExists)

file(GLOB_RECURSE CORE_SRCS *.cpp *.h)

find_package(Eigen3 REQUIRED NO_MODULE)
find_package(ZLIB REQUIRED)
find_package(FFTW REQUIRED)
find_package(Git QUIET)
find_package(Threads REQUIRED)
find_package(PNG QUIET)

# The find modules for Eigen3, and PNG don't log the location
# of the libraries, so we do it manually here
message(STATUS "Found Eigen3: ${EIGEN3_INCLUDE_DIR}")
if(PNG_FOUND)
message(STATUS "Found PNG: ${PNG_LIBRARIES}")
endif()
Expand Down Expand Up @@ -90,6 +86,9 @@ target_link_libraries(mrtrix-core PUBLIC
mrtrix::common
Threads::Threads
${FFTW_LIBRARIES}
nlohmann_json::nlohmann_json
nifti::nifti
half::half
)

target_include_directories(mrtrix-core PUBLIC
Expand Down
Loading

0 comments on commit d533879

Please sign in to comment.