frankaemika / libfranka

C++ library for Franka research robots
https://frankaemika.github.io
Apache License 2.0
221 stars 147 forks source link

[proposed enhancement] CMake: Check for available targets before find_package #132

Open SchneiderROS opened 1 year ago

SchneiderROS commented 1 year ago

Hi there,

I'm unsing libfranka within my own project. Like libfranka my project uses the Eigen library and therefore Eigen is already a target in my cmake generation step. If I now include libfranka to my project with FetchContent, the libfranka CMakeLists.txt is executed and does a find_package(Eigen3 REQUIRED). The find_package tries to find Eigen in the system directories (global install) and does not incorporate the Eigen target that I already have. The find_package fails and the libfranka installation is aborted. I Don't want to install Eigen system wide and I think I am not the only one that want to have everything local and clean. If libfranka just checks if the target is already available before doing a find_package, this rough behavior could be eliminated.

Therefore I propose to replace the CMakeLists.tex line 29 find_package(Eigen3 REQUIRED) with if (NOT TARGET Eigen3::Eigen3) find_package(Eigen3 REQUIRED) endif()

I tested this modification locally and works well.