Using multiple library versions in catkin
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?