I have a project where the CMakeLists.txt attempts to read a file which may or may not be present. It is not a problem for the file to be missing and the script handles either case. This is used to tweak the compilation environment slightly if we can detect a known Linux distribution:
file (READ /etc/redhat-release RHREL)
if (RHREL MATCHES "Red Hat Enterprise Linux Server release 6*")
# tweak for RHEL6
elseif (RHREL MATCHES "Red Hat Enterprise Linux Server release 7*")
# tweak for RHEL7
else()
# either read failed, or we didn't match a known RHEL release
# fallback to reasonable defaults
endif()
The problem is that when file(READ...) fails it seems to be outputting a message using the SEND_ERROR parameter. This means that my configuration continues into the catch-all else() as I expect, but at the end of configuration CMake refuses to generate a Makefile.
How can I run file(READ) in such a way that I can cope with errors locally and prevent them from failing the entire configuration?