Support linking onnxruntime statically for macOS (#403)
This commit is contained in:
61
cmake/onnxruntime-osx-arm64-static.cmake
Normal file
61
cmake/onnxruntime-osx-arm64-static.cmake
Normal file
@@ -0,0 +1,61 @@
|
||||
# Copyright (c) 2022-2023 Xiaomi Corporation
|
||||
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
|
||||
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}")
|
||||
message(STATUS "CMAKE_APPLE_SILICON_PROCESSOR : ${CMAKE_APPLE_SILICON_PROCESSOR}")
|
||||
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
message(FATAL_ERROR "This file is for macOS only. Given: ${CMAKE_SYSTEM_NAME}")
|
||||
endif()
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
message(FATAL_ERROR "This file is for building static libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
|
||||
endif()
|
||||
|
||||
set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-osx-arm64-static_lib-1.16.0.zip")
|
||||
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-osx-arm64-static_lib-1.16.0.zip")
|
||||
set(onnxruntime_HASH "SHA256=5f99c9a51d91e751ac20fcbb73dfa31a379438381c5357fd3f37bda816934e3e")
|
||||
|
||||
# If you don't have access to the Internet,
|
||||
# please download onnxruntime to one of the following locations.
|
||||
# You can add more if you want.
|
||||
set(possible_file_locations
|
||||
$ENV{HOME}/Downloads/onnxruntime-osx-arm64-static_lib-1.16.0.zip
|
||||
${PROJECT_SOURCE_DIR}/onnxruntime-osx-arm64-static_lib-1.16.0.zip
|
||||
${PROJECT_BINARY_DIR}/onnxruntime-osx-arm64-static_lib-1.16.0.zip
|
||||
/tmp/onnxruntime-osx-arm64-static_lib-1.16.0.zip
|
||||
)
|
||||
|
||||
foreach(f IN LISTS possible_file_locations)
|
||||
if(EXISTS ${f})
|
||||
set(onnxruntime_URL "${f}")
|
||||
file(TO_CMAKE_PATH "${onnxruntime_URL}" onnxruntime_URL)
|
||||
message(STATUS "Found local downloaded onnxruntime: ${onnxruntime_URL}")
|
||||
set(onnxruntime_URL2)
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
FetchContent_Declare(onnxruntime
|
||||
URL
|
||||
${onnxruntime_URL}
|
||||
${onnxruntime_URL2}
|
||||
URL_HASH ${onnxruntime_HASH}
|
||||
)
|
||||
|
||||
FetchContent_GetProperties(onnxruntime)
|
||||
if(NOT onnxruntime_POPULATED)
|
||||
message(STATUS "Downloading onnxruntime from ${onnxruntime_URL}")
|
||||
FetchContent_Populate(onnxruntime)
|
||||
endif()
|
||||
message(STATUS "onnxruntime is downloaded to ${onnxruntime_SOURCE_DIR}")
|
||||
|
||||
# for static libraries, we use onnxruntime_lib_files directly below
|
||||
include_directories(${onnxruntime_SOURCE_DIR}/include)
|
||||
|
||||
file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/lib*.a")
|
||||
|
||||
set(onnxruntime_lib_files ${onnxruntime_lib_files} PARENT_SCOPE)
|
||||
|
||||
message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}")
|
||||
install(FILES ${onnxruntime_lib_files} DESTINATION lib)
|
||||
@@ -8,6 +8,10 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
message(FATAL_ERROR "This file is for macOS only. Given: ${CMAKE_SYSTEM_NAME}")
|
||||
endif()
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
message(FATAL_ERROR "This file is for building shared libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
|
||||
endif()
|
||||
|
||||
set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-osx-arm64-1.16.0.tgz")
|
||||
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/onnxruntime-osx-arm64-1.16.0.tgz")
|
||||
set(onnxruntime_HASH "SHA256=fec3b70ca4f642a5c6d5c3a6f3a4eddd4c1b9281893fe2c7ae03a3086e20c316")
|
||||
|
||||
62
cmake/onnxruntime-osx-universal-static.cmake
Normal file
62
cmake/onnxruntime-osx-universal-static.cmake
Normal file
@@ -0,0 +1,62 @@
|
||||
# Possible values for CMAKE_SYSTEM_NAME: Linux, Windows, Darwin
|
||||
|
||||
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
|
||||
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}")
|
||||
message(STATUS "CMAKE_APPLE_SILICON_PROCESSOR : ${CMAKE_APPLE_SILICON_PROCESSOR}")
|
||||
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
message(FATAL_ERROR "This file is for macOS only. Given: ${CMAKE_SYSTEM_NAME}")
|
||||
endif()
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
message(FATAL_ERROR "This file is for building static libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
|
||||
endif()
|
||||
|
||||
set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-osx-universal2-static_lib-1.16.0.zip")
|
||||
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-osx-universal2-static_lib-1.16.0.zip")
|
||||
set(onnxruntime_HASH "SHA256=6df205fb519d311ff57131d35ed43374f4fe483eb665baa38bfbc00034595b35")
|
||||
|
||||
# If you don't have access to the Internet,
|
||||
# please download onnxruntime to one of the following locations.
|
||||
# You can add more if you want.
|
||||
set(possible_file_locations
|
||||
$ENV{HOME}/Downloads/onnxruntime-osx-universal2-static_lib-1.16.0.zip
|
||||
${PROJECT_SOURCE_DIR}/onnxruntime-osx-universal2-static_lib-1.16.0.zip
|
||||
${PROJECT_BINARY_DIR}/onnxruntime-osx-universal2-static_lib-1.16.0.zip
|
||||
/tmp/onnxruntime-osx-universal2-static_lib-1.16.0.zip
|
||||
)
|
||||
|
||||
foreach(f IN LISTS possible_file_locations)
|
||||
if(EXISTS ${f})
|
||||
set(onnxruntime_URL "${f}")
|
||||
file(TO_CMAKE_PATH "${onnxruntime_URL}" onnxruntime_URL)
|
||||
message(STATUS "Found local downloaded onnxruntime: ${onnxruntime_URL}")
|
||||
set(onnxruntime_URL2)
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
FetchContent_Declare(onnxruntime
|
||||
URL
|
||||
${onnxruntime_URL}
|
||||
${onnxruntime_URL2}
|
||||
URL_HASH ${onnxruntime_HASH}
|
||||
)
|
||||
|
||||
FetchContent_GetProperties(onnxruntime)
|
||||
if(NOT onnxruntime_POPULATED)
|
||||
message(STATUS "Downloading onnxruntime from ${onnxruntime_URL}")
|
||||
FetchContent_Populate(onnxruntime)
|
||||
endif()
|
||||
message(STATUS "onnxruntime is downloaded to ${onnxruntime_SOURCE_DIR}")
|
||||
|
||||
# for static libraries, we use onnxruntime_lib_files directly below
|
||||
include_directories(${onnxruntime_SOURCE_DIR}/include)
|
||||
|
||||
file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/lib*.a")
|
||||
|
||||
set(onnxruntime_lib_files ${onnxruntime_lib_files} PARENT_SCOPE)
|
||||
|
||||
message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}")
|
||||
install(FILES ${onnxruntime_lib_files} DESTINATION lib)
|
||||
@@ -9,6 +9,10 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
message(FATAL_ERROR "This file is for macOS only. Given: ${CMAKE_SYSTEM_NAME}")
|
||||
endif()
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
message(FATAL_ERROR "This file is for building shared libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
|
||||
endif()
|
||||
|
||||
set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-osx-universal2-1.16.0.tgz")
|
||||
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/onnxruntime-osx-universal2-1.16.0.tgz")
|
||||
set(onnxruntime_HASH "SHA256=e5b69ece634cf1cd5cf4b45ab478417199a5e8ab5775f6f12560e09dc5ef7749")
|
||||
|
||||
61
cmake/onnxruntime-osx-x86_64-static.cmake
Normal file
61
cmake/onnxruntime-osx-x86_64-static.cmake
Normal file
@@ -0,0 +1,61 @@
|
||||
# Copyright (c) 2022-2023 Xiaomi Corporation
|
||||
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
|
||||
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}")
|
||||
message(STATUS "CMAKE_APPLE_SILICON_PROCESSOR : ${CMAKE_APPLE_SILICON_PROCESSOR}")
|
||||
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
message(FATAL_ERROR "This file is for macOS only. Given: ${CMAKE_SYSTEM_NAME}")
|
||||
endif()
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
message(FATAL_ERROR "This file is for building static libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
|
||||
endif()
|
||||
|
||||
set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-osx-x86_64-static_lib-1.16.0.zip")
|
||||
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-osx-x86_64-static_lib-1.16.0.zip")
|
||||
set(onnxruntime_HASH "SHA256=1686a1b6778483371d29106d8c7300a8960e3db084ab84ac4f870b7685cf5259")
|
||||
|
||||
# If you don't have access to the Internet,
|
||||
# please download onnxruntime to one of the following locations.
|
||||
# You can add more if you want.
|
||||
set(possible_file_locations
|
||||
$ENV{HOME}/Downloads/onnxruntime-osx-x86_64-static_lib-1.16.0.zip
|
||||
${PROJECT_SOURCE_DIR}/onnxruntime-osx-x86_64-static_lib-1.16.0.zip
|
||||
${PROJECT_BINARY_DIR}/onnxruntime-osx-x86_64-static_lib-1.16.0.zip
|
||||
/tmp/onnxruntime-osx-x86_64-static_lib-1.16.0.zip
|
||||
)
|
||||
|
||||
foreach(f IN LISTS possible_file_locations)
|
||||
if(EXISTS ${f})
|
||||
set(onnxruntime_URL "${f}")
|
||||
file(TO_CMAKE_PATH "${onnxruntime_URL}" onnxruntime_URL)
|
||||
message(STATUS "Found local downloaded onnxruntime: ${onnxruntime_URL}")
|
||||
set(onnxruntime_URL2)
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
FetchContent_Declare(onnxruntime
|
||||
URL
|
||||
${onnxruntime_URL}
|
||||
${onnxruntime_URL2}
|
||||
URL_HASH ${onnxruntime_HASH}
|
||||
)
|
||||
|
||||
FetchContent_GetProperties(onnxruntime)
|
||||
if(NOT onnxruntime_POPULATED)
|
||||
message(STATUS "Downloading onnxruntime from ${onnxruntime_URL}")
|
||||
FetchContent_Populate(onnxruntime)
|
||||
endif()
|
||||
message(STATUS "onnxruntime is downloaded to ${onnxruntime_SOURCE_DIR}")
|
||||
|
||||
# for static libraries, we use onnxruntime_lib_files directly below
|
||||
include_directories(${onnxruntime_SOURCE_DIR}/include)
|
||||
|
||||
file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/lib*.a")
|
||||
|
||||
set(onnxruntime_lib_files ${onnxruntime_lib_files} PARENT_SCOPE)
|
||||
|
||||
message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}")
|
||||
install(FILES ${onnxruntime_lib_files} DESTINATION lib)
|
||||
@@ -8,6 +8,10 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
message(FATAL_ERROR "This file is for macOS only. Given: ${CMAKE_SYSTEM_NAME}")
|
||||
endif()
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
message(FATAL_ERROR "This file is for building shared libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
|
||||
endif()
|
||||
|
||||
set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-osx-x86_64-1.16.0.tgz")
|
||||
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/onnxruntime-osx-x86_64-1.16.0.tgz")
|
||||
set(onnxruntime_HASH "SHA256=3d639a269af4e97a455f23cff363a709ef3a5f3e086162e65e3395c339122285")
|
||||
|
||||
@@ -27,17 +27,37 @@ function(download_onnxruntime)
|
||||
endif()
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
if (arm64 IN_LIST CMAKE_OSX_ARCHITECTURES AND x86_64 IN_LIST CMAKE_OSX_ARCHITECTURES)
|
||||
include(onnxruntime-osx-universal)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
include(onnxruntime-osx-universal)
|
||||
else()
|
||||
include(onnxruntime-osx-universal-static)
|
||||
endif()
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 AND CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
|
||||
# cross compiling
|
||||
include(onnxruntime-osx-arm64)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
include(onnxruntime-osx-arm64)
|
||||
else()
|
||||
include(onnxruntime-osx-arm64-static)
|
||||
endif()
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm64 AND CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
|
||||
# cross compiling
|
||||
include(onnxruntime-osx-x86_64)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
include(onnxruntime-osx-x86_64)
|
||||
else()
|
||||
include(onnxruntime-osx-x86_64-static)
|
||||
endif()
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
|
||||
include(onnxruntime-osx-arm64)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
include(onnxruntime-osx-arm64)
|
||||
else()
|
||||
include(onnxruntime-osx-arm64-static)
|
||||
endif()
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
|
||||
include(onnxruntime-osx-x86_64)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
include(onnxruntime-osx-x86_64)
|
||||
else()
|
||||
include(onnxruntime-osx-x86_64-static)
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupport processor {CMAKE_SYSTEM_PROCESSOR} for Darwin")
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user