Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
151 lines (134 loc) · 5.82 KB
/
Copy pathCMakeLists.txt
File metadata and controls
151 lines (134 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
cmake_minimum_required(VERSION 3.19)
# 0.1.0.0 is the first version to carry the Level 1 contract surface. otter makes no ABI promise
# before 1.0; see README, "Versioning and ABI".
project(otter
VERSION 0.1.0.0
LANGUAGES CXX
DESCRIPTION "Orchestratable Transcription, Timing and Expression Runtime"
HOMEPAGE_URL "https://github.com/diffscope/otter"
)
# ----------------------------------
# Build Options
# ----------------------------------
option(OTTER_BUILD_TESTS "Build test cases" OFF)
option(OTTER_INSTALL "Install library" ON)
# ----------------------------------
# CMake Settings
# ----------------------------------
if(MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /manifest:no")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /manifest:no")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /manifest:no")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "d")
endif()
elseif(MINGW)
set(CMAKE_STATIC_LIBRARY_PREFIX "")
set(CMAKE_SHARED_LIBRARY_PREFIX "")
elseif(WIN32)
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "d")
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
if(OTTER_INSTALL)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
endif()
# ----------------------------------
# Project Variables
# ----------------------------------
set(OTTER_INSTALL_NAME ${PROJECT_NAME})
set(OTTER_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# ----------------------------------
# Find basic dependencies
# ----------------------------------
find_package(qmsetup REQUIRED)
qm_import(Filesystem)
if(NOT DEFINED QMSETUP_BUILD_DIR)
set(QMSETUP_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/out")
endif()
qm_init_directories()
find_package(synthrt CONFIG REQUIRED)
# ----------------------------------
# Optional inference backend
# ----------------------------------
# The analysis providers run their models through the dsinfer driver framework. synthrt[onnx]
# builds dsinfer and installs its CMake package beside the synthrt package, so find_package locates
# it without further configuration. The library does not depend on dsinfer: the contract headers
# and the executive abstraction depend only on synthrt. Only the providers depend on dsinfer, and
# OTTER_DISABLE_DSINFER excludes them even if dsinfer is installed, which produces the minimal
# build.
option(OTTER_DISABLE_DSINFER "Build without dsinfer even if it is installed" OFF)
if(NOT OTTER_DISABLE_DSINFER)
find_package(dsinfer CONFIG QUIET)
endif()
if(TARGET dsinfer::dsinfer)
set(OTTER_HAS_DSINFER ON)
# The ONNX driver is installed as a plugin under lib/plugins/dsinfer beside the library, not
# as a link target. The dsinfer package reports the location of that tree in
# DSINFER_PLUGINS_DIR. For an older package without that variable, the tree is searched for
# above the config file, which is share/dsinfer in a vcpkg tree and lib/cmake/dsinfer in a
# plain install. The location is not derived from the library path, because Windows installs
# the library under bin while the plugin tree remains under lib. A vcpkg tree keeps its Debug
# build under debug/, which a multi-configuration generator selects per build, so that part of
# the path is a generator expression. A plugin search path contains one subdirectory per
# plugin, so the result is the parent of the onnx directory. Tests pass it to the driver
# factory at run time.
set(_otter_dsinfer_plugins "")
if(DEFINED DSINFER_PLUGINS_DIR AND IS_DIRECTORY "${DSINFER_PLUGINS_DIR}")
set(_otter_dsinfer_plugins "${DSINFER_PLUGINS_DIR}")
else()
set(_otter_dsinfer_prefix "${dsinfer_DIR}")
foreach(_step RANGE 3)
get_filename_component(_otter_dsinfer_prefix "${_otter_dsinfer_prefix}" DIRECTORY)
if(IS_DIRECTORY "${_otter_dsinfer_prefix}/lib/plugins/dsinfer")
set(_otter_dsinfer_plugins "${_otter_dsinfer_prefix}/lib/plugins/dsinfer")
break()
endif()
endforeach()
endif()
set(OTTER_DSINFER_DRIVER_DIR "")
if(_otter_dsinfer_plugins)
get_filename_component(_otter_dsinfer_prefix "${_otter_dsinfer_plugins}/../../.." ABSOLUTE)
if(IS_DIRECTORY "${_otter_dsinfer_prefix}/debug/lib/plugins/dsinfer")
set(OTTER_DSINFER_DRIVER_DIR
"${_otter_dsinfer_prefix}/$<$<CONFIG:Debug>:debug/>lib/plugins/dsinfer/inferencedrivers")
else()
set(OTTER_DSINFER_DRIVER_DIR "${_otter_dsinfer_plugins}/inferencedrivers")
endif()
else()
message(WARNING "dsinfer was found but its plugin tree was not; the model tests will "
"be skipped because no driver is available")
endif()
message(STATUS "dsinfer: ${dsinfer_DIR}")
else()
set(OTTER_HAS_DSINFER OFF)
if(OTTER_DISABLE_DSINFER)
message(STATUS "dsinfer: disabled; no analysis provider will be built")
else()
message(STATUS "dsinfer: not found; no analysis provider will be built "
"(install synthrt with the onnx feature to enable them)")
endif()
endif()
# Directory of the deployed ONNX Runtime binaries, which tests pass to the driver. The driver loads
# the library at run time, so the value is a directory and not a link target.
find_package(onnxruntime-builds CONFIG QUIET)
if(onnxruntime-builds_FOUND)
set(OTTER_ONNXRUNTIME_DIR "${ONNXRUNTIME_BUILDS_RUNTIME_DIR}")
message(STATUS "ONNX Runtime: ${OTTER_ONNXRUNTIME_DIR}")
else()
set(OTTER_ONNXRUNTIME_DIR "")
endif()
# ----------------------------------
# Tests
# ----------------------------------
if(OTTER_BUILD_TESTS)
enable_testing()
endif()
# ----------------------------------
# Add source modules
# ----------------------------------
add_subdirectory(src)