Theoretically, cmake can check for the existence of a file

if(EXISTS "/dev/spidev0.0")

according to the documentation this should be True if the named file or directory exists. Behavior is well-defined only for full paths., but I found that the said condition fails if the user has neither read not write rights on that file. If I add the permissions, it works.

However, the user that builds the project is not supposed to access the device, so the file permissions are zero for him. The built software will run under a different account with SPI access, so the corresponding module is to be build if the device file is found. test -e /dev/spidev0.0 is true, but cmake seems to do test -r.

As a workaround, I can check for the symlink in /sys/class/spidev/spidev0.0, but what's the correct way to handle the problem?

  • I’m curious — why does the build vary depending on the presence of a device? Would it not be possible to build the project with SPI support in all cases, and check for the presence of the device at runtime? After all, software can be built on one system for use on another, with different devices, or a device can come and go during a system’s lifetime... – Stephen Kitt Apr 10 '18 at 11:47
  • You are mainly right. During development, the software is build and tested on a variety of devices (Jenkins build slaves). It's a lazy way of handling the features along with their tests in cmake. And there is a whole bunch of similar switches! We probably won't keep this after market release. – Philippos Apr 10 '18 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.