4

I have problems to add an external github project in Cmake. The aim is to use the github package ACADO in a ROS (Catkin) project. The installation instructions can be found here: http://acado.github.io/install_linux.html

Please download the toolkit code. Our suggestion is to always clone stable branch:

git clone https://github.com/acado/acado.git -b stable ACADOtoolkit

Go to ACADOtoolkit folder and create a build folder for an out-of-source build:

cd ACADOtoolkit  
mkdir build   
cd build

Run CMake to generate makefiles and start the building process:

cmake .. make

To use this package, I want to download the ACADOtoolkit to the folder and build it there:

catkin_ws/src/myProj/thirdparty/

For this reason I add the ACADOtoolkit as an external Project. I have to git clone the Project into the thirdparty folder, so that I get:

catkin_ws/src/myProj/thirdparty/ACADOtoolkit

afterwards I have to create a build folder catkin_ws/src/myProj/thirdparty/ACADOtoolkit/build and than build the project:

cd catkin_ws/src/myProj/thirdparty/ACADOtoolkit/build
cmake ..
make

I can succesfully download the project to catkin_ws/src/myProj/thirdparty/ by using:

 ExternalProject_Add(acadooo
   DOWNLOAD_COMMAND git clone https://github.com/acado/acado.git -b stable ACADOtoolkit
   DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/
 )

Unfortunately I cannot build the system afterwards with

 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 
 )

as the build folder should be created within the ACACADOtoolkit folder and therefore I receive

destination path 'ACADOtoolkit' already exists and is not an empty directory.

Also building in source ends in the same error.

 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
 )

Furthermore each time I want to build the project, the directory has to be deleted before. Any ideas how to resolve these Issues and build in source?

luator
  • 4,769
  • 3
  • 30
  • 51
DentOpt
  • 77
  • 1
  • 6
  • 1
    Given instructions **don't force** you to create build directory *under* source one. And it isn't definitely imply to use *in source* build, when build directory is *exactly* same as source one. You are free to use classic out-of-source build, without mess in directories. – Tsyvarev Feb 29 '16 at 13:58

2 Answers2

1

The aim is to use the github package ACADO in a ROS (Catkin) project.

If this is what your main goal is, I suggest you simply build ACADO separately outside of your workspace and then implement it in your ROS package, including it as a dependency. I have done this successfully and so I will answer with this solution.

My reasoning for this solution over your proposed one is that ACADO is an external library that you (I assume) wouldn't be re-coding yourself, therefore it does not make sense to re-build it every time you re-build your workspace, nor to include it with your own custom code in the package.

Anyway this is what you need...

pacakge.xml

Put in a build depend:

<build_depend>acado</build_depend>

CMakeLists.txt

After your find_package( catkin REQUIRED COMPONENTS ... call insert:

find_package(ACADO REQUIRED)
find_package(Eigen3 REQUIRED)

Include in your catkin_package call:

catkin_package(
# INCLUDE_DIRS include
# LIBRARIES 
# CATKIN_DEPENDS
 DEPENDS ACADO
)

And then directly after:

###########
## 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}
)

And here is an example of an executable named test which uses the ACADO library:

# 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}
)

If you're adamant on automating the entire clone-and-installation of ACADO through a catkin build, you may want to place this in a script and look at executing it with add_custom_command (I have not tried this myself however).

But I'd like to reiterate the argument that external libraries are not meant to be included and built in the package. For someone wanting to use your package, it as assumed they are responsible for meeting build dependencies, this is what catkin's build dependencies are for, and it's not like ACADO has a complicated installation process.

Peter w
  • 21
  • 3
0

This is an old question but for anyone who comes across this in the future, this has been released as a wrapper package for ROS2: https://index.ros.org/search/?term=acado_vendor&section=pkgs. For ROS1 noetic: https://index.ros.org/p/acado/github-clearpath-gbp-acado-release/#noetic

Joshua Whitley
  • 1,196
  • 7
  • 21