1+ #[============================================================================[
2+
3+ Authors: Federico Sossai (fsossai)
4+ Date: 2021/09/07
5+ Description: CMake script for finding the ONNXRuntime library.
6+ Usage: The user must provide the directory in which ONNXRuntime is installed
7+ together with the one in which it has been built by setting the
8+ following variables:
9+ ONNXRuntime_SRC (e.g. /home/repo/onnxruntime) [MADATORY]
10+ ONNXRuntime_BUILD (e.g. /home/repo/onnxruntime/build)
11+ If ONNXRuntime_BUILD is not set ${ONNXRuntime_SRC}/build is assumed
12+ as default value.
13+
14+ Result Variables
15+ ^^^^^^^^^^^^^^^^
16+
17+ This module defines the following variables::
18+
19+ ONNXRuntime_FOUND - True if ONNXRuntime was found
20+ ONNXRuntime_INCLUDE_DIRS - include directories for ONNXRuntime
21+ ONNXRuntime_LIBRARIES - link against this library to use ONNXRuntime
22+ ONNXRuntime_VERSION_STRING - Full version of ONNXRuntime (e.g. 1.8.0)
23+ ONNXRuntime_VERSION_MAJOR - The major version of the ONNXRuntime implementation
24+ ONNXRuntime_VERSION_MINOR - The minor version of the ONNXRuntime implementation
25+ ONNXRuntime_VERSION_MINOR - The patch version of the ONNXRuntime implementation
26+ ONNXRuntime_BUILD_TYPE - Describes whether the current build is
27+ - Debug, MinSizeRel Release or RelWithDebInfo
28+
29+
30+ The module will also define two cache variables::
31+
32+ ONNXRuntime_OS - Operating system that the library has been built for
33+ ONNXRuntime_INCLUDE_DIR - Identical to ONNXRuntime_INCLUDE_DIRS
34+ ONNXRuntime_LIBRARY - Identical to ONNXRuntime_LIBRARIES
35+
36+ #]============================================================================]
37+
38+ set (ONNXRuntime_SRC /home/fsossai/repo/onnxruntime) # debug
39+
40+ if (NOT ONNXRuntime_SRC)
41+ message (FATAL_ERROR "ONNXRuntime: please set ONNXRuntime_SRC" )
42+ endif ()
43+
44+ if (NOT ONNXRuntime_BUILD)
45+ set (ONNXRuntime_BUILD ${ONNXRuntime_SRC} /build )
46+ message (STATUS "Assuming ${ONNXRuntime_BUILD} as the build directory for ONNXRuntime" )
47+ endif ()
48+
49+ # Setting ONNXRuntime_OS
50+ set (all_os "Linux" "Windows" "MacOS" "iOS" "Android" )
51+ foreach (os ${all_os} )
52+ if (IS_DIRECTORY ${ONNXRuntime_BUILD} /${os} )
53+ set (ONNXRuntime_OS ${os} )
54+ break ()
55+ endif ()
56+ endforeach ()
57+
58+ if (NOT ONNXRuntime_OS)
59+ message (FATAL_ERROR "ONNXRuntime: no suitable operating system found in the build directory" )
60+ endif ()
61+
62+ # Setting ONNXRuntime_BUILD_TYPE
63+ set (all_types "Debug" "MinSizeRel" "Release" "RelWithDebInfo" )
64+ foreach (type ${all_types} )
65+ if (IS_DIRECTORY ${ONNXRuntime_BUILD} /${ONNXRuntime_OS} /${type} )
66+ set (ONNXRuntime_BUILD_TYPE ${type} )
67+ break ()
68+ endif ()
69+ endforeach ()
70+
71+ # Setting ONNXRuntime_LIBRARIES
72+ if (EXISTS ${ONNXRuntime_BUILD} /${ONNXRuntime_OS} /${ONNXRuntime_BUILD_TYPE} /libonnxruntime.so)
73+ set (ONNXRuntime_LIBRARIES ${ONNXRuntime_BUILD} /${ONNXRuntime_OS} /${ONNXRuntime_BUILD_TYPE} )
74+ set (ONNXRuntime_LIBRARY ${ONNXRuntime_LIBRARIES} )
75+
76+ # Setting ONNXRuntime_VERSION_*
77+ file (GLOB match REGEX "${ONNXRuntime_LIBRARIES} /libonnxruntime.so.*" )
78+ foreach (fname ${match} )
79+ get_filename_component (fname ${fname} NAME )
80+ string (REGEX MATCH "[0-9][0-9.]+" ONNXRuntime_VERSION_STRING ${fname} )
81+ string (REPLACE "." ";" version ${ONNXRuntime_VERSION_STRING} )
82+ list (LENGTH version version_length)
83+ if (${version_length} GREATER 2)
84+ list (GET version 0 ONNXRuntime_VERSION_MAJOR)
85+ list (GET version 1 ONNXRuntime_VERSION_MINOR)
86+ list (GET version 2 ONNXRuntime_VERSION_PATCH)
87+ break ()
88+ endif ()
89+ endforeach ()
90+ endif ()
91+
92+ # Setting ONNXRuntime_INCLUDE_DIRS
93+ if (IS_DIRECTORY ${ONNXRuntime_SRC} /include )
94+ set (ONNXRuntime_INCLUDE_DIRS ${ONNXRuntime_SRC} /include )
95+ set (ONNXRuntime_INCLUDE_DIR ${ONNXRuntime_INCLUDE_DIRS} )
96+ endif ()
97+
98+ # Setting
99+
100+ find_package_handle_standard_args(
101+ ONNXRuntime
102+ FOUND_VAR ONNXRuntime_FOUND
103+ REQUIRED_VARS ONNXRuntime_LIBRARIES ONNXRuntime_INCLUDE_DIRS
104+ VERSION_VAR OpenCL_VERSION_STRING)
0 commit comments