You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.4 KiB
72 lines
2.4 KiB
cmake_minimum_required(VERSION 3.5)
|
|
|
|
set(PROJECT_NAME Yolov8OnnxRuntimeCPPInference)
|
|
project(${PROJECT_NAME} VERSION 0.0.1 LANGUAGES CXX)
|
|
|
|
|
|
# -------------- Support C++17 for using filesystem ------------------#
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS ON)
|
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
|
|
|
|
# OpenCV
|
|
find_package(OpenCV REQUIRED)
|
|
include_directories(${OpenCV_INCLUDE_DIRS})
|
|
|
|
|
|
|
|
# ONNXRUNTIME
|
|
|
|
# Set ONNXRUNTIME_VERSION
|
|
set(ONNXRUNTIME_VERSION 1.15.1)
|
|
|
|
if(WIN32)
|
|
# CPU
|
|
# set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/onnxruntime-win-x64-${ONNXRUNTIME_VERSION}")
|
|
# GPU
|
|
set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/onnxruntime-win-x64-gpu-${ONNXRUNTIME_VERSION}")
|
|
elseif(LINUX)
|
|
# CPU
|
|
# set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/onnxruntime-linux-x64-${ONNXRUNTIME_VERSION}")
|
|
# GPU
|
|
set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VERSION}")
|
|
elseif(APPLE)
|
|
set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/onnxruntime-osx-arm64-${ONNXRUNTIME_VERSION}")
|
|
# Apple X64 binary
|
|
# set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/onnxruntime-osx-x64-${ONNXRUNTIME_VERSION}")
|
|
# Apple Universal binary
|
|
# set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/onnxruntime-osx-universal2-${ONNXRUNTIME_VERSION}")
|
|
endif()
|
|
|
|
include_directories(${PROJECT_NAME} ${ONNXRUNTIME_ROOT}/include)
|
|
|
|
set(PROJECT_SOURCES
|
|
main.cpp
|
|
inference.h
|
|
inference.cpp
|
|
)
|
|
|
|
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
|
|
|
|
if(WIN32)
|
|
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${ONNXRUNTIME_ROOT}/lib/onnxruntime.lib)
|
|
elseif(LINUX)
|
|
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${ONNXRUNTIME_ROOT}/lib/libonnxruntime.so)
|
|
elseif(APPLE)
|
|
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${ONNXRUNTIME_ROOT}/lib/libonnxruntime.dylib)
|
|
endif()
|
|
|
|
# For windows system, copy onnxruntime.dll to the same folder of the executable file
|
|
if(WIN32)
|
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
"${ONNXRUNTIME_ROOT}/lib/onnxruntime.dll"
|
|
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
|
|
endif()
|
|
|
|
# Download https://raw.githubusercontent.com/ultralytics/ultralytics/main/ultralytics/cfg/datasets/coco.yaml
|
|
# and put it in the same folder of the executable file
|
|
configure_file(coco.yaml ${CMAKE_CURRENT_BINARY_DIR}/coco.yaml COPYONLY)
|