Issue
I would like to parse a file (XML, JSON or similar) in my CMakeLists and set some variables accordingly.
For example, say I have the following file:
<root>
<Object>
<name = "my_name"/>
<url = "my_url"/>
</Object>
<Object>
<name = "another_name"/>
<url = "another_url"/>
</Object>
</root>
and then in my CMakeLists I would like to set a variable with all the names and another variable with all the urls.
Is that possible? I haven't found much on this topic.
Solution
CMake does not provide an json or XML parser by itself. However you can use tool like jq or xmlstarlet. You can call the tools with execute_process or add_custom_command from CMake depending on your needs.
jq: https://stedolan.github.io/jq/
xmlstarlet: http://xmlstar.sourceforge.net/overview.php
Answered By - Finn