Loading and exporting a .so file with CMake

asked 2021-10-06 08:37:07 -0500

I am attempting to link a ROS project to an external dependency (Gocator SDK or GoSdk) as responsibly as possible. In my current environment (which uses docker), when an external dependency needs to be added, the repo for that dependency is added to a list of external repos (in this case I had to make my own git repo since one didn't already exist), then those repos are compiled as catkin packages, which will finally be fetched by all the various packages in my project as needed. I would like to use the same process for GoSdk, but as I will describe this task would be fairly convoluted.

GoSdk (and an associated dependency, kApi) is compiled by two rather long Makefiles which I would prefer not to touch, so my approach is to run these Makefiles through my CMakeLists.txt file as custom commands, as follows:

cmake_minimum_required(VERSION 3.0.2)

find_package(catkin REQUIRED)

# This is system dependent, it assumes linux_x86d
add_custom_target(go_sdk_build ALL make -f GoSdk-Linux_X86.mk
add_custom_target(k_api_build ALL make -f kApi-Linux_X86.mk

catkin_package(LIBRARIES GoSdk)
set_target_properties(GoSdk PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../../build/GoSdk/lib/linux_x86d/libGoSdk.so)

This currently does not work, as when I try to include GoSdk in a find_package(catkin REQUIRED COMPONENTS ... line it gives me the following error:

Project 'foo' tried to find library 'GoSdk'. The library is neither a target nor built/installed properly. Did you compile project 'GoSdk'? Did you find_package() it before the subdirectory containing its code is included?

To recap, I am trying to compile a dependency by calling two Makefiles and then loading the resulting .so file from a CMakeLists.txt file, which will then act as a catkin package, so that I can then find this dependency from my project within its own CMakeLists.txt file using catkin, all so I can use this dependency from my cpp code. This all seems convoluted and not how the pipeline is meant to be used. If you can tell me how to fix my approach it'd be much appreciated!

edit retag flag offensive close merge delete


This all seems convoluted and not how the pipeline is meant to be used

it is convoluted.

Do you absolutely need this to be a "catkin package"? If not, and all you really want is for it to be usable as a system dependency, then why try make it a Catkin package?

gvdhoorn gravatar image gvdhoorn  ( 2021-10-07 02:58:11 -0500 )edit