Allow to not use pre-installed onnxruntime libs. (#636)
This commit is contained in:
@@ -117,67 +117,69 @@ function(download_onnxruntime)
|
||||
set(onnxruntime_SOURCE_DIR ${onnxruntime_SOURCE_DIR} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# First, we try to locate the header and the lib if the use has already
|
||||
# installed onnxruntime. Otherwise, we will download the pre-compiled lib
|
||||
if(SHERPA_ONNX_USE_PRE_INSTALLED_ONNXRUNTIME_IF_AVAILABLE)
|
||||
# First, we try to locate the header and the lib if the user has already
|
||||
# installed onnxruntime. Otherwise, we will download the pre-compiled lib
|
||||
|
||||
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
|
||||
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
|
||||
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
|
||||
if(DEFINED ENV{SHERPA_ONNXRUNTIME_INCLUDE_DIR})
|
||||
set(location_onnxruntime_header_dir $ENV{SHERPA_ONNXRUNTIME_INCLUDE_DIR})
|
||||
if(DEFINED ENV{SHERPA_ONNXRUNTIME_INCLUDE_DIR})
|
||||
set(location_onnxruntime_header_dir $ENV{SHERPA_ONNXRUNTIME_INCLUDE_DIR})
|
||||
|
||||
include_directories(${location_onnxruntime_header_dir})
|
||||
else()
|
||||
find_path(location_onnxruntime_header_dir onnxruntime_cxx_api.h
|
||||
PATHS
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
)
|
||||
endif()
|
||||
|
||||
message(STATUS "location_onnxruntime_header_dir: ${location_onnxruntime_header_dir}")
|
||||
|
||||
if(DEFINED ENV{SHERPA_ONNXRUNTIME_LIB_DIR})
|
||||
if(APPLE)
|
||||
set(location_onnxruntime_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime.dylib)
|
||||
include_directories(${location_onnxruntime_header_dir})
|
||||
else()
|
||||
set(location_onnxruntime_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime.so)
|
||||
find_path(location_onnxruntime_header_dir onnxruntime_cxx_api.h
|
||||
PATHS
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
)
|
||||
endif()
|
||||
if(NOT EXISTS ${location_onnxruntime_lib})
|
||||
set(location_onnxruntime_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime.a)
|
||||
if(NOT EXISTS ${location_onnxruntime_lib})
|
||||
message(FATAL_ERROR "${location_onnxruntime_lib} cannot be found")
|
||||
endif()
|
||||
set(onnxruntime_lib_files $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime.a)
|
||||
message("Use static lib: ${onnxruntime_lib_files}")
|
||||
endif()
|
||||
if(SHERPA_ONNX_ENABLE_GPU)
|
||||
set(location_onnxruntime_cuda_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime_providers_cuda.so)
|
||||
if(NOT EXISTS ${location_onnxruntime_cuda_lib})
|
||||
set(location_onnxruntime_cuda_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime_providers_cuda.a)
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
find_library(location_onnxruntime_lib onnxruntime
|
||||
PATHS
|
||||
/lib
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
)
|
||||
|
||||
if(SHERPA_ONNX_ENABLE_GPU)
|
||||
find_library(location_onnxruntime_cuda_lib onnxruntime_providers_cuda
|
||||
message(STATUS "location_onnxruntime_header_dir: ${location_onnxruntime_header_dir}")
|
||||
|
||||
if(DEFINED ENV{SHERPA_ONNXRUNTIME_LIB_DIR})
|
||||
if(APPLE)
|
||||
set(location_onnxruntime_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime.dylib)
|
||||
else()
|
||||
set(location_onnxruntime_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime.so)
|
||||
endif()
|
||||
if(NOT EXISTS ${location_onnxruntime_lib})
|
||||
set(location_onnxruntime_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime.a)
|
||||
if(NOT EXISTS ${location_onnxruntime_lib})
|
||||
message(FATAL_ERROR "${location_onnxruntime_lib} cannot be found")
|
||||
endif()
|
||||
set(onnxruntime_lib_files $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime.a)
|
||||
message("Use static lib: ${onnxruntime_lib_files}")
|
||||
endif()
|
||||
if(SHERPA_ONNX_ENABLE_GPU)
|
||||
set(location_onnxruntime_cuda_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime_providers_cuda.so)
|
||||
if(NOT EXISTS ${location_onnxruntime_cuda_lib})
|
||||
set(location_onnxruntime_cuda_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime_providers_cuda.a)
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
find_library(location_onnxruntime_lib onnxruntime
|
||||
PATHS
|
||||
/lib
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(STATUS "location_onnxruntime_lib: ${location_onnxruntime_lib}")
|
||||
if(SHERPA_ONNX_ENABLE_GPU)
|
||||
message(STATUS "location_onnxruntime_cuda_lib: ${location_onnxruntime_cuda_lib}")
|
||||
if(SHERPA_ONNX_ENABLE_GPU)
|
||||
find_library(location_onnxruntime_cuda_lib onnxruntime_providers_cuda
|
||||
PATHS
|
||||
/lib
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(STATUS "location_onnxruntime_lib: ${location_onnxruntime_lib}")
|
||||
if(SHERPA_ONNX_ENABLE_GPU)
|
||||
message(STATUS "location_onnxruntime_cuda_lib: ${location_onnxruntime_cuda_lib}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(location_onnxruntime_header_dir AND location_onnxruntime_lib)
|
||||
@@ -195,6 +197,10 @@ if(location_onnxruntime_header_dir AND location_onnxruntime_lib)
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Could not find a pre-installed onnxruntime. Downloading pre-compiled onnxruntime")
|
||||
if(SHERPA_ONNX_USE_PRE_INSTALLED_ONNXRUNTIME_IF_AVAILABLE)
|
||||
message(STATUS "Could not find a pre-installed onnxruntime.")
|
||||
endif()
|
||||
message(STATUS "Downloading pre-compiled onnxruntime")
|
||||
|
||||
download_onnxruntime()
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user