Search code examples
cmakedrake

Are there any tutorials or example code to get a drake simulator project running in c++ using a CmakeLists.txt file?


I want to experiment with the new drake simulator, however I do not want to build projects exclusively in the drake install folder under "examples" using exclusively bazel, the reason for this is I want to create a program that can handle multiple physics simulators with some basic functionality (loading models, setting controls etc.). To achieve this I need everything building from one CMakeLists.txt file.

I cant seem to find any examples for a really basic drake project compiled with cmake, even if it was using cmake to compile bazel just for drake.

Any help would be greatly appreciated.

I tried using find_package(drake REQUIRED) in cmake and it could not find drake-config.cmake.

-------- my cmake code ----------

list(APPEND CMAKE_PREFIX_PATH /home/dave/projects/drake/tools/install/libdrake)
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
find_package(drake REQUIRED)

-------- error ---------------

CMake Error at CMakeLists.txt:28 (find_package):
  By not providing "Finddrake.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "drake", but
  CMake did not find one.

  Could not find a package configuration file provided by "drake" with any of
  the following names:

    drakeConfig.cmake
    drake-config.cmake

  Add the installation prefix of "drake" to CMAKE_PREFIX_PATH or set
  "drake_DIR" to a directory containing one of the above files.  If "drake"
  provides a separate development package or SDK, be sure it has been
  installed.

Solution

  • The https://github.com/RobotLocomotion/drake-external-examples shows up-to-date samples for how to use Drake as a library from your own CMake project.

    The drake_cmake_installed or drake_cmake_installed_apt shows the case of using a pre-compiled Drake stable releases. This is usually the best way, it is fast and uses a stable release of Drake.

    The drake_cmake_external shows how to build Drake from source, as an external to your own project. This usually takes a long time to build, but might be helpful if you need to customize the build flags.

    Looking at your example code specifically, the problem there is trying to point CMAKE_PREFIX_PATH into a Drake source tree. That variable needs to point to an installed copy of Drake, either one downloaded per https://drake.mit.edu/installation.html or else one build from source (ala drake_cmake_external).