-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.cmake
66 lines (57 loc) · 2.72 KB
/
utils.cmake
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
function(DownloadTorch version cuda destination)
if(NOT EXISTS ${destination}/libtorch)
set(DOWNLOAD_FILE ${CMAKE_CURRENT_SOURCE_DIR}/torch.zip)
if(cuda)
if(WIN32)
file(DOWNLOAD https://download.pytorch.org/libtorch/cu118/libtorch-win-shared-with-deps-${version}%2Bcu118.zip ${DOWNLOAD_FILE} SHOW_PROGRESS)
elseif(APPLE)
message(FATAL_ERROR "NO GPU SUPPORT FOR APPLE")
else()
file(DOWNLOAD https://download.pytorch.org/libtorch/cu118/libtorch-cxx11-abi-shared-with-deps-${version}%2Bcu118.zip ${DOWNLOAD_FILE} SHOW_PROGRESS)
endif()
else()
#file(DOWNLOAD https://download.pytorch.org/libtorch/cu118/libtorch-win-shared-with-deps-${version}%2Bcu118.zip ${CMAKE_CURRENT_SOURCE_DIR}/torch.zip SHOW_PROGRESS)
if(WIN32)
file(DOWNLOAD https://download.pytorch.org/libtorch/cpu/libtorch-win-shared-with-deps-${version}%2Bcpu.zip ${DOWNLOAD_FILE} SHOW_PROGRESS)
elseif(APPLE)
file(DOWNLOAD https://download.pytorch.org/libtorch/cpu/libtorch-macos-${version}.zip ${DOWNLOAD_FILE} SHOW_PROGRESS)
else()
file(DOWNLOAD https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-${version}%2Bcpu.zip ${DOWNLOAD_FILE} SHOW_PROGRESS)
endif()
endif()
message(STATUS "Extracting")
file(ARCHIVE_EXTRACT INPUT ${DOWNLOAD_FILE} DESTINATION ${destination})
message(STATUS "Done Extracting")
file(REMOVE ${DOWNLOAD_FILE})
endif()
endfunction()
function(BuildTorchVision VERSION DESTINATION)
if(NOT EXISTS ${DESTINATION}/torchvision)
set(CLONED_DIR ${CMAKE_CURRENT_BINARY_DIR}/vision)
execute_process(
COMMAND git clone --depth 1 --branch v${VERSION} https://github.com/pytorch/vision ${CLONED_DIR}
)
execute_process(
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release -DUSE_PYTHON=OFF -DWITH_CUDA=${WITH_CUDA} -DWITH_PNG=ON -DWITH_JPEG=ON -DCMAKE_PREFIX_PATH=${TORCH_DEPS_DIR} -S ${CLONED_DIR} -B ${CLONED_DIR}/build/
)
execute_process(
COMMAND ${CMAKE_COMMAND} --build ${CLONED_DIR}/build --config Release
)
execute_process(
COMMAND ${CMAKE_COMMAND} --install ${CLONED_DIR}/build --prefix ${DESTINATION}/torchvision
)
endif()
endfunction()
# Get the version from the package.json
function(GetVersion)
file(READ ${CMAKE_SOURCE_DIR}/package.json PACKAGE_JSON)
string(JSON PACKAGE_VERSION GET ${PACKAGE_JSON} version)
set(PACKAGE_VERSION ${PACKAGE_VERSION} PARENT_SCOPE)
endfunction()
# generate node.lib
function(GenerateNodeLib)
if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
# Generate node.lib
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
endif()
endfunction()