ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Using multiple library versions in catkin

asked 2017-12-09 06:54:11 -0500

MohsenTamiz gravatar image

updated 2017-12-09 06:56:22 -0500

For some test purposes I had to define some pre-processors that create different classes for test or non-test modes. For using in a single package this approach is sufficient and we could define pre-processors definitions in CMakeLists for test or regular executable.

But If I export a library from a catkin package, I confused how could I have different libraries export form a single catkin package to able to use the test version of the library.

For example assume I have a package A:

project(A)
catkin_package(
  LIBRARIES A
)    
add_library(A src/foo.cpp src/A.cpp)    
if (CATKIN_ENABLE_TESTING)
  catkin_add_gtest(test_A test/test_A.cpp src/foo.cpp src/A.cpp)          
  target_compile_definitions(test_A PRIVATE some_macro=true)
endif()

And another B package:

project(B)    
find_package(catkin REQUIRED COMPONENTS
                    A)
catkin_package(
)    
add_executable(B src/bar.cpp src/B.cpp)
target_link_libraries(B ${catkin_LIBRARIES})    
if (CATKIN_ENABLE_TESTING)
  catkin_add_gtest(test_B test/test_B.cpp src/bar.cpp src/B.cpp)          
  target_compile_definitions(test_B PRIVATE some_macro=true)
  target_link_libraries(test_B ${catkin_LIBRARIES})
endif()

The problem arises when we want to build test_B target, we must have a test version of library A but we could not able to export another test library using catkin, in fact, we could but all of them exported at once we could not define which one must use in which case.

Is there anyway to define some customized behavior for catkin package or do you have other suggestions for have a test version of a library?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-01-02 13:20:17 -0500

Dirk Thomas gravatar image

The exported variable <pkgname>_LIBRARIES should contain the library downstream packages are commonly supposed to use. In your case I would say the non-test library.

Your package can optionally define any arbitrary CMake variable. So it could set a variable <pkgname>_TEST_LIBRARIES. Since this is not a "standard" use case you need to do that in your own CMake file which you can register using the CFG_EXTRAS argument of the catkin_package function. Downstream packages must than choose to use that CMake variable instead in order to get the test version of your libraries.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-12-09 06:54:11 -0500

Seen: 436 times

Last updated: Jan 02 '18