How to parse CMakeLists.txt in python [closed]
I'm building automatic tests in python for my ROS project and I want to check certain elements inside the CMakeLists.txt during the tests. I want to check if CMakeLists.txt is written correctly in order for it to work with my code (required parameters set etc.).
I have spend a whole day implementing my own CMakeLists Parser that would return a dictionary of elements, but I failed as I don't understand the syntax of CMakeLists well enough. I could probably obtain the information I am looking for in the file, but there would be no guarantee unless the parser is totally universal.
I was looking for already implemented solution before I started to implementing my own, but couldn't find any. There are parsers that allows me to generate the CMakeLists, but not read it. Or I didn't find the documentation for this use case.
What do you use for reading CMakeLists.txt? What would you recommend me to use?
I'm sorry, but in its current form this is not a question for ROS Answers, as it's purely about CMake and parsing
CMakeLists.txt
.I'm going to close this and recommend you post it elsewhere.
Have you seen catkin_lint btw?
@gvdhoorn Thank you, I didn't see this. I specifically need to get elements of the list defined in CMakeLists.txt by construction
I went through the website and it doesn't look like this package enables this.
I suggested taking a look at
catkin_lint
as it may already cover 80% of your use case (ie: checking ROS Catkin packages for mistakes/errors).The
catkin_lint
module surely contains functionality for parsingCMakeLists.txt
(as that is what it needs itself), but you would have to try and .... see whether you can use/extract that for your own purposes.
A quick look at the
catkin_lint
module lets me believe that cmake.py could be very relevant.