Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: Fix compiler flags from FindWayland and FindPipeWire #6205

Merged
merged 2 commits into from
Apr 14, 2022

Conversation

Arthus
Copy link
Contributor

@Arthus Arthus commented Mar 25, 2022

${WAYLAND_DEFINITIONS} is set to "-I/usr/include/wayland" on my system

Setting it as INTERFACE_COMPILE_DEFINITIONS leads to CMake emitting "-D-I/usr/include/wayland" in the compiler flags
this breaks the compilation

Instead add WAYLAND_DEFINITIONS as compile option so it just gets appended without adding the superflours "-D"

Description

Motivation and Context

I was trying to compile OBS for the first time using openSUSE Tumbleweed. I was able to set the dependencies and cmake up, but during compilation GCC throws an error:

<command-line>: error: macro names must be identifiers

This is caused by cmake emitting
cd /home/user/Programming/OBS/obs-studio/build/libobs && /usr/bin/cc -D-I/usr/include/wayland -DENABLE_DARRAY_TYPE_TEST [...]
-D makes gcc wait for a macro, but instead the include flag follows immediately.

To fix it we just have to tell cmake to not interpret WAYLAND_DEFINITIONS as macro definition, but only append it to the compiler flags. (This is inline with what is done in FindPipeWire.cmake.)

This issue was likely introduced by commit df94b02 from PR #5155

P.S.: First day of working with OBS and first patch. I've tried following all contributor guidelines, but please tell me if I could've done better. :)

How Has This Been Tested?

With this commit I am able to compile OBS using openSUSE Tumbleweed on a Thinkpad P14s.
Snapshot 20220322 with CMake 3.22.2
Snapshot 20220323 with CMake 3.22.3
I'm able to launch the compiled binary on X11 and Wayland using KDE 5.24.3, do some simple screen capture using XSHM and Pipewire, record my desktop and click through menus.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

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

@WizardCM WizardCM added the Bug Fix Non-breaking change which fixes an issue label Mar 25, 2022
@WizardCM WizardCM requested a review from PatTheMav March 25, 2022 04:06
@PatTheMav
Copy link
Member

The fix is correct insofar as WAYLAND_DEFINITIONS contains the CFLAGS as reported by pkg-config.

I'd prefer if the variable is renamed as well, to avoid the confusion introduced by the fix ("definitions" being set as compiler options).

Copy link
Member

@PatTheMav PatTheMav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also rename WAYLAND_DEFINITIONS to something like WAYLAND_COMPILE_FLAGS.

@Arthus
Copy link
Contributor Author

Arthus commented Mar 26, 2022

I've renamed WAYLAND_DEFINITIONS as requested and also added a commit to rename PIPEWIRE_DEFINITIONS as all your comments also apply to that one.

Question:
Is it ok to have two commits for that, should I squash them or even open another PR?

@PatTheMav
Copy link
Member

Multiple commits is fine, but I'd suggest splitting the changes between one commit for Wayland and another for PipeWire.

@Arthus
Copy link
Contributor Author

Arthus commented Mar 26, 2022

Hi, sorry, just force pushed the commits again after some fiddling with git.

It's just as you've proposed: One commit makes the changes for pipewire. The other one fixes the compilation with wayland and also renames the wayland variable. :)

@PatTheMav
Copy link
Member

Minor nit to pick: One commit explicitly mentions Wayland, the other doesn't. I'd suggest renaming the commit to explicitly call out that it changes something related to PipeWire.

@Arthus
Copy link
Contributor Author

Arthus commented Mar 29, 2022

Done :)

Copy link
Member

@RytoEX RytoEX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpicks on the commit messages.

Use a capitalized word immediately after the commit message prefix. Punctuate paragraphs in the commit message body correctly.

The first commit doesn't seem to have anything to do directly with libobs, so mentioning it is confusing. The changes are just in our CMake finders, so I don't think it makes sense to mention libobs, unless you can elaborate?

@Arthus
Copy link
Contributor Author

Arthus commented Mar 30, 2022

One more try...

Regarding the first commit: CMake is perfectly happy with the current state of FindWayland. The error manifests later during libobs-* compilation when gcc needs to interpret cmake's output.
So I think mentioning what is actually fixed in the commit message is a sensible thing to do. The commit fixes the compilation of libobs-* which fails otherwise. Although the fix happens in FindWayland.cmake

If you still don't like it, please propose an alternative to get it merged.

@Arthus Arthus requested a review from RytoEX March 30, 2022 12:24
@RytoEX RytoEX self-assigned this Apr 12, 2022
If WAYLAND_DEFINITIONS is set to "-I/usr/include/wayland", setting its
value as INTERFACE_COMPILE_DEFINITION leads to CMake emitting
"-D-I/usr/include/wayland" in the compiler flags. This breaks the
compilation of targets that call find_package(Wayland), such as libobs
and libobs-opengl, in gcc.

To avoid this, rename WAYLAND_DEFINITIONS to WAYLAND_COMPILE_FLAGS to
reflect that it contains ready-to-use compiler flags. Use
WAYLAND_COMPILE_FLAGS as INTERFACE_COMPILE_OPTIONS so it just gets
appended without adding the superfluous "-D".
@RytoEX RytoEX added this to the OBS Studio 28.0 milestone Apr 14, 2022
PIPEWIRE_DEFINITIONS contains ready-to-use compile flags. If used with
INTERFACE_COMPILE_DEFINITIONS, this can lead to a compile error.

Rename the variable to PIPEWIRE_COMPILE_FLAGS to be clear about that and
prevent accidental misuse.
@RytoEX RytoEX changed the title cmake: fix compiler flag in libobs-* with wayland cmake: Fix compiler flags from FindWayland and FindPipeWire Apr 14, 2022
Copy link
Member

@RytoEX RytoEX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've adjusted the commit messages and the PR title. Merging shortly.

@RytoEX RytoEX merged commit b94e960 into obsproject:master Apr 14, 2022
@Arthus Arthus deleted the first_steps branch April 17, 2022 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Fix Non-breaking change which fixes an issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants