FindLibObs.cmake 3.0 KB

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