我在cmake中添加外部github项目时遇到问题。
目的是在ros(catkin)项目中使用github包acado。
安装说明如下:
http://acado.github.io/install_linux.html
请下载工具包代码。我们的建议是永远克隆
稳定分支:
git clone https://github.com/acado/acado.git -b stable ACADOtoolkit
转到acadoolkit文件夹并为
源代码外生成:
cd ACADOtoolkit
mkdir build
cd build
运行cmake生成makefile并启动生成过程:
cmake .. make
要使用此软件包,我想将acadoolkit下载到
文件夹并在那里构建它:
catkin_ws/src/myProj/thirdparty/
为此,我将acadoolkit添加为外部项目。
我必须用git将项目克隆到第三方文件夹中,以便获得:
catkin_ws/src/myProj/thirdparty/ACADOtoolkit
之后我必须创建一个生成文件夹
catkin_ws/src/myproj/thirdparty/acadoolkit/构建
而不是建立项目:
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
)
而且每次我想做这个项目的时候,
必须先删除目录。
如何解决这些问题并构建源代码?
最佳答案
目的是在ros(catkin)项目中使用github包acado。
如果这是您的主要目标,我建议您只需在工作区之外单独构建acado,然后在ros包中实现它,包括将其作为依赖项。我已经成功地做到了,所以我会用这个解决方案来回答。
我对这个解决方案的理由是,acado是一个外部库,您(我假设)不会自己重新编写代码,因此,每次重新构建工作区时都重新构建它,或者将它与您自己的自定义代码一起包含在包中是没有意义的。
不管怎样这是你需要的…
pacakge.xml文件
放入生成依赖项:
<build_depend>acado</build_depend>
CmakeLists.txt文件
在您的呼叫插入之后:
find_package(ACADO REQUIRED)
find_package(Eigen3 REQUIRED)
包括在您的
find_package( catkin REQUIRED COMPONENTS ...
通话中: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的安装过程并不复杂。
关于git - CMake Git项目外部项目,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35700881/