[英]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.