The built executable runs fine on MacOS. But on ubuntu 20.04.2 it generates this error:
% mbgrdviz
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 19 (X_DeleteProperty)
Resource id in failed request: 0x0
Serial number of failed request: 119
Current serial number in output stream: 123
the resulting executable runs fine on both MacOS and ubuntu.
What’s the difference between the “imported target” and “variables” approaches? I.e. instead of “Motif::Motif X11:Xt” I specify “${MOTIF_LIBRARIES} ${X11_LIBRARIES} and ${X11_Xt_LIB}” to target_link_libraries(). Why would the imported target approach work on MacOS but fail on ubuntu?
In general, always prefer to use imported targets over variables. The imported targets also provide things like header search paths, compiler defines, etc. which the variables don’t.
In this case, the list of libraries you link using variables appears to be different to the list of imported targets. Perhaps you are missing X11::X11 in your list of imported targets?
You can see the list of libraries the variables would pull in by adding the following line to your project:
As to why this results in different behavior at runtime, it may relate to libraries that are dynamically loaded at runtime rather than linked, but that’s just a guess. Let’s see what the above output reveals.
That’s not generally available as the transitive closure needs to be queried manually. But you can ask the targets for their INTERFACE_INCLUDE_DIRECTORIES and INTERFACE_LINK_LIBRARIES properties to take a peek.
By the way, once you figure out what is missing, it might be worth filing an issue so that FindX11 can encode this in these properties for macOS/Quartz usage.
Thanks @ben.boeckel - pardon my newbie-ness but how exactly would I modify my CMakeLists.txt to peek into INTERFACE_INCLUDE_DIRECTORIES and INTERFACE_LINK_LIBRARIES to see what’s provided by the X11 and Motif packages? I.e. I currently have: