[英]Is there any way to link add_custom_command to a target defined in another directory with add_custom_target?
因为这是 ROS 工作区(机器人框架)的标准结构,所以我有以下两个目录:
ros/
|── DIR_A
│ ├── CMakeLists.txt
│ ├── package.xml
│ ├── README.md
│ ├── setup.py
│ └── src
│ ├── some_code.cpp
|── DIR_B
│ ├── CMakeLists.txt
│ ├── package.xml
│ ├── README.md
│ ├── setup.py
│ └── src
│ ├── some_other_code.cpp
我正在尝试添加一个名为clean_compiled
的自定义目标,它将运行特定外部项目的make clean
目标(已经有效)。 但是我还需要在另一个目录的 CMakeLists 中向这个干净的目标添加一个自定义命令。 这就是我所拥有的:
首先 CMakeLists.txt:
# We add the custom target
add_custom_target(clean_compiled
COMMENT "Cleaning compilation files in ${SOME_DESTDIR}"
COMMAND $(MAKE) clean PATH=${SOME_DESTDIR}
WORKING_DIRECTORY ${SOME_WORKING_DIRECTORY}
)
第二个 CMakeLists.txt:
# We try to add a custom command to this custom target
add_custom_command(TARGET clean_compiled
COMMENT "Cleaning compilation files in ${ANOTHER_DESTDIR}"
WORKING_DIRECTORY ${ANOTHER_WORKING_DIRECTORY}
COMMAND $(MAKE) clean PATH=${ANOTHER_DESTDIR}
)
当我为整个存储库运行make clean_compiled
,我收到此警告:
TARGET 'clean_compiled' was not created in this directory.
This warning is for project developers. Use -Wno-dev to suppress it.
并且 custom_command 永远不会被调用。
有什么方法可以将自定义命令链接到另一个目录中的目标而不导致循环依赖?
add_custom_command
很清楚它只适用于同一目录中的目标。 没有办法解决这个问题。 所以第二条规则不能是自定义命令,需要是自定义目标,例如称为 clean_another_dest_dir。
https://discourse.cmake.org/t/create-target-that-only-runs-other-target/885/6
您可以使用add_dependency
使自定义目标依赖于其他自定义目标并使它们运行, add_dependencies(clean_another_dest_dir clean_compiled)
,但这并不总是您想要的。
另一种选择是运行所有其他自定义目标的自定义目标。
add_custom_target(clean_all_dir
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR } --target clean_compiled
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR } --target clean_another_dest_dir
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.