我的项目由许多组件组成。每个文件都依赖于使用外部工具从*.hpp
生成的一个或多个*.lcm
文件。我希望能够指定每个组件需要哪些*.lcm
文件的列表,并让CMake在需要时自动进行编译,也许使用漂亮的小宏指定:
REQUIRED_LCMS (the_component x.lcm z.lcm)
对于*.lcm
的编译,我认为以下内容应该有效:
ADD_CUSTOM_COMMAND (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${lcm_basename}.hpp
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${lcm}
COMMAND "lcm-gen"
ARGS "--lazy --cpp ${CMAKE_CURRENT_SOURCE_DIR}/${lcm}"
COMMENT " ${lcm} -> ${lcm_basename}.hpp")
......但我不确定REQUIRED_LCMS
应该是什么。 ADD_CUSTOM_COMMAND
和ADD_CUSTOM_TARGET
?
答案 0 :(得分:3)
通过执行以下操作,我设法使其工作,没有细粒度(即每lcm文件依赖性):
SET (LCM_MESSAGES x.lcm
y.lcm
z.lcm)
SET (LCM_COMPILED_MESSAGES)
FOREACH (_file ${LCM_MESSAGES})
GET_FILENAME_COMPONENT (_filewe ${_file} NAME_WE)
STRING (TOUPPER ${_filewe} _FILEWE)
SET (_filehpp ${_filewe}.hpp)
SET (_filehpp_output ${CMAKE_CURRENT_BINARY_DIR}/${_filehpp})
ADD_CUSTOM_COMMAND (OUTPUT ${_filehpp_output}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
COMMAND lcm-gen
ARGS --lazy --cpp ${CMAKE_CURRENT_SOURCE_DIR}/${_file})
LIST (APPEND LCM_COMPILED_MESSAGES ${_filehpp_output})
ENDFOREACH ()
ADD_CUSTOM_TARGET (LCM_MESSAGES DEPENDS ${LCM_COMPILED_MESSAGES})
...然后在每个组件的CMakeLists.txt中:
ADD_DEPENDENCIES (the_component LCM_MESSAGES)