[cmake-developers] inappropriate use of PATH_SUFFIXES in FindALSA?

Andriy Gapon avg at icyb.net.ua
Thu Feb 9 03:17:31 EST 2012


First a snippet taken from FindALSA.cmake from cmake-2.8.7:
find_path(ALSA_INCLUDE_DIR NAMES asoundlib.h
          PATH_SUFFIXES alsa
          DOC "The ALSA (asound) include directory"
)

If I understand correctly how find_path and PATH_SUFFIXES work, then it means
that if asoundlib.h has a full path of /some/dir/alsa/asoundlib.h, then
ALSA_INCLUDE_DIR will get a value of /some/dir/alsa.

I perceive this as a problem because typically (always?) the code that uses ALSA
includes <alsa/asoundlib.h> and not <asoundlib.h>.  And thus there would be a
mismatch between -I/some/dir/alsa and #include <alsa/asoundlib.h>.

Of course, it seems that the problem is frequently just masked, especially on
GNU/Linux systems, where /some/dir is actually /usr/include and this directory
has a magic property of being a system include directory.  So alsa/asoundlib.h
gets resolved relative to the implicit /usr/include and not to the explicit
/usr/include/alsa.

On other systems where asoundlib.h may reside in e.g.
/usr/local/include/alsa/asoundlib.h a compiler won't be able to find
alsa/asoundlib.h because /usr/local/include doesn't have any magic properties.

To summarize, if the C code actually includes alsa/asoundlib.h, then wouldn't it
be appropriate to use exactly the same path, alsa/asoundlib.h, with find_path
like this:
find_path(ALSA_INCLUDE_DIR NAMES alsa/asoundlib.h
          DOC "The ALSA (asound) include directory"
)
?

What do you think?
Thank you!
-- 
Andriy Gapon



More information about the cmake-developers mailing list