obs-studio icon indicating copy to clipboard operation
obs-studio copied to clipboard

cmake: Update Linux build scripts to new 3.0 build path

Open PatTheMav opened this issue 1 year ago • 13 comments

Description

Completes the migration of OBS Studio's build system to the updated CMake 3.0 build path introduced to macOS and Windows before.

[!IMPORTANT]

This PR is directly based on top of https://github.com/obsproject/obs-studio/pull/9769, which should be reviewed and merged first, at which point a rebase will reduce the amount of changes introduced by this PR.

Additional squashing of commits will be done after reviews are finished.

This PR builds on all the systems and methods introduced for other platforms before and extends it:

  • Added updated find modules for Linux-specific dependencies:
    • JACK audio
    • LibUUID
    • Libdrm
    • Libfdk
    • Libpci
    • Libudev
    • Libv4l2
    • Libva
    • OSS
    • PipeWire
    • PulseAudio
    • Sndio
    • Sysinfo
    • Wayland
    • glib and gio
    • X11-xcb
    • XCB
    • xkbcommon
  • Updates existing find modules to improve compatibility with Linux:
    • FFmpeg (improved version extraction from ffversion.h)
    • Libx264 (improved version extraction from x264_config.h)
    • LuaJIT (switched version extraction to use LuaJIT version and not Lua version)
    • MbedTLS (improved version extraction from mbedtls/version.h)
  • Find modules should be able to locate dependencies either via pkg-config hints or CMake's build in dependency detection
  • Added check for possibly separate math library provided by toolchain to explicitly link to it when necessary
  • Added some additional checks for the presence of headers in system include paths
  • Updated all Linux-specific modules:
    • linux-alsa
    • linux-capture
    • linux-jack
    • linux-pipewire
    • linux-pulseaudio
    • linux-v4l2
    • oss-audio
    • sndio
  • Updated Linux-specific code for already updated modules:
    • libobs
    • obs-libfdk
    • obs-ffmpeg
    • obs-outputs
    • obs-qsv11
    • UI
    • aja
    • vlc
  • Enabled support for Python 3.11+ outside of Windows and macOS
  • Fixed simple GCC compile warnings (unused code)
  • Add GCC-specific warning suppressions where appropriate (usually for parity with Clang-specific warnings)
  • Updated default GCC compiler flags for parity with Clang compiler flags
  • Retained reasonable FreeBSD compatibility (updated Cirrus CI file to enable CMake 3.0 builds for FreeBSD)
  • Updated CI build scripts and GitHub Actions workflows

[!NOTE]

Lower CMake version boundary is not increased by this PR, the minimum required version on Linux will still be CMake 3.22.

Motivation and Context

Remove legacy code and improve CMake codebase for Linux (and FreeBSD) and achieve parity with Windows and macOS.

How Has This Been Tested?

Tested on Ubuntu 23.04 and FreeBSD 13.2.

Types of changes

  • Code cleanup (non-breaking change which makes code smaller or more readable)

Checklist:

  • [x] My code has been run through clang-format.
  • [x] I have read the contributing document.
  • [x] My code is not on the master branch.
  • [x] The code has been tested.
  • [x] All commit messages are properly formatted and commits squashed where appropriate.
  • [x] I have included updates to all appropriate documentation.

PatTheMav avatar Nov 01 '23 16:11 PatTheMav

CMake 3.0 does not provide support for system ftl-sdk install.

tytan652 avatar Nov 01 '23 20:11 tytan652

Made a packaging test build on Arch Linux and many headers are missing as it is.

~~example.h~~ indicate a missing header compared to a build without the PR.

Screenshot from 2023-11-01 22-11-01

Screenshot from 2023-11-01 22-11-28

I didn't dig further but for some reason obs-browser-page locale file are no longer installed, ~~I don't know if it's intended~~ error.html is missing too. I do use your obs-browser branch.

tytan652 avatar Nov 01 '23 21:11 tytan652

I forgot to mention, the pkg-config file for libobs is no longer installed. On Linux, even if there is a CMake package, this method is not universal among build-systems (pkg-config is).

tytan652 avatar Nov 01 '23 21:11 tytan652

I forgot to mention, the pkg-config file for libobs is no longer installed. On Linux, even if there is a CMake package, this method is not universal among build-systems (pkg-config is).

We should add a handcrafted pkg-config file - generating it from CMake will break the moment generator expressions are used in the dependency graph (or at the very least make it complicated to generate one).

Some elements might be generated automatically (e.g. version) but CFlags and everything surround static/shared requirements should be written by hand.

I'm happy to add that if someone can provide me the template file for it.

PatTheMav avatar Nov 01 '23 22:11 PatTheMav

You should force the Flatpak to build with CMake 3.0 (without preset), there is many issues not revealed in CI because of that.

tytan652 avatar Nov 02 '23 12:11 tytan652

You should force the Flatpak to build with CMake 3.0 (without preset), there is many issues not revealed in CI because of that.

I deliberately not updated that yet because I wanted to leave that to you or @GeorgesStavracas to update when you can support the migration.

PatTheMav avatar Nov 02 '23 12:11 PatTheMav

I deliberately not updated that yet because I wanted to leave that to you or @GeorgesStavracas to update when you can support the migration.

I will not debug this post merge, this should pass all Linux CI with CMake 3.0. Also what migration ?

tytan652 avatar Nov 02 '23 12:11 tytan652

I deliberately not updated that yet because I wanted to leave that to you or @GeorgesStavracas to update when you can support the migration.

I will not debug this post merge, this should pass all Linux CI with CMake 3.0. Also what migration ?

When this PR is merged, it will not automatically default to the new CMake build variant if no preset is selected, it is "opt-in" (like it is on Windows right now). That way packagers/maintainers can chose when to make the switch and report bugs that might not have been discovered during review without breaking the ability to still generate packages.

That timeframe until either a preset is required or the legacy code paths are removed is the migration period (so far we waited a full release cycle to remove the legacy path for macOS, Windows legacy and x86 slices might be removed with the version after the next) so the Flatpak update does not have to occur at the same time but can happen at a later point.

That's up to the Flatpak maintainers to decide and adapt.

PatTheMav avatar Nov 02 '23 12:11 PatTheMav

AJA is broken, on Flatpak and Arch Linux.

[152/509] Linking CXX shared module plugins/aja/aja.so
FAILED: plugins/aja/aja.so 
: && /usr/bin/c++ -fPIC -O3 -DNDEBUG  -L/app/lib -shared  -o plugins/aja/aja.so plugins/aja/CMakeFiles/aja-support.dir/aja-card-manager.cpp.o plugins/aja/CMakeFiles/aja-support.dir/aja-common.cpp.o plugins/aja/CMakeFiles/aja-support.dir/aja-presets.cpp.o plugins/aja/CMakeFiles/aja-support.dir/aja-props.cpp.o plugins/aja/CMakeFiles/aja-support.dir/aja-routing.cpp.o plugins/aja/CMakeFiles/aja-support.dir/aja-vpid-data.cpp.o plugins/aja/CMakeFiles/aja-support.dir/aja-widget-io.cpp.o plugins/aja/CMakeFiles/aja.dir/aja-output.cpp.o plugins/aja/CMakeFiles/aja.dir/aja-source.cpp.o plugins/aja/CMakeFiles/aja.dir/audio-repack.c.o plugins/aja/CMakeFiles/aja.dir/main.cpp.o  -Wl,-rpath,/home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/rundir/Release/lib:/home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/libobs:  libobs/libobs.so.30  /app/lib/libajantv2.a && cd /home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/plugins/aja && /usr/bin/cmake -E make_directory /home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/rundir/Release/lib/obs-plugins && /usr/bin/cmake -E copy_if_different /home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/plugins/aja/aja.so /home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/rundir/Release/lib/obs-plugins && cd /home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/plugins/aja && /usr/bin/cmake -E make_directory /home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/rundir/Release/share/obs/obs-plugins/aja && /usr/bin/cmake -E copy_directory /home/tytan652/Programming/OBS/obs-studio/plugins/aja/data /home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/rundir/Release/share/obs/obs-plugins/aja
/usr/lib/gcc/x86_64-unknown-linux-gnu/12.2.0/../../../../x86_64-unknown-linux-gnu/bin/ld: plugins/aja/CMakeFiles/aja-support.dir/aja-routing.cpp.o: warning: relocation against `_ZTVSt9basic_iosIcSt11char_traitsIcEE@@GLIBCXX_3.4' in read-only section `.text.unlikely'
/usr/lib/gcc/x86_64-unknown-linux-gnu/12.2.0/../../../../x86_64-unknown-linux-gnu/bin/ld: plugins/aja/CMakeFiles/aja-support.dir/aja-card-manager.cpp.o: relocation R_X86_64_PC32 against symbol `__libc_single_threaded@@GLIBC_2.32' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-unknown-linux-gnu/12.2.0/../../../../x86_64-unknown-linux-gnu/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
[157/509] Building C object plugins/linux-capture/CMakeFiles/linux-capture.dir/xshm-input.c.o
ninja: build stopped: subcommand failed.

tytan652 avatar Nov 02 '23 12:11 tytan652

AJA is broken, on Flatpak and Arch Linux.

[152/509] Linking CXX shared module plugins/aja/aja.so
FAILED: plugins/aja/aja.so 
: && /usr/bin/c++ -fPIC -O3 -DNDEBUG  -L/app/lib -shared  -o plugins/aja/aja.so plugins/aja/CMakeFiles/aja-support.dir/aja-card-manager.cpp.o plugins/aja/CMakeFiles/aja-support.dir/aja-common.cpp.o plugins/aja/CMakeFiles/aja-support.dir/aja-presets.cpp.o plugins/aja/CMakeFiles/aja-support.dir/aja-props.cpp.o plugins/aja/CMakeFiles/aja-support.dir/aja-routing.cpp.o plugins/aja/CMakeFiles/aja-support.dir/aja-vpid-data.cpp.o plugins/aja/CMakeFiles/aja-support.dir/aja-widget-io.cpp.o plugins/aja/CMakeFiles/aja.dir/aja-output.cpp.o plugins/aja/CMakeFiles/aja.dir/aja-source.cpp.o plugins/aja/CMakeFiles/aja.dir/audio-repack.c.o plugins/aja/CMakeFiles/aja.dir/main.cpp.o  -Wl,-rpath,/home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/rundir/Release/lib:/home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/libobs:  libobs/libobs.so.30  /app/lib/libajantv2.a && cd /home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/plugins/aja && /usr/bin/cmake -E make_directory /home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/rundir/Release/lib/obs-plugins && /usr/bin/cmake -E copy_if_different /home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/plugins/aja/aja.so /home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/rundir/Release/lib/obs-plugins && cd /home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/plugins/aja && /usr/bin/cmake -E make_directory /home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/rundir/Release/share/obs/obs-plugins/aja && /usr/bin/cmake -E copy_directory /home/tytan652/Programming/OBS/obs-studio/plugins/aja/data /home/tytan652/.cache/gnome-builder/projects/obs-studio/builds/com.obsproject.Studio.json-flatpak-org.kde.Platform-6.5-x86_64-linux-build-update/rundir/Release/share/obs/obs-plugins/aja
/usr/lib/gcc/x86_64-unknown-linux-gnu/12.2.0/../../../../x86_64-unknown-linux-gnu/bin/ld: plugins/aja/CMakeFiles/aja-support.dir/aja-routing.cpp.o: warning: relocation against `_ZTVSt9basic_iosIcSt11char_traitsIcEE@@GLIBCXX_3.4' in read-only section `.text.unlikely'
/usr/lib/gcc/x86_64-unknown-linux-gnu/12.2.0/../../../../x86_64-unknown-linux-gnu/bin/ld: plugins/aja/CMakeFiles/aja-support.dir/aja-card-manager.cpp.o: relocation R_X86_64_PC32 against symbol `__libc_single_threaded@@GLIBC_2.32' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-unknown-linux-gnu/12.2.0/../../../../x86_64-unknown-linux-gnu/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
[157/509] Building C object plugins/linux-capture/CMakeFiles/linux-capture.dir/xshm-input.c.o
ninja: build stopped: subcommand failed.

That might require explicitly setting the POSITION_INDEPENDENT_CODE target property - I just have to find out for which target specifically.

PatTheMav avatar Nov 03 '23 13:11 PatTheMav

Fails to build on linux?

IGN-Styly avatar Dec 09 '23 13:12 IGN-Styly

PR has been rebased and updated but still requires the browser and websocket submodules to be updated first.

PatTheMav avatar Dec 20 '23 18:12 PatTheMav

Just a heads-up for all participants on this PR so far: This will not be rushed to be merged for the immediate next version of OBS, but hopefully can be finalised and merged after the next release branch has been created.

PatTheMav avatar Jan 10 '24 13:01 PatTheMav

There are warnings for module name correctness

plugins/linux-capture/CMakeLists.txt:8 (find_package) (Xcb/xcb)
libobs-opengl/CMakeLists.txt:17 (find_package) (Xcb/xcb)
libobs/cmake/os-linux.cmake:5 (find_package) (Xcb/xcb)

And pipewire was not updated for the new casing in plugins/linux-pipewire/CMakeLists.txt:19 which causes the check to always be false. Maybe there is a good way to find references to undefined variables, but that might be too much to hope for. Also this caught some unused variables in the camera-portal.c code that need to be cleaned up heh...

On my system obs-browser doesnt compile with headers for libobs not found, ill look into it some more later.

kkartaltepe avatar Mar 30 '24 03:03 kkartaltepe

Also impossible to run obs since it will never be able to find locale because it uses the working directory for relative paths.

tytan652 avatar Mar 30 '24 08:03 tytan652

There are warnings for module name correctness

plugins/linux-capture/CMakeLists.txt:8 (find_package) (Xcb/xcb)
libobs-opengl/CMakeLists.txt:17 (find_package) (Xcb/xcb)
libobs/cmake/os-linux.cmake:5 (find_package) (Xcb/xcb)

And pipewire was not updated for the new casing in plugins/linux-pipewire/CMakeLists.txt:19 which causes the check to always be false. Maybe there is a good way to find references to undefined variables, but that might be too much to hope for. Also this caught some unused variables in the camera-portal.c code that need to be cleaned up heh...

On my system obs-browser doesnt compile with headers for libobs not found, ill look into it some more later.

Those are already fixed and pushed. The browser issue I wasn't able to reproduce.

PatTheMav avatar Mar 30 '24 15:03 PatTheMav

➜  ~ ls -lA /usr/lib/libobs*
lrwxrwxrwx 1 root root      23 30 mars  09:15 /usr/lib/libobs-opengl.so -> libobs-opengl.so.30.1.0
-rwxr-xr-x 1 root root 1246184 30 mars  09:15 /usr/lib/libobs-opengl.so.30
lrwxrwxrwx 1 root root      19 30 mars  09:15 /usr/lib/libobs-opengl.so.30.1.0 -> libobs-opengl.so.30
lrwxrwxrwx 1 root root      16 30 mars  09:15 /usr/lib/libobs.so -> libobs.so.30.1.0
-rwxr-xr-x 1 root root 5490136 30 mars  09:15 /usr/lib/libobs.so.30
lrwxrwxrwx 1 root root      12 30 mars  09:15 /usr/lib/libobs.so.30.1.0 -> libobs.so.30

libobs-frontend-api and libobs-scripting are missing ?

Edit: Both missing are in fact missing their lib prefix in their name.

Did they always ship with the lib prefix?

PatTheMav avatar Mar 30 '24 15:03 PatTheMav

Also impossible to run obs since it will never be able to find locale because it uses the working directory for relative paths.

Confirmed, I have a working fix, viability is being discussed off-thread.

PatTheMav avatar Mar 30 '24 15:03 PatTheMav

Did they always ship with the lib prefix?

It's a default on Linux (and maybe more), beside modules where CMake kind of enforce no prefix. Libraries have the lib prefix.

tytan652 avatar Mar 30 '24 16:03 tytan652

obs-ffmpeg also requires the compile definition NVCODEC_AVAILABLE to be set for the native NVENC to be registered on Linux, and FFmpeg NVENC to be marked as hidden.

target_enable_feature set the definition (it's signature is target_enable_feature(<target> <description string> [<compiler definitions>])) but I had to rewrite the whole thing anyway.

PatTheMav avatar Apr 03 '24 14:04 PatTheMav

Should mark that this closes/supersedes #10008 and fixes #7972. Also mention that this fixes #7407 in the PR description as well.

RytoEX avatar Apr 05 '24 01:04 RytoEX

On OpenSUSE the xkbcommon finder fails for me.

Here's the output of rpm -ql libxkbcommon-devel to show where the files are installed:

/usr/include/libxkbcommon
/usr/include/libxkbcommon/xkbcommon
/usr/include/libxkbcommon/xkbcommon/xkbcommon-compat.h
/usr/include/libxkbcommon/xkbcommon/xkbcommon-compose.h
/usr/include/libxkbcommon/xkbcommon/xkbcommon-keysyms.h
/usr/include/libxkbcommon/xkbcommon/xkbcommon-names.h
/usr/include/libxkbcommon/xkbcommon/xkbcommon.h
/usr/include/libxkbcommon/xkbcommon/xkbregistry.h
/usr/lib64/libxkbcommon.so
/usr/lib64/pkgconfig/xkbcommon.pc
/usr/share/doc/packages/libxkbcommon-devel
/usr/share/doc/packages/libxkbcommon-devel/NEWS.md

This seems like a weird packaging decision... My build has a number of features disabled so I'm not sure if there are other packages where there could be issues.

Edit: Found a mistake in the finder, will add code comment shortly.

Edit 2: Nvm while cmake works with that it still fails building for some reason:

/home/dennis/Projects/obs-studio/libobs/obs-nix-wayland.c:27:10: fatal error: xkbcommon/xkbcommon.h: No such file or directory
   27 | #include <xkbcommon/xkbcommon.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~

Edit 3: Changing xkbcommon.h to xkbcommon/xkbcommon.h in the finder works for me, but not sure if that would fall apart on other distros.

Edit 4: This builds on Ubuntu and openSUSE at least: https://github.com/derrod/obs-studio/commit/0a6e93041f683d032386a46d81578856de73fbea

derrod avatar Apr 05 '24 04:04 derrod

Changing xkbcommon.h to xkbcommon/xkbcommon.h in the finder works for me, but not sure if that would fall apart on other distros.

xkbcommon/xkbcommon.h is the popular usage, you should not end up with ${prefix}/include/xkbcommon in the list of included directory but ${prefix}/include like its pkgconfig file does.

tytan652 avatar Apr 05 '24 06:04 tytan652

I'll pick this up again early next week.

RytoEX avatar Apr 05 '24 23:04 RytoEX

Building on Windows 11 in RelWithDebInfo or Debug resulted in a failure to launch: image

---------------------------
obs64.exe - System Error
---------------------------
The code execution cannot proceed because libx264-164.dll was not found. Reinstalling the program may fix this problem. 
---------------------------
OK   
---------------------------

I can confirm that libx264-164.dll is missing from the rundir's bin directory.

Comparing CMakeCache before and after this PR... Before:

//Libx264 import library location
Libx264_IMPLIB:FILEPATH=C:/dev/obsproject/obs-studio/.deps/obs-deps-2024-03-19-x64/lib/libx264.lib

//Libx264 include directory
Libx264_INCLUDE_DIR:PATH=C:/dev/obsproject/obs-studio/.deps/obs-deps-2024-03-19-x64/include

//Libx264 DLL location
Libx264_LIBRARY:FILEPATH=C:/dev/obsproject/obs-studio/.deps/obs-deps-2024-03-19-x64/bin/libx264-164.dll

After:

//Libx264 import library location
Libx264_IMPLIB:FILEPATH=C:/dev/obsproject/obs-studio/.deps/obs-deps-2024-03-19-x64/lib/libx264.lib

//Libx264 include directory
Libx264_INCLUDE_DIR:PATH=C:/dev/obsproject/obs-studio/.deps/obs-deps-2024-03-19-x64/include

//Libx264 DLL location
Libx264_LIBRARY:FILEPATH=Libx264_LIBRARY-NOTFOUND

Can confirm that reverting the changes in cmake/finders/FindLibx264.cmake produces a CMakeCache as in the "Before" above.

RytoEX avatar Apr 08 '24 23:04 RytoEX

Building on Windows 11 in RelWithDebInfo or Debug resulted in a failure to launch: !

The change was necessary because the header looks differently on FreeBSD:

#define X264_POINTVER "0.164.3106 eaa68fa"

vs

#define X264_POINTVER "0.164.x"

As such the regular expression had to yield a version number even if the commit hash part was omitted. On Ubuntu it correctly only yields the semver string, but on Windows and macOS it always included the commit hash as well, which is unexpected..

PatTheMav avatar Apr 10 '24 00:04 PatTheMav

Confirming that I can now build and run in Debug, RelWithDebInfo, and Release on Windows 11. cmake-format is still failing on cmake/finders/FindLibx264.cmake though, so that will need to be fixed.

RytoEX avatar Apr 10 '24 19:04 RytoEX

Confirming that I can now build and run in Debug, RelWithDebInfo, and Release on Windows 11. cmake-format is still failing on cmake/finders/FindLibx264.cmake though, so that will need to be fixed.

That was just me waiting for confirmation that the bug was actually fixed - pushed an update for formatting just now.

PatTheMav avatar Apr 10 '24 23:04 PatTheMav

@PatTheMav and I did some off-thread testing and debugging and found a few lingering items to fix up. Will re-check this "soon".

RytoEX avatar Apr 13 '24 18:04 RytoEX