We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4185

Summary: CMake build doesn't locate X headers correctly under FreeBSD without manual CFLAGS
Product: SDL Reporter: Mahmoud Al-Qudsi <mqudsi>
Component: buildAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: icculus
Version: HG 2.1   
Hardware: x86_64   
OS: FreeBSD   

Description Mahmoud Al-Qudsi 2018-06-01 18:48:08 UTC
```
~> mkdir build; cd build
~> cmake ..
-- Looking for include files X11/Xlib.h, X11/extensions/xf86vmode.h
-- Looking for include files X11/Xlib.h, X11/extensions/xf86vmode.h - not found
-- Looking for 3 include files X11/Xlib.h, ..., X11/extensions/Xext.h
-- Looking for 3 include files X11/Xlib.h, ..., X11/extensions/Xext.h - not found
CMake Error at cmake/macros.cmake:28 (message):
  *** ERROR: Missing Xext.h, maybe you need to install the libxext-dev
  package?
Call Stack (most recent call first):
  cmake/sdlchecks.cmake:401 (message_error)
  CMakeLists.txt:977 (CheckX11)
```

but the file exists in the default location:

```
mqudsi@freebsd12 ~/S/build> fd Xext.h /usr/local
/usr/local/include/X11/extensions/Xext.h
```

This can be worked around by manually specifying the include directory:

```
~> env CFLAGS=-I/usr/local/include cmake ..
```

But presumably this isn't something that should need to be manually specified as that is a "default" include directory under FreeBSD (not a default hardcoded into clang/clang++, but a "default" for the platform in that CMake should be able to pick up on this dependency with the user having to specify it manually).
Comment 1 Ryan C. Gordon 2018-06-25 05:50:25 UTC
This happens because the configure script uses AC_PATH_X to figure this out with a bunch of internal magic, but CMake doesn't.

I've fixed this up to look at the most popular places for the headers to exist (largely taken from CMake's FindX11 module, which we currently don't use and which also didn't know to look in /usr/local, as of 3.5.2), and some other fixes here: https://hg.libsdl.org/SDL/rev/c0c4ba22a685

Tested on FreeBSD 9, this went from completely broken to able to build X11 support with this patch, so I think we're good here.

--ryan.
Comment 2 Mahmoud Al-Qudsi 2018-06-25 15:08:59 UTC
Awesome, thanks!