@@ -343,26 +343,25 @@ if (WIN32)
343343else () # macOS and Linux
344344 find_package (PkgConfig REQUIRED ) # required to execute `pkg_search_module()` below
345345 if (APPLE )
346- # prepare onnxruntime if needed
347- set (ONNXRUNTIME_VERSION "1.23.2" )
348- set (ONNXRUNTIME_WORK_DIR "${REPO_ROOT_DIR} /3rdPartyBinaries" )
349- if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" )
350- set (ONNXRUNTIME_ARCH "arm64" )
346+ # ==== Get ONNX Runtime paths ====
347+ # First, try to see if there is an ONNX Runtime library built from source.
348+ # Assume the onnxruntime repo, https://github.com/microsoft/onnxruntime is placed in the same folder as
349+ # this Arduino-Source repo:
350+ set (ONNXRUNTIME_ROOTDIR "${REPO_ROOT_DIR} ../onnxruntime/" )
351+ set (ONNXRUNTIME_HEADER_DIR "${ONNXRUNTIME_ROOTDIR} include/onnxruntime/core/session/" )
352+ if (EXISTS "${ONNXRUNTIME_HEADER_DIR} " )
353+ # we have ONNX Runtime built from source
354+ message ("Use ONNX Runtime built from source at ${ONNXRUNTIME_ROOTDIR} " )
355+ target_include_directories (SerialProgramsLib PRIVATE ${ONNXRUNTIME_HEADER_DIR} )
356+ target_link_libraries (SerialProgramsLib PRIVATE ${ONNXRUNTIME_ROOTDIR} /build/MacOS/Release/libonnxruntime.dylib )
351357 else ()
352- set (ONNXRUNTIME_ARCH "x86_64" )
358+ message ("Built-from-source ONNX Runtime folder ${ONNXRUNTIME_ROOTDIR} does not exist." )
359+ message ("Use ONNX Runtime installed by Homebrew." )
360+ pkg_search_module (ONNXRUNTIME REQUIRED libonnxruntime onnxruntime )
361+ target_include_directories (SerialProgramsLib PRIVATE ${ONNXRUNTIME_INCLUDE_DIRS} )
362+ target_link_directories (SerialProgramsLib PUBLIC ${ONNXRUNTIME_LIBRARY_DIRS} )
363+ target_link_libraries (SerialProgramsLib PUBLIC ${ONNXRUNTIME_LINK_LIBRARIES} )
353364 endif ()
354- set (ONNXRUNTIME_LIB_DIR "${ONNXRUNTIME_WORK_DIR} /onnxruntime-osx-${ONNXRUNTIME_ARCH} -${ONNXRUNTIME_VERSION} " )
355- set (ONNXRUNTIME_LIB_TAR "${ONNXRUNTIME_LIB_DIR} .tgz" )
356- set (ONNXRUNTIME_DYLIB "${ONNXRUNTIME_LIB_DIR} /lib/libonnxruntime.dylib" )
357- if (NOT EXISTS "${ONNXRUNTIME_LIB_DIR} " )
358- message (STATUS "ONNXRUNTIME not found, extracting from tgz..." )
359- execute_process (
360- COMMAND ${CMAKE_COMMAND} -E tar xf "${ONNXRUNTIME_LIB_TAR} "
361- WORKING_DIRECTORY "${ONNXRUNTIME_WORK_DIR} "
362- )
363- endif ()
364- target_include_directories (SerialProgramsLib SYSTEM PRIVATE "${ONNXRUNTIME_LIB_DIR} /include" )
365- target_link_libraries (SerialProgramsLib PRIVATE "${ONNXRUNTIME_DYLIB} " )
366365 else () # Linux
367366 # ONNX RUNTIME LINUX CONFIG
368367 # NOTE: users can specify their own ONNX_ROOT_PATH (this is the base folder for ONNX) on the command line when evoking cmake.
@@ -506,7 +505,7 @@ else() # macOS and Linux
506505 target_compile_options (SerialProgramsLib PRIVATE -Wall -Wextra -Wpedantic -Werror -fno-strict-aliasing )
507506 endif ()
508507
509- if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" )
508+ IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" )
510509 # Arm CPU
511510 # Run-time ISA dispatching
512511 target_compile_definitions (SerialProgramsLib PRIVATE PA_AutoDispatch_arm64_20_M1 )
0 commit comments