exeldro / obs-dynamic-delay

GNU General Public License v2.0
42 stars 4 forks source link

Compiling on Linux and fix OBS < 28 support #9

Open gnif opened 1 year ago

gnif commented 1 year ago

Not tested on other operating systems however the following changes are needed to be made to make this work in a reliable way on Linux.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d9638b8..bf02446 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,9 +24,14 @@ target_sources(${PROJECT_NAME} PRIVATE
        easing.h)

 if(BUILD_OUT_OF_TREE)
-       find_package(libobs REQUIRED)
-       find_package(obs-frontend-api REQUIRED)
+       find_package(PkgConfig)
+       pkg_check_modules(OBS REQUIRED IMPORTED_TARGET libobs)
        include(cmake/ObsPluginHelpers.cmake)
+       target_link_libraries(${PROJECT_NAME} PRIVATE
+               PkgConfig::OBS)
+else()
+       target_link_libraries(${PROJECT_NAME}
+               OBS::libobs)
 endif()

 if(OS_WINDOWS)
@@ -51,9 +56,6 @@ elseif(OS_MACOS)
        target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
 endif()

-target_link_libraries(${PROJECT_NAME}
-       OBS::libobs)
-
 if(BUILD_OUT_OF_TREE)
     if(NOT LIB_OUT_DIR)
         set(LIB_OUT_DIR "/lib/obs-plugins")
diff --git a/dynamic-delay.c b/dynamic-delay.c
index b0bad76..e1e8647 100644
--- a/dynamic-delay.c
+++ b/dynamic-delay.c
@@ -1,6 +1,6 @@
-#include <obs-module.h>
-#include <util/circlebuf.h>
-#include <util/dstr.h>
+#include <obs/obs-module.h>
+#include <obs/util/circlebuf.h>
+#include <obs/util/dstr.h>
 #include "dynamic-delay.h"
 #include "easing.h"
 #include "version.h"
@@ -568,11 +568,13 @@ static obs_properties_t *dynamic_delay_properties(void *data)
                                obs_module_text("TextFormat"),
                                OBS_TEXT_MULTILINE);

+#if LIBOBS_API_MAJOR_VER >= 28
        obs_properties_add_text(
                ppts, "plugin_info",
                "<a href=\"https://obsproject.com/forum/resources/dynamic-delay.1035/\">Dynamic Delay</a> (" PROJECT_VERSION
                ") by <a href=\"https://www.exeldro.com\">Exeldro</a>",
                OBS_TEXT_INFO);
+#endif
        return ppts;
 }
exeldro commented 1 year ago

Why are there changes needed to compile on Linux? In the GitHub actions it seems to compile on Linux without those changes.

gnif commented 1 year ago

Because your github actions are building against the OBS studio source from upstream directly rather then the packaged version that is distributed with Debian/Ubuntu using the libobs-dev packages.

The norm is to make use of pkg-config to obtain the linker and compiler flags, which is what these changes do. Each distro provides their own header packages which contain the configuration for pkg-config making this distro agnostic.

Without these changes, attempting to build against the packaged version results in the following:

CMake Error at CMakeLists.txt:27 (find_package):
  By not providing "Findlibobs.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "libobs", but
  CMake did not find one.

  Could not find a package configuration file provided by "libobs" with any
  of the following names:

    libobsConfig.cmake
    libobs-config.cmake

  Add the installation prefix of "libobs" to CMAKE_PREFIX_PATH or set
  "libobs_DIR" to a directory containing one of the above files.  If "libobs"
  provides a separate development package or SDK, be sure it has been
  installed.

-- Configuring incomplete, errors occurred!
See also "/home/geoff/Projects/LG/obs-dynamic-delay/CMakeFiles/CMakeOutput.log".
make: *** [Makefile:299: cmake_check_build_system] Error 1

as for the version ifdef, OBS_TEXT_INFO does not exist before v28

gnif commented 1 year ago

Further to this it would be nice too if the CMake install target was by default for the local user, installing into ~/.config/obs-studio/plugins/dynamic-delay making it available without needing to run make install as root.

ie:

-- Install configuration: "RelWithDebInfo"
-- Installing: /home/geoff/.config/obs-studio/plugins/dynamic-delay/bin/64bit/dynamic-delay.so
-- Installing: /home/geoff/.config/obs-studio/plugins/dynamic-delay/data//locale
-- Installing: /home/geoff/.config/obs-studio/plugins/dynamic-delay/data//locale/en-US.ini
-- Installing: /home/geoff/.config/obs-studio/plugins/dynamic-delay/obs-plugins/64bit/dynamic-delay.so
-- Installing: /home/geoff/.config/obs-studio/plugins/dynamic-delay/data/obs-plugins/dynamic-delay
-- Installing: /home/geoff/.config/obs-studio/plugins/dynamic-delay/data/obs-plugins/dynamic-delay/locale
-- Installing: /home/geoff/.config/obs-studio/plugins/dynamic-delay/data/obs-plugins/dynamic-delay/locale/en-US.ini

obviously it can be done with cmake defines by setting the install prefix and out dirs manually, but it would be a nice default to have if the install target is run as an unprivileged user.

If you would like a working example, we are doing this here for the Looking Glass project: https://github.com/gnif/LookingGlass/blob/master/obs/CMakeLists.txt#L33:L48 https://github.com/gnif/LookingGlass/blob/master/obs/CMakeLists.txt#L86:L88