11#[============================================================================[
22
3- Authors: Federico Sossai (fsossai)
4- Date: 2021/09/07
3+ Author: Federico Sossai (fsossai), 2021
54Description: CMake script for finding the ONNXRuntime library.
65Usage: The user must provide the directory in which ONNXRuntime is installed
76 together with the one in which it has been built by setting the
@@ -36,68 +35,67 @@ The module will also define two cache variables::
3635#]============================================================================]
3736
3837
39- if (NOT ONNXRuntime_SRC)
40- message (FATAL_ERROR "ONNXRuntime: please set ONNXRuntime_SRC" )
41- endif ()
42-
43- if (NOT ONNXRuntime_BUILD)
44- set (ONNXRuntime_BUILD ${ONNXRuntime_SRC} /build )
45- message (STATUS "Assuming ${ONNXRuntime_BUILD} as the build directory for ONNXRuntime" )
46- endif ()
38+ if (ONNXRuntime_SRC)
4739
48- # Setting ONNXRuntime_OS
49- set (all_os "Linux" "Windows" "MacOS" "iOS" "Android" )
50- foreach (os ${all_os} )
51- if (IS_DIRECTORY ${ONNXRuntime_BUILD} /${os} )
52- set (ONNXRuntime_OS ${os} )
53- break ()
40+ if (NOT ONNXRuntime_BUILD)
41+ set (ONNXRuntime_BUILD ${ONNXRuntime_SRC} /build )
42+ message (STATUS "Assuming ${ONNXRuntime_BUILD} as the build directory for ONNXRuntime" )
5443 endif ()
55- endforeach ()
5644
57- if (NOT ONNXRuntime_OS)
58- message (FATAL_ERROR "ONNXRuntime: no suitable operating system found in the build directory" )
59- endif ()
45+ # Setting ONNXRuntime_OS
46+ set (all_os "Linux" "Windows" "MacOS" "iOS" "Android" )
47+ foreach (os ${all_os} )
48+ if (IS_DIRECTORY ${ONNXRuntime_BUILD} /${os} )
49+ set (ONNXRuntime_OS ${os} )
50+ break ()
51+ endif ()
52+ endforeach ()
6053
61- # Setting ONNXRuntime_BUILD_TYPE
62- set (all_types "Debug" "MinSizeRel" "Release" "RelWithDebInfo" )
63- foreach (type ${all_types} )
64- if (IS_DIRECTORY ${ONNXRuntime_BUILD} /${ONNXRuntime_OS} /${type} )
65- set (ONNXRuntime_BUILD_TYPE ${type} )
66- break ()
54+ if (NOT ONNXRuntime_OS)
55+ message (FATAL_ERROR "ONNXRuntime: no suitable operating system found in the build directory" )
6756 endif ()
68- endforeach ()
69-
70- # Setting ONNXRuntime_LIBRARIES
71- if (EXISTS ${ONNXRuntime_BUILD} /${ONNXRuntime_OS} /${ONNXRuntime_BUILD_TYPE} /libonnxruntime.so)
72- set (ONNXRuntime_LIBRARIES ${ONNXRuntime_BUILD} /${ONNXRuntime_OS} /${ONNXRuntime_BUILD_TYPE} )
73- set (ONNXRuntime_LIBRARY ${ONNXRuntime_LIBRARIES} )
74-
75- # Setting ONNXRuntime_VERSION_*
76- file (GLOB match REGEX "${ONNXRuntime_LIBRARIES} /libonnxruntime.so.*" )
77- foreach (fname ${match} )
78- get_filename_component (fname ${fname} NAME )
79- string (REGEX MATCH "[0-9][0-9.]+" ONNXRuntime_VERSION_STRING ${fname} )
80- string (REPLACE "." ";" version ${ONNXRuntime_VERSION_STRING} )
81- list (LENGTH version version_length)
82- if (${version_length} GREATER 2)
83- list (GET version 0 ONNXRuntime_VERSION_MAJOR)
84- list (GET version 1 ONNXRuntime_VERSION_MINOR)
85- list (GET version 2 ONNXRuntime_VERSION_PATCH)
57+
58+ # Setting ONNXRuntime_BUILD_TYPE
59+ set (all_types "Debug" "MinSizeRel" "Release" "RelWithDebInfo" )
60+ foreach (type ${all_types} )
61+ if (IS_DIRECTORY ${ONNXRuntime_BUILD} /${ONNXRuntime_OS} /${type} )
62+ set (ONNXRuntime_BUILD_TYPE ${type} )
8663 break ()
8764 endif ()
8865 endforeach ()
89- endif ()
9066
91- # Setting ONNXRuntime_INCLUDE_DIRS
92- if (IS_DIRECTORY ${ONNXRuntime_SRC} /include )
93- set (ONNXRuntime_INCLUDE_DIRS ${ONNXRuntime_SRC} /include )
94- set (ONNXRuntime_INCLUDE_DIR ${ONNXRuntime_INCLUDE_DIRS} )
95- endif ()
67+ # Setting ONNXRuntime_LIBRARIES
68+ if (EXISTS ${ONNXRuntime_BUILD} /${ONNXRuntime_OS} /${ONNXRuntime_BUILD_TYPE} /libonnxruntime.so)
69+ set (ONNXRuntime_LIBRARIES ${ONNXRuntime_BUILD} /${ONNXRuntime_OS} /${ONNXRuntime_BUILD_TYPE} )
70+ set (ONNXRuntime_LIBRARY ${ONNXRuntime_LIBRARIES} )
71+
72+ # Setting ONNXRuntime_VERSION_*
73+ file (GLOB match REGEX "${ONNXRuntime_LIBRARIES} /libonnxruntime.so.*" )
74+ foreach (fname ${match} )
75+ get_filename_component (fname ${fname} NAME )
76+ string (REGEX MATCH "[0-9][0-9.]+" ONNXRuntime_VERSION_STRING ${fname} )
77+ string (REPLACE "." ";" version ${ONNXRuntime_VERSION_STRING} )
78+ list (LENGTH version version_length)
79+ if (${version_length} GREATER 2)
80+ list (GET version 0 ONNXRuntime_VERSION_MAJOR)
81+ list (GET version 1 ONNXRuntime_VERSION_MINOR)
82+ list (GET version 2 ONNXRuntime_VERSION_PATCH)
83+ break ()
84+ endif ()
85+ endforeach ()
86+ endif ()
9687
97- # Setting
88+ # Setting ONNXRuntime_INCLUDE_DIRS
89+ if (IS_DIRECTORY ${ONNXRuntime_SRC} /include )
90+ set (ONNXRuntime_INCLUDE_DIRS ${ONNXRuntime_SRC} /include )
91+ set (ONNXRuntime_INCLUDE_DIR ${ONNXRuntime_INCLUDE_DIRS} )
92+ endif ()
93+
94+ endif ()
9895
9996find_package_handle_standard_args(
10097 ONNXRuntime
10198 FOUND_VAR ONNXRuntime_FOUND
10299 REQUIRED_VARS ONNXRuntime_LIBRARIES ONNXRuntime_INCLUDE_DIRS
103- VERSION_VAR OpenCL_VERSION_STRING)
100+ VERSION_VAR ONNXRuntime_VERSION_STRING
101+ )
0 commit comments