How to parse CMakeLists.txt in python [closed]

asked 2018-11-15 10:13:54 -0600

kump gravatar image

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?

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant. Please see http://wiki.ros.org/Support for more details. by gvdhoorn
close date 2018-11-15 10:46:16.182035

Comments

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.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-15 10:46:02 -0600 )edit

Have you seen catkin_lint btw?

gvdhoorn gravatar image gvdhoorn  ( 2018-11-15 10:46:47 -0600 )edit

@gvdhoorn Thank you, I didn't see this. I specifically need to get elements of the list defined in CMakeLists.txt by construction

set(LIST_NAME
      element1
      element2
      etc
)

I went through the website and it doesn't look like this package enables this.

kump gravatar image kump  ( 2018-11-16 02:15:57 -0600 )edit

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_lintmodule surely contains functionality for parsing CMakeLists.txt (as that is what it needs itself), but you would have to try and ..

gvdhoorn gravatar image gvdhoorn  ( 2018-11-16 02:19:47 -0600 )edit

.. 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.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-16 02:20:31 -0600 )edit