-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
151 lines (128 loc) · 4.81 KB
/
CMakeLists.txt
File metadata and controls
151 lines (128 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
include(CheckSymbolExists)
find_package(ZLIB REQUIRED)
find_package(FFTW REQUIRED)
find_package(Git QUIET)
find_package(Threads REQUIRED)
find_package(PNG QUIET)
find_package(Dawn CONFIG REQUIRED)
find_package(slang CONFIG REQUIRED)
if(PNG_FOUND)
message(STATUS "Found PNG: ${PNG_LIBRARIES}")
endif()
# Check to see if we can use lgamma_r() function in custom Math::betaincreg()
# The function is defined under _REENTRANT on some systems (e.g. MacOS)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_REENTRANT)
check_symbol_exists(lgamma_r "math.h" MRTRIX_HAVE_LGAMMA_R)
list(REMOVE_AT CMAKE_REQUIRED_DEFINITIONS -1)
if(NOT MRTRIX_HAVE_LGAMMA_R)
message(STATUS "No lgamma_r() function found; statistical inference may have poorer multi-threading performance")
endif()
file(GLOB_RECURSE HEADLESS_SOURCES *.h *.cpp)
find_package(Git QUIET)
# Create version target and library
set(MRTRIX_VERSION_CPP ${CMAKE_CURRENT_BINARY_DIR}/mrtrix_version.cpp)
set(CMD_VERSION_CPP ${CMAKE_CURRENT_BINARY_DIR}/executable_version.cpp)
add_custom_target(mrtrix-executable-version-target ALL
COMMAND ${CMAKE_COMMAND}
-D GIT_EXECUTABLE=${GIT_EXECUTABLE}
-D MRTRIX_BASE_VERSION=${MRTRIX_BASE_VERSION}
-D DST=${CMD_VERSION_CPP}
-D SRC=${CMAKE_CURRENT_SOURCE_DIR}/executable_version.cpp.in
-P ${PROJECT_SOURCE_DIR}/cmake/FindVersion.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating executable_version.cpp"
BYPRODUCTS ${CMD_VERSION_CPP}
VERBATIM
)
add_custom_target(mrtrix-version-target ALL
COMMAND ${CMAKE_COMMAND}
-D GIT_EXECUTABLE=${GIT_EXECUTABLE}
-D MRTRIX_BASE_VERSION=${MRTRIX_BASE_VERSION}
-D DST=${MRTRIX_VERSION_CPP}
-D SRC=${CMAKE_CURRENT_SOURCE_DIR}/mrtrix_version.cpp.in
-P ${PROJECT_SOURCE_DIR}/cmake/FindVersion.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating mrtrix_version.cpp"
BYPRODUCTS ${MRTRIX_VERSION_CPP}
VERBATIM
)
add_library(mrtrix-version STATIC ${MRTRIX_VERSION_CPP})
add_library(mrtrix::version ALIAS mrtrix-version)
target_include_directories(mrtrix-version PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
add_dependencies(mrtrix-version mrtrix-version-target)
add_library(mrtrix-executable-version STATIC ${CMD_VERSION_CPP})
add_library(mrtrix::executable-version ALIAS mrtrix-executable-version)
target_include_directories(mrtrix-executable-version PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
add_dependencies(mrtrix-executable-version mrtrix-executable-version-target)
if(MRTRIX_BUILD_STATIC)
set(MRTRIX_LIBRARY_TYPE STATIC)
else()
set(MRTRIX_LIBRARY_TYPE SHARED)
endif()
add_library(mrtrix-core ${MRTRIX_LIBRARY_TYPE} ${HEADLESS_SOURCES})
add_library(mrtrix::core ALIAS mrtrix-core)
target_include_directories(mrtrix-core PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
if(MRTRIX_USE_PCH)
target_precompile_headers(mrtrix-core PRIVATE
[["exception.h"]]
<fstream>
<complex>
)
endif()
target_compile_definitions(mrtrix-core PUBLIC
MRTRIX_BASE_VERSION="${MRTRIX_BASE_VERSION}"
$<$<BOOL:${MRTRIX_HAVE_LGAMMA_R}>:MRTRIX_HAVE_LGAMMA_R>
)
if(APPLE AND MRTRIX_HAVE_LGAMMA_R)
target_compile_definitions(mrtrix-core PRIVATE _REENTRANT)
endif()
if(PNG_FOUND)
target_compile_definitions(mrtrix-core PUBLIC MRTRIX_PNG_SUPPORT)
target_link_libraries(mrtrix-core PUBLIC PNG::PNG)
else()
message(WARNING "libpng not found, disabling PNG support")
endif()
target_link_libraries(mrtrix-core PUBLIC
dawn::webgpu_dawn
Eigen3::Eigen
ZLIB::ZLIB
fftw3::fftw
mrtrix::common
mrtrix::version
Threads::Threads
nlohmann_json::nlohmann_json
nifti::nifti
slang::slang
tcb::span
)
# On Windows, the libraries need to be in the same directory as the executables
if(WIN32)
set_target_properties(mrtrix-core PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
)
add_custom_command(TARGET mrtrix-core POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:dawn::webgpu_dawn>
$<TARGET_FILE:slang::slang>
$<TARGET_FILE_DIR:mrtrix-core>
COMMENT "Copying imported dependencies to output directory"
)
# In an MSYS2 environment, dawn fails to load the required vulkan-1.dll library when
# creating a WebGPU instance. To remedy this, we copy the DLL from C:/Windows/System32
# to the build output directory.
# TODO: Investigate further and find a better solution.
if(NOT MSVC)
add_custom_command(TARGET mrtrix-core POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$ENV{WINDIR}/System32/vulkan-1.dll
$<TARGET_FILE_DIR:mrtrix-core>
COMMENT "Copying vulkan-1.dll to output directory"
)
endif()
endif()
install(TARGETS mrtrix-core
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)