[CMake] Proposed fix for the FindX11.cmake triplication annoyance

Alan W. Irwin irwin at beluga.phys.uvic.ca
Fri Aug 3 13:27:25 EDT 2007


On Linux (at least for both my Debian and Ubuntu platforms), FindX11.cmake
sets X11_INCLUDE_DIR to /usr/include;/usr/include;/usr/include.

This triplication is an annoyance at least in the case where you are using
SET_SOURCE_FILES_PROPERTIES to set the -I compiler flags (as we do for the
subset of the PLplot source files which depend on X) because you then
end up with triplicate -I/usr/include options for the compiler which (unless
the compiler itself ignores duplicate -I flags) causes compilation
inefficiencies as the same /usr/include directory is searched three times for
header files.

N.B. I am well aware that you don't need the -I/usr/include flag at all on
most/all Linux platforms.  I am also aware that FindX11.cmake violates the
readme.txt standard for Find modules.  However, please ignore those issues
for now and focus here on the triplication issue.

The source of the triplication is the following code in FindX11.cmake.

   FIND_PATH(X11_X11_INCLUDE_PATH X11/X.h ${X11_INC_SEARCH_PATH})
   FIND_PATH(X11_Xlib_INCLUDE_PATH X11/Xlib.h ${X11_INC_SEARCH_PATH})
   FIND_PATH(X11_Xutil_INCLUDE_PATH X11/Xutil.h ${X11_INC_SEARCH_PATH})
[...]
   IF(X11_X11_INCLUDE_PATH)
     SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_X11_INCLUDE_PATH})
   ENDIF(X11_X11_INCLUDE_PATH)

   IF(X11_Xlib_INCLUDE_PATH)
     SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xlib_INCLUDE_PATH})
   ENDIF(X11_Xlib_INCLUDE_PATH)

   IF(X11_Xutil_INCLUDE_PATH)
     SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xutil_INCLUDE_PATH})
   ENDIF(X11_Xutil_INCLUDE_PATH)

The question I have is whether there is _any_ platform left where X is
distributed with X.h, Xlib.h, and Xutil.h in different directories?  If
there is no possibility of that any more, then the above code could be
vastly simplified to

FIND_PATH(X11_INCLUDE_DIR X11/X.h ${X11_INC_SEARCH_PATH})

since it appears (at least on my platforms) that X11/Xutil.h includes
X11/Xlib.h and that file in turn includes X11/X.h so it is redundant to
search for the X11/Xlib.h and X11/Xutil names since those files are
not independent of X11/X.h.

I would appreciate comment from the X experts here about whether the
proposed simplification would break any X platform that exists today. The
attached patch should serve as a concrete basis for discussion of such
simplification, and I have verified it gives correct results (with no
triplication) at least on my platforms.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list