Skip to content

Commit 42b2238

Browse files
committed
add findlibobs.cmake
1 parent b3d9056 commit 42b2238

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

external/FindLibObs.cmake

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# This module can be copied and used by external plugins for OBS
2+
#
3+
# Once done these will be defined:
4+
#
5+
# LIBOBS_FOUND
6+
# LIBOBS_INCLUDE_DIRS
7+
# LIBOBS_LIBRARIES
8+
9+
find_package(PkgConfig QUIET)
10+
if (PKG_CONFIG_FOUND)
11+
pkg_check_modules(_OBS QUIET obs libobs)
12+
endif()
13+
14+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
15+
set(_lib_suffix 64)
16+
else()
17+
set(_lib_suffix 32)
18+
endif()
19+
20+
if(DEFINED CMAKE_BUILD_TYPE)
21+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
22+
set(_build_type_base "debug")
23+
else()
24+
set(_build_type_base "release")
25+
endif()
26+
endif()
27+
28+
find_path(LIBOBS_INCLUDE_DIR
29+
NAMES obs.h
30+
HINTS
31+
ENV obsPath${_lib_suffix}
32+
ENV obsPath
33+
${obsPath}
34+
PATHS
35+
/usr/include /usr/local/include /opt/local/include /sw/include
36+
PATH_SUFFIXES
37+
libobs
38+
)
39+
40+
function(find_obs_lib base_name repo_build_path lib_name)
41+
string(TOUPPER "${base_name}" base_name_u)
42+
43+
if(DEFINED _build_type_base)
44+
set(_build_type_${repo_build_path} "${_build_type_base}/${repo_build_path}")
45+
set(_build_type_${repo_build_path}${_lib_suffix} "${_build_type_base}${_lib_suffix}/${repo_build_path}")
46+
endif()
47+
48+
find_library(${base_name_u}_LIB
49+
NAMES ${_${base_name_u}_LIBRARIES} ${lib_name} lib${lib_name}
50+
HINTS
51+
ENV obsPath${_lib_suffix}
52+
ENV obsPath
53+
${obsPath}
54+
${_${base_name_u}_LIBRARY_DIRS}
55+
PATHS
56+
/usr/lib /usr/local/lib /opt/local/lib /sw/lib
57+
PATH_SUFFIXES
58+
lib${_lib_suffix} lib
59+
libs${_lib_suffix} libs
60+
bin${_lib_suffix} bin
61+
../lib${_lib_suffix} ../lib
62+
../libs${_lib_suffix} ../libs
63+
../bin${_lib_suffix} ../bin
64+
# base repo non-msvc-specific search paths
65+
${_build_type_${repo_build_path}}
66+
${_build_type_${repo_build_path}${_lib_suffix}}
67+
build/${repo_build_path}
68+
build${_lib_suffix}/${repo_build_path}
69+
# base repo msvc-specific search paths on windows
70+
build${_lib_suffix}/${repo_build_path}/Debug
71+
build${_lib_suffix}/${repo_build_path}/RelWithDebInfo
72+
build/${repo_build_path}/Debug
73+
build/${repo_build_path}/RelWithDebInfo
74+
)
75+
endfunction()
76+
77+
find_obs_lib(LIBOBS libobs obs)
78+
79+
if(MSVC)
80+
find_obs_lib(W32_PTHREADS deps/w32-pthreads w32-pthreads)
81+
endif()
82+
83+
include(FindPackageHandleStandardArgs)
84+
find_package_handle_standard_args(Libobs DEFAULT_MSG LIBOBS_LIB LIBOBS_INCLUDE_DIR)
85+
mark_as_advanced(LIBOBS_INCLUDE_DIR LIBOBS_LIB)
86+
87+
if(LIBOBS_FOUND)
88+
if(MSVC)
89+
if (NOT DEFINED W32_PTHREADS_LIB)
90+
message(FATAL_ERROR "Could not find the w32-pthreads library" )
91+
endif()
92+
93+
set(W32_PTHREADS_INCLUDE_DIR ${LIBOBS_INCLUDE_DIR}/../deps/w32-pthreads)
94+
endif()
95+
96+
set(LIBOBS_INCLUDE_DIRS ${LIBOBS_INCLUDE_DIR} ${W32_PTHREADS_INCLUDE_DIR})
97+
set(LIBOBS_LIBRARIES ${LIBOBS_LIB} ${W32_PTHREADS_LIB})
98+
include(${LIBOBS_INCLUDE_DIR}/../cmake/external/ObsPluginHelpers.cmake)
99+
100+
# allows external plugins to easily use/share common dependencies that are often included with libobs (such as FFmpeg)
101+
if(NOT DEFINED INCLUDED_LIBOBS_CMAKE_MODULES)
102+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LIBOBS_INCLUDE_DIR}/../cmake/Modules/")
103+
set(INCLUDED_LIBOBS_CMAKE_MODULES true)
104+
endif()
105+
else()
106+
message(FATAL_ERROR "Could not find the libobs library" )
107+
endif()

0 commit comments

Comments
 (0)