The open source OpenXR runtime
1# Copyright 2021-2022, Collabora, Ltd.
2#
3# SPDX-License-Identifier: BSL-1.0
4#
5# Distributed under the Boost Software License, Version 1.0.
6# (See accompanying file LICENSE_1_0.txt or copy at
7# http://www.boost.org/LICENSE_1_0.txt)
8#
9# Original Author:
10# 2021 Moshi Turner <moshiturner@protonmail.com>
11# 2021 Rylie Pavlik <rylie.pavlik@collabora.com>
12
13#.rst:
14# FindONNXRuntime
15# ---------------
16#
17# Find the ONNX runtime
18#
19# Targets
20# ^^^^^^^
21#
22# If successful, the following import target is created.
23#
24# ``ONNXRuntime::ONNXRuntime``
25#
26# Cache variables
27# ^^^^^^^^^^^^^^^
28#
29# The following cache variable may also be set to assist/control the operation of this module:
30#
31# ``ONNXRuntime_ROOT_DIR``
32# The root to search for ONNX runtime.
33#
34
35include(FeatureSummary)
36set_package_properties(
37 ONNXRuntime PROPERTIES
38 URL "https://onnxruntime.ai/"
39 DESCRIPTION "Machine learning runtime")
40
41set(ONNXRuntime_ROOT_DIR
42 "${ONNXRuntime_ROOT_DIR}"
43 CACHE PATH "Root to search for ONNXRuntime")
44
45find_package(PkgConfig)
46pkg_check_modules(PC_ONNXRuntime QUIET libonnxruntime)
47
48find_library(
49 ONNXRuntime_LIBRARY
50 NAMES onnxruntime
51 PATHS ${ONNXRuntime_ROOT_DIR}
52 PATH_SUFFIXES lib
53 HINTS ${PC_ONNXRuntime_LIBRARY_DIRS})
54find_path(
55 ONNXRuntime_INCLUDE_DIR onnxruntime_cxx_api.h
56 PATHS ${ONNXRuntime_ROOT_DIR}
57 PATH_SUFFIXES onnxruntime include include/onnxruntime onnxruntime/core/session
58 include/onnxruntime/core/session
59 HINTS ${PC_ONNXRuntime_INCLUDE_DIRS})
60
61include(FindPackageHandleStandardArgs)
62find_package_handle_standard_args(
63 ONNXRuntime REQUIRED_VARS ONNXRuntime_INCLUDE_DIR ONNXRuntime_LIBRARY)
64
65if(ONNXRuntime_FOUND)
66 set(ONNXRuntime_INCLUDE_DIRS ${ONNXRuntime_INCLUDE_DIR})
67 set(ONNXRuntime_LIBRARIES "${ONNXRuntime_LIBRARY}")
68 if(NOT TARGET ONNXRuntime::ONNXRuntime)
69 add_library(ONNXRuntime::ONNXRuntime UNKNOWN IMPORTED)
70 endif()
71 set_target_properties(
72 ONNXRuntime::ONNXRuntime PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
73 "${ONNXRuntime_INCLUDE_DIRS}")
74 set_target_properties(
75 ONNXRuntime::ONNXRuntime
76 PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
77 IMPORTED_LOCATION "${ONNXRuntime_LIBRARY}")
78 mark_as_advanced(ONNXRuntime_INCLUDE_DIRS ONNXRuntime_LIBRARY)
79endif()
80
81mark_as_advanced(ONNXRuntime_ROOT_DIR)