file(STRINGS ...) with empty filename does not fail

All of the following do not fail and return an empty string (tested with CMake 3.22.1):

file(STRINGS "${nonexistent}" content)
message("content: '${content}'")

file(STRINGS "" content)
message("content: '${content}'")

file(STRINGS "/" content)
message("content: '${content}'")

file(STRINGS "." content)
message("content: '${content}'")

Interestingly file(READ ...) behaves a bit different and returns a single newline character instead:

file(READ "" content)
message("content: '${content}'")

file(READ "/" content)
message("content: '${content}'")

file(READ "." content)
message("content: '${content}'")
1 Like