[cmake-developers] Limitations of IS_ABSOLUTE

Alan W. Irwin irwin at beluga.phys.uvic.ca
Thu Dec 20 21:43:07 EST 2012


My use case is I want to quickly test whether a data file that is external
to the source tree exists or not.  So I naively tried to use if(IS_ABSOLUTE
fullpathname) for this purpose, but all that tests at the current time is
whether fullpathname starts with a slash or not.  It does not test
whether fullpathname actually exists.

To demonstrate this limitation use the following test script

set(file /home/irwinx)
if(IS_ABSOLUTE ${file})
   message(STATUS "${file} is absolute")
else(IS_ABSOLUTE ${file})
   message(STATUS "${file} is not absolute")
endif(IS_ABSOLUTE ${file})

and run

cmake -p test.cmake

The result is

-- /home/irwinx is absolute

even though that absolute pathname does not exist.

I suspect this behaviour is by design and not a bug, but in that case
please change the documentation to say that IS_ABSOLUTE (unlike
IS_SYMLINK and IS_DIRECTORY) just checks for a leading "/" regardless
of whether the PATH exists or not so that users know the actual limits
to the usefulness of IS_ABSOLUTE.

I have brought this up because I think it is important to document the
limitations of IS_ABSOLUTE when the existence of IS_SYMLINK and
IS_DIRECTORY might lead the user to think there might be an existence
test with IS_ABSOLUTE.  Obviously for my use case it does look like a
reasonable alternative is to use file(GLOB...) followed by a check of
the result variable to see if it is empty.  But implementation of an
additional IF subcommand called IS_FILE which just checks for the
existence of the specified file would do this in fewer lines and does
seem to be a logical companion subcommand to IS_SYMLINK and IS_DIRECTORY.

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); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); 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-developers mailing list