Skip to content

baselib_binding

Jennifer Buehler edited this page May 30, 2016 · 2 revisions

The baselib_binding package offers header files which help to easily switch between boost and std c++1 implementations.

Including this package in your CMake project

You can configure the architecture (boost or c++11) you want to use with a cmake flag.

You will need to add compiler definitions depending on which library you want to use.

find_package(baselib_binding REQUIRED)

add_definitions(${baselib_binding_DEFINITIONS})

# Or to use c++11 or boost explicitly, use either of:
# add_definitions(${baselib_binding_DEFINITIONS_BOOST})
# add_definitions(${baselib_binding_DEFINITIONS_STD})

include_directories(${baselib_binding_INCLUDE_DIRS})

# Link your targets
target_link_libraries(<your-target> ${baselib_binding_LIBRARIES})

# Or to use c++11 or boost explicitly, use either of:
# target_link_libraries(<your-target> ${baselib_binding_LIBRARIES_BOOST})
# target_link_libraries(<your-target> ${baselib_binding_LIBRARIES_STD})

You will need to make sure that cmake looks for configuration files in <install-prefix>/lib/baselib_binding/ (it will need to use <install-prefix>/lib/baselib_binding/baselib_bindingConfig.cmake). This should have been installed by baselib_binding, but if you used a custom installation <install-prefix>, you will have to pass it with CMAKE_PREFIX_PATH.

In order to switch between implementations, set the cmake variable baselib_binding_USE_BOOST (which a cache variable). Leave it on true (default) for using boost, or set it to false to use std c++11. For example:

cd <your-project>/build
cmake -Dbaselib_binding_USE_BOOST=false ..

will use the std c++11 implementation.

Tipp: If you are using catkin and want to automatically add the compile definitions to all depending packages, you can move the add_definitions directive to a cmake file, e.g. cmake/baselib_binding.cmake.in and add this cmake file as CFG_EXTRAS in your catkin_package(), so that depending packages include it as well.

catkin_package(
  ...
  CFG_EXTRAS baselib_binding.cmake.in
)

Alternatively to add_definitions in your exported cmake file, you can also do set(<your-own-package>_DEFINITIONS ${baselib_binding_DEFINITIONS} and require depending packages to include this in the compiler definitions.

Usage

To use thread and share pointer types, define the templated types as in this example:

    // define the types
    typedef baselib_binding::unique_lock<baselib_binding::mutex>::type unique_lock;
    typedef baselib_binding::shared_ptr<YourClassOrType>::type YourClassOrTypePtr;

    // declare variables
    unique_recursive_lock my_recursive_lock;
    YourClassOrTypePtr my_pointer;

For a list of all types, please refer to SharedPtr.h and Thread.h. Not all types from boost and std c++11 have been added there yet. The types will be extended in near future. If you have a particular request, please post it as an issue on this git repository.

Clone this wiki locally