我在Cmake中添加外部github项目时遇到问题。 目的是在ROS(Catkin)项目中使用github包ACADO。 安装说明可在此处找到: http://acado.github.io/install_linux.html
请下载工具包代码。我们的建议是永远克隆 稳定的分支:
git clone https://github.com/acado/acado.git -b stable ACADOtoolkit
转到ACADOtoolkit文件夹并为其创建构建文件夹 源外构建:
cd ACADOtoolkit mkdir build cd build
运行CMake以生成makefile并开始构建过程:
cmake .. make
要使用此软件包,我想将ACADOtoolkit下载到 文件夹并在那里构建:
catkin_ws/src/myProj/thirdparty/
因此我将ACADOtoolkit添加为外部项目。 我必须将项目克隆到第三方文件夹中,以便我得到:
catkin_ws/src/myProj/thirdparty/ACADOtoolkit
之后我必须创建一个构建文件夹 catkin_ws / src目录/的Myproj /第三方/ ACADOtoolkit /编译 而不是建立项目:
cd catkin_ws/src/myProj/thirdparty/ACADOtoolkit/build
cmake ..
make
我可以使用以下方法成功地将项目下载到catkin_ws / src / myProj / thirdparty /:
ExternalProject_Add(acadooo
DOWNLOAD_COMMAND git clone https://github.com/acado/acado.git -b stable ACADOtoolkit
DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/
)
不幸的是我之后无法使用
构建系统 ExternalProject_Add(acado
DOWNLOAD_COMMAND git clone https://github.com/acado/acado.git -b stable ACADOtoolkit
DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/
BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ACADOtoolkit/build/
BUILD_COMMAND make
)
因为应在ACACADOtoolkit文件夹中创建构建文件夹 因此我收到了
destination path 'ACADOtoolkit' already exists and is not an empty directory.
同样在源中构建也会出现同样的错误。
ExternalProject_Add(acado
DOWNLOAD_COMMAND git clone https://github.com/acado/acado.git -b stable ACADOtoolkit
DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/build/
BUILD_COMMAND make
BUILD_IN_SOURCE 1
)
此外,每次我想构建项目时, 之前必须删除该目录。 任何想法如何解决这些问题并在源代码中构建?
答案 0 :(得分:1)
目的是在ROS(Catkin)项目中使用github包ACADO。
如果这是您的主要目标,我建议您在工作区之外单独构建ACADO,然后在ROS包中实现它,包括它作为依赖项。我已成功完成此操作,因此我将回答此解决方案。
我对你提议的这个解决方案的理由是,ACADO是一个外部库,你(我假设)不会自己重新编码,因此每次重新构建它都没有意义。构建您的工作区,也不要在程序包中包含您自己的自定义代码。
无论如何,这就是你需要的......
加入构建依赖:
<build_depend>acado</build_depend>
在find_package( catkin REQUIRED COMPONENTS ...
来电插入后
find_package(ACADO REQUIRED)
find_package(Eigen3 REQUIRED)
加入catkin_package
来电:
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES
# CATKIN_DEPENDS
DEPENDS ACADO
)
然后直接:
###########
## Build ##
###########
link_directories(${ACADO_LIBRARY_DIRS})
## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include)
include_directories(
include/${PROJECT_NAME}
${catkin_INCLUDE_DIRS}
${ACADO_INCLUDE_DIRS}
${Eigen_INCLUDE_DIRS}
)
以下是使用ACADO库的名为 test 的可执行文件的示例:
# Declare a C++ executable
# With catkin_make all packages are built within a single CMake context
# The recommended prefix ensures that target names across packages don't collide
add_executable(${PROJECT_NAME}_test src/test.cpp)
# Rename C++ executable without prefix
# The above recommended prefix causes long target names, the following renames the
# target back to the shorter version for ease of user use
# e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
set_target_properties(${PROJECT_NAME}_test PROPERTIES OUTPUT_NAME test PREFIX "")
# Add cmake target dependencies of the executable
# same as for the library above
add_dependencies(${PROJECT_NAME}_test ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME}_test ${PROJECT_NAME}
${catkin_LIBRARIES}
${ACADO_SHARED_LIBRARIES}
)
如果您坚持通过catkin构建自动完成ACADO的整个克隆和安装,您可能希望将其置于脚本中并查看使用add_custom_command执行它(我没有试过这个但是我自己。)
但是我想重申一下这个论点,即外部库并不意味着包含在内容中并构建在包中。对于想要使用你的软件包的人来说,它假设他们负责满足构建依赖关系,这就是catkin的构建依赖关系所针对的,并且它不像ACADO有一个复杂的安装过程。