@@ -19,6 +19,16 @@ set(CMAKE_AUTOUIC ON)
1919add_custom_target (build -time-make-directory ALL
2020 COMMAND ${CMAKE_COMMAND} -E make_directory Assembly/)
2121
22+ # Find repo root folder path
23+ string (FIND "${CMAKE_CURRENT_SOURCE_DIR} " "Arduino-Source-Internal" internal_repro_position) # determine if this is an internal repo
24+ if (internal_repro_position EQUAL -1) # no "Arduino-Source-Internal" substr in the current source dir
25+ # we are building the public repo
26+ set (REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR} /../" )
27+ else ()
28+ # we are building the internal repo
29+ set (REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR} /../../../" )
30+ endif ()
31+
2232#Find threads library
2333set (THREADS_PREFER_PTHREAD_FLAG ON )
2434find_package (Threads REQUIRED)
@@ -2402,14 +2412,7 @@ if (APPLE)
24022412
24032413 # make sure Packages repo, https://github.com/PokemonAutomation/Packages is placed in the same folder as this Arduino-Source repo
24042414 # so the post-build command can copy the resources folder Packages/SerialPrograms/Resources/ into the built app bundle:
2405- string (FIND "${CMAKE_CURRENT_SOURCE_DIR} " "Arduino-Source-Internal" internal_repro_position) # determine if this is an internal repo
2406- if (internal_repro_position EQUAL -1) # no "Arduino-Source-Internal" substr in the current source dir
2407- # we are building the public repo
2408- set (RESOURCES_PATH "${CMAKE_CURRENT_SOURCE_DIR} /../../Packages/SerialPrograms/Resources" )
2409- else ()
2410- # we are building the internal repo
2411- set (RESOURCES_PATH "${CMAKE_CURRENT_SOURCE_DIR} /../../../../Packages/SerialPrograms/Resources" )
2412- endif ()
2415+ set (RESOURCES_PATH "${REPO_ROOT_DIR} ../Packages/SerialPrograms/Resources" )
24132416 message (STATUS "Set Resources folder path from Packages repo: ${RESOURCES_PATH} " )
24142417 add_custom_command (
24152418 TARGET SerialPrograms
@@ -2551,9 +2554,25 @@ else() # macOS and Linux
25512554 # Save the root path as CMake variable HOMEBREW_PREFIX.
25522555 execute_process (COMMAND brew --prefix OUTPUT_VARIABLE HOMEBREW_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
25532556
2554- # Get ONNX Runtime paths
2555- target_include_directories (SerialPrograms PRIVATE ${HOMEBREW_PREFIX} /include /onnxruntime)
2556- target_link_libraries (SerialPrograms PRIVATE ${HOMEBREW_PREFIX} /lib/libonnxruntime.dylib)
2557+ # ==== Get ONNX Runtime paths ====
2558+ # First, try to see if there is an ONNX Runtime library built from source.
2559+ # Assume the onnxruntime repo, https://github.com/microsoft/onnxruntime is placed in the same folder as
2560+ # this Arduino-Source repo:
2561+ set (ONNXRUNTIME_ROOTDIR "${REPO_ROOT_DIR} ../onnxruntime/" )
2562+ set (ONNXRUNTIME_HEADER_DIR "${ONNXRUNTIME_ROOTDIR} include/onnxruntime/core/session/" )
2563+ if (EXISTS "${ONNXRUNTIME_HEADER_DIR} " )
2564+ # we have ONNX Runtime built from source
2565+ message ("Use ONNX Runtime built from source at ${ONNXRUNTIME_ROOTDIR} " )
2566+ target_include_directories (SerialPrograms PRIVATE ${ONNXRUNTIME_HEADER_DIR} )
2567+ link_directories (SerialPrograms PRIVATE ${ONNXRUNTIME_ROOTDIR} /build /MacOS/Release)
2568+ target_link_libraries (SerialPrograms PRIVATE ${ONNXRUNTIME_ROOTDIR} /build /MacOS/Release/libonnxruntime.dylib)
2569+ else ()
2570+ message ("Built-from-source ONNX Runtime folder ${ONNXRUNTIME_ROOTDIR} does not exist." )
2571+ message ("Use ONNX Runtime installed by Homebrew." )
2572+ target_include_directories (SerialPrograms PRIVATE ${HOMEBREW_PREFIX} /include /onnxruntime)
2573+ target_link_libraries (SerialPrograms PRIVATE ${HOMEBREW_PREFIX} /lib/libonnxruntime.dylib)
2574+ endif ()
2575+
25572576 else () # Linux
25582577 # Instructions took from https://github.com/microsoft/onnxruntime/discussions/6489
25592578 # Step 1: Download the file
0 commit comments