-
Notifications
You must be signed in to change notification settings - Fork 40
/
CMakeLists.txt
323 lines (289 loc) · 11.9 KB
/
CMakeLists.txt
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
cmake_minimum_required(VERSION 3.16)
# ----------------------------- Setup -----------------------------
project(mlx.data LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
# ----------------------------- Configuration -----------------------------
option(MLX_BUILD_PYTHON_BINDINGS "Build python bindings for mlx data" OFF)
if(NOT MLX_DATA_VERSION)
set(MLX_DATA_VERSION 0.0.2)
endif()
# ----------------------------- 3rdparty -----------------------------
include(FetchContent)
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
# stb
FetchContent_Declare(
stb
GIT_REPOSITORY "https://github.com/nothings/stb.git"
GIT_TAG "03f50e343d796e492e6579a11143a085429d7f5d"
CONFIGURE_COMMAND "" BUILD_COMMAND "")
FetchContent_GetProperties(stb)
if(NOT stb_POPULATED)
FetchContent_Populate(stb)
endif()
add_library(stb INTERFACE)
target_include_directories(stb INTERFACE ${stb_SOURCE_DIR})
# bxzstr
find_package(ZLIB)
find_package(BZip2)
find_package(LibLZMA)
add_library(bxzstr INTERFACE)
if(ZLIB_FOUND)
target_include_directories(bxzstr INTERFACE ${ZLIB_INCLUDE_DIRS})
target_link_libraries(bxzstr INTERFACE ${ZLIB_LIBRARIES})
set(BXZSTR_Z_SUPPORT 1)
else()
set(BXZSTR_Z_SUPPORT 0)
endif()
if(BZIP2_FOUND)
target_include_directories(bxzstr INTERFACE ${BZIP2_INCLUDE_DIRS})
target_link_libraries(bxzstr INTERFACE ${BZIP2_LIBRARIES})
set(BXZSTR_BZ2_SUPPORT 1)
else()
set(BXZSTR_BZ2_SUPPORT 0)
endif()
if(LIBLZMA_FOUND)
target_include_directories(bxzstr INTERFACE ${LIBLZMA_INCLUDE_DIRS})
target_link_libraries(bxzstr INTERFACE ${LIBLZMA_LIBRARIES})
set(BXZSTR_LZMA_SUPPORT 1)
else()
set(BXZSTR_LZMA_SUPPORT 0)
endif()
set(BXZSTR_ZSTD_SUPPORT 0)
set(bxzstr_patch git apply ${CMAKE_CURRENT_SOURCE_DIR}/cmake/bxzstr.patch)
FetchContent_Declare(
bxzstr
GIT_REPOSITORY "https://github.com/tmaklin/bxzstr.git"
GIT_TAG "a6e5d743b5547a3ec23fd842813dec8067c8aff1"
# patch is always applied, so we silently fail if already patched
PATCH_COMMAND ${bxzstr_patch} || true CONFIGURE_COMMAND "" BUILD_COMMAND "")
FetchContent_GetProperties(bxzstr)
if(NOT bxzstr_POPULATED)
FetchContent_Populate(bxzstr)
configure_file(${bxzstr_SOURCE_DIR}/bxzstr/config.hpp.in
${bxzstr_SOURCE_DIR}/bxzstr/config.hpp)
endif()
target_include_directories(bxzstr INTERFACE ${bxzstr_SOURCE_DIR})
# pybind11
if(MLX_BUILD_PYTHON_BINDINGS)
find_package(Python COMPONENTS Interpreter Development.Module)
# avoid warning regarding FindPythonInterp and FindPythonLibs modules which
# are deprecated from CMake 3.27
set(pybind11_patch git apply
${CMAKE_CURRENT_SOURCE_DIR}/cmake/pybind11-v2.11.1.patch)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11
GIT_TAG v2.11.1
# patch is always applied, so we silently fail if already patched
PATCH_COMMAND ${pybind11_patch} || true)
FetchContent_GetProperties(pybind11)
if(NOT pybind11_POPULATED)
FetchContent_Populate(pybind11)
add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
endif()
endif()
# ----------------------------- lib -----------------------------
find_package(SndFile)
find_package(SampleRate)
find_package(Threads REQUIRED)
find_package(FFMPEG COMPONENTS avcodec avdevice avformat avutil swscale
swresample)
find_package(
AWSSDK
COMPONENTS s3
QUIET)
if(AWSSDK_FOUND)
message(
STATUS
"AWS SDK found (includes: ${AWSSDK_INCLUDE_DIRS} libs: ${AWSSDK_LIBRARIES})"
)
else()
message(STATUS "Could NOT find AWS SDK")
endif()
find_package(JPEGTURBO)
if(NOT JPEGTURBO_FOUND)
find_package(JPEG)
endif()
include(CheckSymbolExists)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
check_symbol_exists(dlopen "dlfcn.h" HAS_DLOPEN)
check_symbol_exists(RTLD_NOLOAD "dlfcn.h" HAS_RTLD_NOLOAD)
if(APPLE)
check_symbol_exists(_dyld_get_image_name "mach-o/dyld.h"
HAS_DYLD_GET_IMAGE_NAME)
else()
set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE=1")
check_symbol_exists(dl_iterate_phdr "link.h" HAS_DL_ITERATE_PHDR)
endif()
set(mlxdata-src
${CMAKE_CURRENT_LIST_DIR}/mlx/data/Array.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/Sample.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/Dataset.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/Buffer.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/Stream.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/BatchShape.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/CSVReader.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/FileFetcher.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/Graph.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/Numpy.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/State.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/TARReader.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/ThreadController.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/ThreadPool.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/Tokenizer.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/Levenshtein.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/Utils.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/audio/Audio.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/audio/AudioSndfile.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/audio/AudioSampleRate.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/image/ImageTransform.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/image/ImageIO.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/image/ImageSTBI.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/image/ImageJPEG.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/video/Video.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/video/VideoFFMPEG.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/buffer/Buffer.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/buffer/Batch.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/buffer/DynamicBatch.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/buffer/FromStream.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/buffer/FromVector.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/buffer/FilesFromTAR.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/buffer/Partition.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/buffer/Perm.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/buffer/Shuffle.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/buffer/Transform.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/Stream.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/Batch.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/Buffered.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/DynamicBatch.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/Compose.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/CSVReader.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/FromBuffer.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/LineReader.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/OrderedPrefetch.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/Partition.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/Prefetch.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/Repeat.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/Shuffle.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/SlidingWindow.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/stream/Transform.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/Op.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/FilterByShape.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/FilterKey.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/ReadFromTAR.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/KeyTransform.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/SampleTransform.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/Shape.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/RenameKey.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/SaveImage.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/LoadAudio.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/LoadImage.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/LoadFile.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/LoadNumpy.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/LoadVideo.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/Pad.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/Shard.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/Squeeze.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/Tokenize.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/ImageTransform.cpp
${CMAKE_CURRENT_LIST_DIR}/mlx/data/op/RemoveValue.cpp)
if(AWSSDK_FOUND)
list(APPEND mlxdata-src
${CMAKE_CURRENT_LIST_DIR}/mlx/data/core/AWSFileFetcher.cpp)
endif()
add_library(mlxdata STATIC ${mlxdata-src})
if(HAS_DLOPEN AND HAS_RTLD_NOLOAD)
target_compile_definitions(mlxdata PRIVATE MLX_HAS_DLOPEN_NOLOAD)
target_link_libraries(mlxdata PRIVATE ${CMAKE_DL_LIBS})
endif()
if(HAS_DL_ITERATE_PHDR)
target_compile_definitions(mlxdata PRIVATE MLX_HAS_DL_ITERATE_PHDR)
target_link_libraries(mlxdata PRIVATE ${CMAKE_DL_LIBS})
elseif(HAS_DYLD_GET_IMAGE_NAME)
target_compile_definitions(mlxdata PRIVATE MLX_HAS_DYLD_GET_IMAGE_NAME)
target_link_libraries(mlxdata PRIVATE ${CMAKE_DL_LIBS})
endif()
target_link_libraries(mlxdata PRIVATE $<BUILD_INTERFACE:stb>
$<BUILD_INTERFACE:bxzstr>)
target_include_directories(
mlxdata PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
$<INSTALL_INTERFACE:include>)
set_property(TARGET mlxdata PROPERTY POSITION_INDEPENDENT_CODE ON)
if(SndFile_FOUND)
target_link_libraries(mlxdata PRIVATE SndFile::sndfile)
target_compile_definitions(mlxdata PRIVATE MLX_HAS_SNDFILE)
endif()
if(SampleRate_FOUND)
target_link_libraries(mlxdata PRIVATE SampleRate::samplerate)
target_compile_definitions(mlxdata PRIVATE MLX_HAS_SAMPLERATE)
endif()
target_link_libraries(mlxdata PRIVATE Threads::Threads)
if(JPEGTURBO_FOUND)
target_include_directories(mlxdata PUBLIC ${JPEGTURBO_INCLUDE_DIRS})
target_link_libraries(mlxdata PRIVATE ${JPEGTURBO_LIBRARIES})
target_compile_definitions(mlxdata PUBLIC MLX_HAS_JPEG)
endif()
if(JPEG_FOUND)
target_include_directories(mlxdata PUBLIC ${JPEG_INCLUDE_DIRS})
target_link_libraries(mlxdata PRIVATE ${JPEG_LIBRARIES})
target_compile_definitions(mlxdata PUBLIC MLX_HAS_JPEG)
endif()
if(AWSSDK_FOUND)
target_include_directories(mlxdata PUBLIC ${AWSSDK_INCLUDE_DIRS})
target_link_libraries(mlxdata PRIVATE ${AWSSDK_LIBRARIES})
target_compile_definitions(mlxdata PUBLIC MLX_HAS_AWS)
endif()
if(FFMPEG_avformat_FOUND)
target_include_directories(mlxdata PRIVATE ${FFMPEG_INCLUDE_DIRS})
target_link_libraries(mlxdata PRIVATE ${FFMPEG_LIBRARIES})
target_compile_definitions(mlxdata PUBLIC MLX_HAS_FFMPEG)
endif()
include("tests/CMakeLists.txt")
if(MLX_BUILD_PYTHON_BINDINGS)
include("python/src/CMakeLists.txt")
endif()
# ----------------------------- Installation -----------------------------
include(GNUInstallDirs)
# Install library
install(
TARGETS mlxdata
EXPORT MLXDataTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Install headers
install(
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/mlx
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT headers
FILES_MATCHING
PATTERN "*.h")
# Install cmake config
set(MLX_DATA_CMAKE_BUILD_CONFIG ${CMAKE_BINARY_DIR}/MLXDataConfig.cmake)
set(MLX_DATA_CMAKE_BUILD_VERSION_CONFIG
${CMAKE_BINARY_DIR}/MLXDataConfigVersion.cmake)
set(MLX_DATA_CMAKE_INSTALL_MODULE_DIR share/cmake/MLXData)
install(
EXPORT MLXDataTargets
FILE MLXDataTargets.cmake
DESTINATION ${MLX_DATA_CMAKE_INSTALL_MODULE_DIR})
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${MLX_DATA_CMAKE_BUILD_VERSION_CONFIG}
COMPATIBILITY SameMajorVersion
VERSION ${MLX_DATA_VERSION})
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/mlx-data.pc.in ${MLX_DATA_CMAKE_BUILD_CONFIG}
INSTALL_DESTINATION ${MLX_DATA_CMAKE_INSTALL_MODULE_DIR}
NO_CHECK_REQUIRED_COMPONENTS_MACRO
PATH_VARS CMAKE_INSTALL_LIBDIR CMAKE_INSTALL_INCLUDEDIR
MLX_DATA_CMAKE_INSTALL_MODULE_DIR)
install(FILES ${MLX_DATA_CMAKE_BUILD_CONFIG}
${MLX_DATA_CMAKE_BUILD_VERSION_CONFIG}
DESTINATION ${MLX_DATA_CMAKE_INSTALL_MODULE_DIR})