Auto generation of ros messages: Cmaklists add_message_files not detecting variable

asked 2021-07-26 18:34:48 -0500

praskot gravatar image

Hi,

I'm autogenerating ros-messages (ROS1) using a python script. Since there are many (about 100+) ros messages, I'm trying to automate the CMakelists.txt add_message_files. Tried the following two options, but neither is working as needed.

  1. add_message_files(DIRECTORY msg) this method works well when compiling the package for the first time, but it doesn't track any new *.msg files that I create later on or update the existing *.msg files. I have to clear the build and build the package anew.

  2. Alternately, I tried reading the list of *.msg files and storing it a variable as follows,

    file(GLOB msg_files CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/msg/*.msg")
    set(MSG_FILE_NAMES "")
    list (SORT msg_files)
    foreach (_variableName ${msg_files})
      get_filename_component(msg_name ${_variableName} NAME)
      message(STATUS "${msg_name}")
      set(MSG_FILE_NAMES "${MSG_FILE_NAMES} ${msg_name}")
    endforeach()
    message(STATUS "${MSG_FILE_NAMES}")
    add_message_files( FILES ${MSG_FILES_NAMES}
    )
    

but CMakelists does not recognize the variable MSG_FILES_NAMES. I get

CMake Warning at *-genmsg.cmake:3 (message):
  Invoking generate_messages() without having added any message or service
  file before.

  You should either add add_message_files() and/or add_service_files() calls
  or remove the invocation of generate_messages().

I also modified the line set(MSG_FILE_NAMES "${MSG_FILE_NAMES} ${msg_name}") with list(APPEND ${MSG_FILE_NAMES} ${msg_name}) and still the same warning.

One other alternative I can think of is modifying the CMakeLists.txt file externally and updating it with new *.msg files every time I generate new files.

Look for forwarding to any suggestions/thoughts.

Thank you

edit retag flag offensive close merge delete