Skip to content

Commit 50add3b

Browse files
committed
Cleanup in cmake
1 parent 728ba86 commit 50add3b

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/cpp/CMakeLists.txt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,39 @@ include(FetchContent)
1212
FetchContent_Declare(json GIT_REPOSITORY https://github.com/nlohmann/json.git
1313
GIT_TAG d41ca94fa85d5119852e2f7a3f94335cc7cb0486 # PR #4709, fixes cmake deprecation warnings
1414
)
15-
FetchContent_Declare(
16-
onnxrt
17-
URL https://github.com/microsoft/onnxruntime/releases/download/v1.22.0/onnxruntime-linux-x64-1.22.0.tgz
18-
URL_HASH MD5=2b3a728a057226a3d6577335604db9bc
19-
)
20-
2115
FetchContent_MakeAvailable(json)
22-
FetchContent_MakeAvailable(onnxrt)
16+
17+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
18+
FetchContent_Declare(
19+
onnxrt
20+
URL https://github.com/microsoft/onnxruntime/releases/download/v1.22.0/onnxruntime-linux-x64-1.22.0.tgz
21+
URL_HASH MD5=2b3a728a057226a3d6577335604db9bc
22+
)
23+
FetchContent_MakeAvailable(onnxrt)
24+
25+
# fixes onnxrt cmake disabilities
26+
set(ONNXRUNTIME_ROOTDIR ${CMAKE_BINARY_DIR}/_deps/onnxrt-src)
27+
file(CREATE_LINK "${ONNXRUNTIME_ROOTDIR}/lib" "${ONNXRUNTIME_ROOTDIR}/lib64" SYMBOLIC)
28+
file(CREATE_LINK "${ONNXRUNTIME_ROOTDIR}/include" "${ONNXRUNTIME_ROOTDIR}/include/onnxruntime" SYMBOLIC)
29+
list(APPEND CMAKE_PREFIX_PATH "${ONNXRUNTIME_ROOTDIR}/lib/cmake")
30+
else()
31+
message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}. Only Linux is supported at the moment.")
32+
endif()
2333

2434

2535
find_package(OpenCV REQUIRED COMPONENTS core imgproc)
2636

2737
find_package(OpenVINO REQUIRED
2838
COMPONENTS Runtime Threading)
2939

40+
find_package(onnxruntime REQUIRED)
41+
3042
file(GLOB TASK_SOURCES src/tasks/**/*.cpp)
3143
file(GLOB TASKS_SOURCES src/tasks/*.cpp)
3244
file(GLOB UTILS_SOURCES src/utils/*.cpp)
3345
file(GLOB ADAPTERS_SOURCES src/adapters/*.cpp)
3446

3547
add_library(model_api STATIC ${TASK_SOURCES} ${TASKS_SOURCES} ${UTILS_SOURCES} ${ADAPTERS_SOURCES} ${TILERS_SOURCES})
3648

37-
target_link_libraries(model_api PUBLIC openvino::runtime opencv_core opencv_imgproc PRIVATE nlohmann_json::nlohmann_json)
49+
target_link_libraries(model_api PUBLIC openvino::runtime opencv_core opencv_imgproc PRIVATE nlohmann_json::nlohmann_json onnxruntime::onnxruntime)
3850
target_include_directories(model_api PUBLIC ${PROJECT_SOURCE_DIR}/include)
39-
40-
# onnxrt doesn't have a working CMake config, set the related directories manually
41-
set(ONNXRUNTIME_ROOTDIR ${CMAKE_BINARY_DIR}/_deps/onnxrt-src)
42-
43-
target_include_directories(model_api PUBLIC ${ONNXRUNTIME_ROOTDIR}/include)
44-
45-
target_link_directories(model_api PUBLIC "${ONNXRUNTIME_ROOTDIR}/lib")
46-
target_link_libraries(model_api PUBLIC libonnxruntime.so)

0 commit comments

Comments
 (0)