diff --git a/cmake/VarsFromFile.cmake b/cmake/VarsFromFile.cmake index e41f577..6b9e8b8 100644 --- a/cmake/VarsFromFile.cmake +++ b/cmake/VarsFromFile.cmake @@ -1,13 +1,15 @@ function(VarsFromFile filename) - file(STRINGS ${filename} ConfigContents) - foreach(NameAndValue ${ConfigContents}) - # Strip leading spaces - string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue}) - # Find variable name - string(REGEX MATCH "^[^=]+" Name ${NameAndValue}) - # Find the value - string(REPLACE "${Name}=" "" Value ${NameAndValue}) - # Set the variable - set(${Name} "${Value}" PARENT_SCOPE) - endforeach() + if (EXISTS ${filename}) + file(STRINGS ${filename} ConfigContents) + foreach(NameAndValue ${ConfigContents}) + # Strip leading spaces + string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue}) + # Find variable name + string(REGEX MATCH "^[^=]+" Name ${NameAndValue}) + # Find the value + string(REPLACE "${Name}=" "" Value ${NameAndValue}) + # Set the variable + set(${Name} "${Value}" PARENT_SCOPE) + endforeach() + endif () endfunction(VarsFromFile) \ No newline at end of file