This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
46 lines (38 loc) · 1.81 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
cmake_minimum_required(VERSION 3.13)
if(APPLE)
if(CMAKE_OSX_ARCHITECTURES STREQUAL "")
message(STATUS "Setting macOS architecture to ${CMAKE_HOST_SYSTEM_PROCESSOR}")
set(CMAKE_OSX_ARCHITECTURES ${CMAKE_HOST_SYSTEM_PROCESSOR} CACHE STRING "Build architecture for macOS" FORCE)
endif()
endif()
project(onnxruntime_node_gpu)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (APPLE)
add_definitions(-DHAS_COREML)
endif ()
if (WIN32)
add_definitions(-DHAS_ONNXRUNTIME_CUDA_PROVIDERS)
add_definitions(-DHAS_DML_PROVIDER_FACTORY)
elseif(UNIX AND NOT APPLE)
find_library(ONNXRUNTIME_PROVIDERS_CUDA_LIB NAMES onnxruntime_providers_cuda HINTS ${CUSTOM_LIBRARY_PATHS})
if(ONNXRUNTIME_PROVIDERS_CUDA_LIB)
message(STATUS "Found ONNX Runtime CUDA providers library: ${ONNXRUNTIME_PROVIDERS_CUDA_LIB}")
add_definitions(-DHAS_ONNXRUNTIME_CUDA_PROVIDERS)
else()
message(STATUS "ONNX Runtime CUDA providers library not found")
endif()
endif ()
file(GLOB ORT_NODEJS_BINDING_SOURCE_FILES ${CMAKE_SOURCE_DIR}/src/*.cc)
# Define the Node.js addon target
add_library(${PROJECT_NAME} SHARED ${ORT_NODEJS_BINDING_SOURCE_FILES} ${CMAKE_JS_SRC})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC} ${CMAKE_SOURCE_DIR}/node_modules/node-addon-api)
target_link_directories(${PROJECT_NAME} PRIVATE /usr/local/lib onnxruntime/lib onnxruntime/runtimes/win-x64/native)
include(cmake/FetchOnnxruntime.cmake)
target_link_libraries(${PROJECT_NAME} PRIVATE
${CMAKE_JS_LIB}
$<$<BOOL:${ONNXRUNTIME_PROVIDERS_CUDA_LIB}>:${ONNXRUNTIME_PROVIDERS_CUDA_LIB}>
${CUDA_LIBRARIES})
# Set the target properties
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
target_compile_definitions(${PROJECT_NAME} PRIVATE NAPI_CPP_EXCEPTIONS)