This repository has been archived by the owner on May 13, 2022. It is now read-only.
forked from locaal-ai/obs-backgroundremoval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
293 lines (235 loc) · 10 KB
/
CMakeLists.txt
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
cmake_minimum_required(VERSION 3.10)
include(external/MunkeiVersionFromGit.cmake)
version_from_git()
# Change obs-plugintemplate to your plugin's name in a machine-readable format
# (e.g.: obs-myawesomeplugin) and set
project(obs-backgroundremoval VERSION ${VERSION})
# Replace `Your Name Here` with the name (yours or your organization's) you want
# to see as the author of the plugin (in the plugin's metadata itself and in the installers)
set(PLUGIN_AUTHOR "Roy Shilkrot")
# Replace `com.example.obs-plugin-template` with a unique Bundle ID for macOS releases
# (used both in the installer and when submitting the installer for notarization)
set(MACOS_BUNDLEID "com.example.obs-backgroundremoval")
# Replace `[email protected]` with the maintainer email address you want to put in Linux packages
set(LINUX_MAINTAINER_EMAIL "[email protected]")
option(WITH_CUDA "Build with CUDA support." OFF)
if(WITH_CUDA)
add_compile_definitions("WITH_CUDA=1")
endif()
if(WIN32 OR MSVC)
set(VCPKG_DIR ${CMAKE_BINARY_DIR}/vcpkg)
set(VCPKG_INSTALLED_DIR ${VCPKG_DIR}/installed/x64-windows-static)
set(CMAKE_TOOLCHAIN_FILE ${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake)
set(OpenCV_DIR ${VCPKG_INSTALLED_DIR}/share/opencv)
set(Protobuf_DIR ${VCPKG_INSTALLED_DIR}/share/protobuf)
set(LibLZMA_DIR ${VCPKG_INSTALLED_DIR}/share/liblzma)
set(quirc_DIR ${VCPKG_INSTALLED_DIR}/share/quirc)
if(NOT ${libobs_DIR})
message(FATAL "Please provide libobs_DIR to CMake.")
endif(NOT ${libobs_DIR})
set(w32-pthreads_DIR ${libobs_DIR}/../deps/w32-pthreads)
set(obs-frontend-api_DIR ${libobs_DIR}/../UI/obs-frontend-api)
# Find lib TIFF
find_library(TIFF_LIBRARY tiff PATHS ${VCPKG_INSTALLED_DIR}/lib)
find_path(TIFF_INCLUDE_DIR tiff.h PATHS ${VCPKG_INSTALLED_DIR}/include)
find_file(Protobuf_PROTOC_EXECUTABLE protoc.exe PATHS ${VCPKG_INSTALLED_DIR}/tools/protobuf)
elseif(APPLE)
# Apple
if (WITH_CUDA)
message(FATAL "Cannot use CUDA on Apple builds")
endif()
endif()
if (UNIX)
set(Onnxruntime_INCLUDE_HINT /usr/local/include/)
endif()
if (APPLE)
set(OpenCV_DIR ${CMAKE_BINARY_DIR}/opencv/lib/cmake/opencv4)
endif()
set(RELEASE_DIR "${PROJECT_SOURCE_DIR}/release" CACHE STRING "Directory for building release packages")
set(CMAKE_PREFIX_PATH "${QTDIR}")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/external")
# In case you need C++
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
configure_file(
src/plugin-macros.h.in
../src/plugin-macros.generated.h
)
configure_file(
installer/installer-macOS.pkgproj.in
../installer/installer-macOS.generated.pkgproj
)
configure_file(
installer/installer-Windows.iss.in
../installer/installer-Windows.generated.iss
)
configure_file(
ci/ci_includes.sh.in
../ci/ci_includes.generated.sh
)
configure_file(
ci/ci_includes.cmd.in
../ci/ci_includes.generated.cmd
)
set(PLUGIN_SOURCES
src/background-filter.cpp
src/plugin-main.cpp
)
set(PLUGIN_HEADERS
src/plugin-macros.generated.h)
# --- Platform-independent build settings ---
add_library(${CMAKE_PROJECT_NAME} MODULE ${PLUGIN_SOURCES} ${PLUGIN_HEADERS})
find_package(libobs REQUIRED)
find_package(obs-frontend-api REQUIRED)
include(external/ObsPluginHelpers.cmake)
find_package(Onnxruntime REQUIRED)
find_package(OpenCV 4.5 REQUIRED COMPONENTS core imgproc)
include_directories(
${LIBOBS_INCLUDE_DIR}/../UI/obs-frontend-api
${LIBOBS_INCLUDE_DIR}
${LIBOBS_INCLUDE_DIRS}
${Onnxruntime_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
target_link_libraries(${CMAKE_PROJECT_NAME}
OBS::libobs OBS::obs-frontend-api
${Onnxruntime_LIBRARIES}
${OpenCV_LIBRARIES}
)
# --- End of section ---
# --- Windows-specific build settings and tasks ---
if(WIN32)
# Enable Multicore Builds and disable FH4 (to not depend on VCRUNTIME140_1.DLL when building with VS2019)
if (MSVC)
add_definitions(/MP /d2FH4- /std:c++latest /MT)
endif()
# --- Release package helper ---
# The "release" folder has a structure similar OBS' one on Windows
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
"${CMAKE_COMMAND}" -E remove_directory "${RELEASE_DIR}"
)
# If config is Release or RelWithDebInfo, package release files
COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
"${CMAKE_COMMAND}" -E make_directory
"${RELEASE_DIR}/data/obs-plugins/${CMAKE_PROJECT_NAME}"
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}"
)
COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
"${CMAKE_COMMAND}" -E copy_directory
"${PROJECT_SOURCE_DIR}/data"
"${RELEASE_DIR}/data/obs-plugins/${CMAKE_PROJECT_NAME}"
)
COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
"${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:${CMAKE_PROJECT_NAME}>"
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}"
)
# package the DirectML DLL with the plugin DLL unless using CUDA
COMMAND if $<AND:$<NOT:$<BOOL:${WITH_CUDA}>>,$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>>==1 (
"${CMAKE_COMMAND}" -E copy
"${CMAKE_BINARY_DIR}/nuget/Microsoft.AI.DirectML.1.8.0/bin/x64-win/DirectML.dll"
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}"
)
# package the onnxruntime DLL with the plugin DLL
COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
"${CMAKE_COMMAND}" -E copy
"${Onnxruntime_LIBRARY_DIR}/onnxruntime.dll"
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}"
)
# If config is RelWithDebInfo, copy the pdb file
COMMAND if $<CONFIG:RelWithDebInfo>==1 (
"${CMAKE_COMMAND}" -E copy
"$<TARGET_PDB_FILE:${CMAKE_PROJECT_NAME}>"
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}"
)
# Copy to obs-studio dev environment for immediate testing
COMMAND if $<CONFIG:Debug>==1 (
"${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:${CMAKE_PROJECT_NAME}>"
"${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/obs-plugins/${ARCH_NAME}"
)
COMMAND if $<CONFIG:Debug>==1 (
"${CMAKE_COMMAND}" -E copy
"$<TARGET_PDB_FILE:${CMAKE_PROJECT_NAME}>"
"${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/obs-plugins/${ARCH_NAME}"
)
COMMAND if $<CONFIG:Debug>==1 (
"${CMAKE_COMMAND}" -E make_directory
"${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/data/obs-plugins/${CMAKE_PROJECT_NAME}"
)
COMMAND if $<CONFIG:Debug>==1 (
"${CMAKE_COMMAND}" -E copy_directory
"${PROJECT_SOURCE_DIR}/data"
"${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/data/obs-plugins/${CMAKE_PROJECT_NAME}"
)
)
# --- End of sub-section ---
install(DIRECTORY "${RELEASE_DIR}/" DESTINATION .)
# Tell CPack to create a zip file.
set(CPACK_GENERATOR "ZIP")
# Tell CPack what to name the zip file. It will append `.zip`.
if (WITH_CUDA)
set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}-cuda")
endif()
# Tell CPack not to put everything inside an enclosing directory.
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
# Apparently this should be always on but isn't for backwards compatibility.
set(CPACK_VERBATIM_VARIABLES YES)
include(CPack)
endif()
# --- End of section ---
# --- Linux-specific build settings and tasks ---
if(UNIX AND NOT APPLE)
include(GNUInstallDirs)
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES PREFIX "")
target_link_libraries(${CMAKE_PROJECT_NAME} obs-frontend-api)
file(GLOB locale_files data/locale/*.ini)
file(GLOB onnxmodels data/*.onnx)
install(TARGETS ${CMAKE_PROJECT_NAME}
LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/obs-plugins")
install(FILES ${locale_files}
DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/obs/obs-plugins/${CMAKE_PROJECT_NAME}/locale")
install(FILES ${onnxmodels}
DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/obs/obs-plugins/${CMAKE_PROJECT_NAME}/")
endif()
# --- End of section ---
# -- OS X specific build settings and tasks --
if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -fvisibility=default -framework Foundation")
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES PREFIX "")
target_link_libraries(${CMAKE_PROJECT_NAME} "${OBS_FRONTEND_LIB}")
# add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
add_custom_target(dist DEPENDS ${CMAKE_PROJECT_NAME}
COMMAND
"${CMAKE_COMMAND}" -E rm -rf "${RELEASE_DIR}"
COMMAND
"${CMAKE_COMMAND}" -E make_directory
"${RELEASE_DIR}/Resources/data/obs-plugins/${CMAKE_PROJECT_NAME}"
"${RELEASE_DIR}/Plugins"
COMMAND
"${CMAKE_COMMAND}" -E copy_directory
"${PROJECT_SOURCE_DIR}/data"
"${RELEASE_DIR}/Resources/data/obs-plugins/${CMAKE_PROJECT_NAME}"
COMMAND
"${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:${CMAKE_PROJECT_NAME}>"
"${RELEASE_DIR}/Plugins/"
COMMAND
"${CMAKE_COMMAND}" -E rm -f
"${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}-macosx.zip"
)
install(DIRECTORY "${RELEASE_DIR}/" DESTINATION .)
# Tell CPack to create a zip file.
set(CPACK_GENERATOR "ZIP")
# Tell CPack what to name the zip file. It will append `.zip`.
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-macosx")
# Tell CPack not to put everything inside an enclosing directory.
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
# Apparently this should be always on but isn't for backwards compatibility.
set(CPACK_VERBATIM_VARIABLES YES)
include(CPack)
endif()
# -- End of section --