-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
203 lines (181 loc) · 7.54 KB
/
Copy pathCMakeLists.txt
File metadata and controls
203 lines (181 loc) · 7.54 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# ____ _ _
# | _ \| |_ _ __ _(_)_ __
# | |_) | | | | |/ _` | | '_ \
# | __/| | |_| | (_| | | | | |
# |_| |_|\__,_|\__, |_|_| |_|
# |___/
# A Template for Hpe2dPlugin, a Source Plugin
# Generated by the command: plugin -t source -d ../hpe2D -i /Users/p4010/MADS hpe2D
# Hostname: Fram-IV.local
# Current working directory: /Users/p4010/Develop/plugin_hpe
# Creation date: 2024-07-29T14:29:07.609+0200
# NOTICE: MADS Version 1.0.0
cmake_minimum_required(VERSION 3.20)
project(hpe2d VERSION 1.0.0 LANGUAGES CXX)
if(CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
endif()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set_property(CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "/Users/p4010/MADS")
endif()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
# PROJECT SETTINGS #############################################################
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()
# DEPENDENCIES #################################################################
if(WIN32)
# On Windows, we rely on env variables to find install paths
if(NOT DEFINED ENV{OpenCV_DIR})
message(FATAL_ERROR "OpenCV_DIR env var not set, please set it to the OpenCV install directory")
endif()
set(OpenCV_DIR "$ENV{OpenCV_DIR}\\build" CACHE PATH "OpenCV build directory" FORCE)
if(NOT DEFINED ENV{OpenVINO_DIR})
message(FATAL_ERROR "OpenVINO_DIR env var not set, please set it to the OpenVINO install directory")
endif()
set(OpenVINO_DIR "$ENV{OpenVINO_DIR}\\runtime\\cmake" CACHE PATH "OpenVINO install directory" FORCE)
endif()
find_package(OpenCV REQUIRED COMPONENTS core highgui videoio imgproc imgcodecs)
find_package(OpenVINO REQUIRED COMPONENTS Runtime)
if(WIN32)
# OpenVINO headers have to be manually found on Windows
set(OPENVINO_INCLUDE_DIR "$ENV{OpenVINO_DIR}\\runtime\\include")
elseif(APPLE)
find_path(OPENVINO_INCLUDE_DIR NAMES openvino.hpp
PATHS /opt/homebrew/include /usr/local/include
PATH_SUFFIXES openvino
)
cmake_path(GET OPENVINO_INCLUDE_DIR PARENT_PATH OPENVINO_INCLUDE_DIR)
else()
find_path(OPENVINO_INCLUDE_DIR NAMES openvino.hpp
PATHS /opt/intel/openvino_2024.2.0/runtime/include
PATH_SUFFIXES openvino
)
cmake_path(GET OPENVINO_INCLUDE_DIR PARENT_PATH OPENVINO_INCLUDE_DIR)
endif()
if (NOT OPENVINO_INCLUDE_DIR)
message(FATAL_ERROR "OpenVINO not found")
else()
message(STATUS "OpenVINO headers found at ${OPENVINO_INCLUDE_DIR}")
endif()
include(FetchContent)
# pugg is for the plugin system
FetchContent_Declare(pugg
GIT_REPOSITORY https://github.com/pbosetti/pugg.git
GIT_TAG 1.0.2
GIT_SHALLOW TRUE
)
set(BUILD_TESTING OFF CACHE INTERNAL "")
set(JSON_BuildTests OFF CACHE INTERNAL "")
FetchContent_Declare(json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(pugg json)
FetchContent_Populate(plugin
GIT_REPOSITORY https://github.com/pbosetti/mads_plugin.git
GIT_TAG HEAD
GIT_SHALLOW TRUE
)
# Download OpenPOSE models #####################################################
set(MODEL_NAME "human-pose-estimation-0001" CACHE STRING "Model name (no extension)")
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/models/${MODEL_NAME}.xml)
message(STATUS "Downloading OpenPOSE model")
file(DOWNLOAD https://storage.openvinotoolkit.org/repositories/open_model_zoo/2023.0/models_bin/1/${MODEL_NAME}/FP32/${MODEL_NAME}.xml ${CMAKE_CURRENT_SOURCE_DIR}/models/${MODEL_NAME}.xml)
file(DOWNLOAD https://storage.openvinotoolkit.org/repositories/open_model_zoo/2023.0/models_bin/1/${MODEL_NAME}/FP32/${MODEL_NAME}.bin ${CMAKE_CURRENT_SOURCE_DIR}/models/${MODEL_NAME}.bin)
endif()
# Compiler options #############################################################
if(MSVC)
add_compile_options(/wd4267)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
else()
add_compile_options(-Wno-deprecated-anon-enum-enum-conversion)
endif()
# MACROS #######################################################################
# Call: add_plugin(name [SRCS src1 src2 ...] [LIBS lib1 lib2 ...])
# the source file ${SRC_DIR}/plugin/<name>.cpp is implicitly added
macro(add_plugin name)
# on MacOS only, plugins can be compiled as executables
set(multiValueArgs LIBS SRCS)
cmake_parse_arguments(plugin "" "" "${multiValueArgs}" ${ARGN})
if (APPLE)
add_executable(${name} ${SRC_DIR}/${name}.cpp ${plugin_SRCS})
set_target_properties(${name} PROPERTIES ENABLE_EXPORTS TRUE)
set(${name}_EXEC ${name}.plugin)
else()
add_library(${name} SHARED ${SRC_DIR}/${name}.cpp ${plugin_SRCS})
add_executable(${name}_main ${SRC_DIR}/${name}.cpp ${plugin_SRCS})
target_link_libraries(${name}_main PRIVATE pugg ${plugin_LIBS})
set_target_properties(${name}_main PROPERTIES OUTPUT_NAME ${name})
set(${name}_EXEC ${name})
list(APPEND TARGET_LIST ${name}_main)
endif()
target_link_libraries(${name} PRIVATE pugg ${plugin_LIBS})
set_target_properties(${name} PROPERTIES PREFIX "")
set_target_properties(${name} PROPERTIES SUFFIX ".plugin")
target_compile_definitions(${name} PRIVATE PLUGIN_NAME="${name}")
list(APPEND TARGET_LIST ${name})
endmacro()
# BUILD SETTINGS ###############################################################
include_directories(${plugin_SOURCE_DIR}/src)
if (APPLE)
set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
include_directories(/opt/homebrew/include)
link_directories(/opt/homebrew/lib)
else()
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib;/usr/local/lib")
endif()
include_directories(${json_SOURCE_DIR}/include)
set(COMMON ${SRC_DIR}/common)
file(GLOB COMMON_SOURCES
${COMMON}/models/src/*.cpp
${COMMON}/monitors/src/*.cpp
${COMMON}/pipelines/src/*.cpp
${COMMON}/utils/src/*.cpp
)
file(GLOB COMMON_HEADERS
${COMMON}/models/include/models/*.h
${COMMON}/monitors/include/monitors/*.h
${COMMON}/pipelines/include/pipelines/*.h
${COMMON}/utils/include/utils/*.h*
)
# Remove items that depend on gflags (which we don't want)
list(REMOVE_ITEM COMMON_SOURCES ${COMMON}/monitors/src/query_wrapper.cpp)
list(REMOVE_ITEM COMMON_HEADERS ${COMMON}/monitors/src/query_wrapper.h)
list(REMOVE_ITEM COMMON_SOURCES ${COMMON}/utils/src/args_helper.cpp)
list(REMOVE_ITEM COMMON_HEADERS ${COMMON}/utils/include/utils/default_flags.hpp)
# locally modified files
list(APPEND COMMON_SOURCES ${SRC_DIR}/args_helper.cpp)
list(APPEND COMMON_SOURCES ${SRC_DIR}/args_helper.cpp)
# Add the include directories ##################################################
include_directories(
${OpenCV_INCLUDE_DIRS}
${COMMON}/models/include
${COMMON}/monitors/include
${COMMON}/pipelines/include
${COMMON}/utils/include
${OPENVINO_INCLUDE_DIR}
${json_SOURCE_DIR}/include
)
add_library(common STATIC ${COMMON_SOURCES} ${COMMON_HEADERS})
if(UNIX)
target_compile_options(common PUBLIC -fPIC)
endif()
# These plugins are always build and use for testing
add_plugin(hpe2d LIBS common ${OpenCV_LIBS} openvino::runtime)
add_executable(query_devices ${SRC_DIR}/query_devices.cpp ${SRC_DIR}/slog.cpp)
target_link_libraries(query_devices PRIVATE ${OpenCV_LIBS} openvino::runtime)
# INSTALL ######################################################################
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set_property(CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE ${USR_DIR})
endif()
install(TARGETS ${TARGET_LIST}
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
)