|
| 1 | +# Possible values for CMAKE_SYSTEM_NAME: Linux, Windows, Darwin |
| 2 | + |
| 3 | +message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") |
| 4 | +message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") |
| 5 | +message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}") |
| 6 | +message(STATUS "CMAKE_APPLE_SILICON_PROCESSOR : ${CMAKE_APPLE_SILICON_PROCESSOR}") |
| 7 | + |
| 8 | +if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) |
| 9 | + message(FATAL_ERROR "This file is for macOS only. Given: ${CMAKE_SYSTEM_NAME}") |
| 10 | +endif() |
| 11 | + |
| 12 | +if(BUILD_SHARED_LIBS) |
| 13 | + message(FATAL_ERROR "This file is for building static libraries. BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") |
| 14 | +endif() |
| 15 | + |
| 16 | +set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.16.0/onnxruntime-osx-universal2-static_lib-1.16.0.zip") |
| 17 | +set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/onnxruntime-libs/resolve/main/onnxruntime-osx-universal2-static_lib-1.16.0.zip") |
| 18 | +set(onnxruntime_HASH "SHA256=6df205fb519d311ff57131d35ed43374f4fe483eb665baa38bfbc00034595b35") |
| 19 | + |
| 20 | +# If you don't have access to the Internet, |
| 21 | +# please download onnxruntime to one of the following locations. |
| 22 | +# You can add more if you want. |
| 23 | +set(possible_file_locations |
| 24 | + $ENV{HOME}/Downloads/onnxruntime-osx-universal2-static_lib-1.16.0.zip |
| 25 | + ${PROJECT_SOURCE_DIR}/onnxruntime-osx-universal2-static_lib-1.16.0.zip |
| 26 | + ${PROJECT_BINARY_DIR}/onnxruntime-osx-universal2-static_lib-1.16.0.zip |
| 27 | + /tmp/onnxruntime-osx-universal2-static_lib-1.16.0.zip |
| 28 | +) |
| 29 | + |
| 30 | +foreach(f IN LISTS possible_file_locations) |
| 31 | + if(EXISTS ${f}) |
| 32 | + set(onnxruntime_URL "${f}") |
| 33 | + file(TO_CMAKE_PATH "${onnxruntime_URL}" onnxruntime_URL) |
| 34 | + message(STATUS "Found local downloaded onnxruntime: ${onnxruntime_URL}") |
| 35 | + set(onnxruntime_URL2) |
| 36 | + break() |
| 37 | + endif() |
| 38 | +endforeach() |
| 39 | + |
| 40 | +FetchContent_Declare(onnxruntime |
| 41 | + URL |
| 42 | + ${onnxruntime_URL} |
| 43 | + ${onnxruntime_URL2} |
| 44 | + URL_HASH ${onnxruntime_HASH} |
| 45 | +) |
| 46 | + |
| 47 | +FetchContent_GetProperties(onnxruntime) |
| 48 | +if(NOT onnxruntime_POPULATED) |
| 49 | + message(STATUS "Downloading onnxruntime from ${onnxruntime_URL}") |
| 50 | + FetchContent_Populate(onnxruntime) |
| 51 | +endif() |
| 52 | +message(STATUS "onnxruntime is downloaded to ${onnxruntime_SOURCE_DIR}") |
| 53 | + |
| 54 | +# for static libraries, we use onnxruntime_lib_files directly below |
| 55 | +include_directories(${onnxruntime_SOURCE_DIR}/include) |
| 56 | + |
| 57 | +file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/lib*.a") |
| 58 | + |
| 59 | +set(onnxruntime_lib_files ${onnxruntime_lib_files} PARENT_SCOPE) |
| 60 | + |
| 61 | +message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}") |
| 62 | +install(FILES ${onnxruntime_lib_files} DESTINATION lib) |
0 commit comments