Only try to read file if it exists

This commit is contained in:
2024-05-22 12:19:45 +02:00
parent d896e8f29a
commit 4f539e786c

View File

@@ -1,13 +1,15 @@
function(VarsFromFile filename) function(VarsFromFile filename)
file(STRINGS ${filename} ConfigContents) if (EXISTS ${filename})
foreach(NameAndValue ${ConfigContents}) file(STRINGS ${filename} ConfigContents)
# Strip leading spaces foreach(NameAndValue ${ConfigContents})
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue}) # Strip leading spaces
# Find variable name string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
string(REGEX MATCH "^[^=]+" Name ${NameAndValue}) # Find variable name
# Find the value string(REGEX MATCH "^[^=]+" Name ${NameAndValue})
string(REPLACE "${Name}=" "" Value ${NameAndValue}) # Find the value
# Set the variable string(REPLACE "${Name}=" "" Value ${NameAndValue})
set(${Name} "${Value}" PARENT_SCOPE) # Set the variable
endforeach() set(${Name} "${Value}" PARENT_SCOPE)
endforeach()
endif ()
endfunction(VarsFromFile) endfunction(VarsFromFile)