yarp icon indicating copy to clipboard operation
yarp copied to clipboard

Unable to find `YARP::YARP_profiler` with `find_package`

Open GiulioRomualdi opened this issue 3 years ago • 2 comments
trafficstars

Describe the bug If I try to link link YARP_profiler to an application I got the following error

-- Found YARP: /home/gromualdi/robot-code/robotology-superbuild/build/install/lib/cmake/YARP (found version "3.7.0")
-- Configuring done
CMake Error at CMakeLists.txt:5 (add_executable):
  Target "example" links to target "YARP::YARP_profiler" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

The target should be found since in the main CMakeLists.txt I have find_package(YARP REQUIRED)

If I substitute find_package(YARP REQUIRED) with find_package(YARP REQUIRED COMPONENTS profiler) I got this other error

CMake Error at /home/gromualdi/robot-code/robotology-superbuild/build/install/lib/cmake/YARP/YARPConfig.cmake:159 (find_package):
  Found package configuration file:

    /home/gromualdi/robot-code/robotology-superbuild/build/install/lib/cmake/YARP_profiler/YARP_profilerConfig.cmake

  but it set YARP_profiler_FOUND to FALSE so package "YARP_profiler" is
  considered to be NOT FOUND.  Reason given by package:

  The following imported targets are referenced, but are missing:
  YARP::YARP_companion

To Reproduce Create a project with the following CMakeLists.txt

cmake_minimum_required(VERSION 3.0)
project(myproject)
find_package(YARP REQUIRED)

add_executable(example example.cpp)
target_link_libraries(example YARP::YARP_profiler) 

and the following example.cpp

#include <yarp/profiler/NetworkProfilerBasic.h>
int main() {
    return 0;
}

Expected behavior I am expecting that YARP::YARP_profiler is found if installed in the system

Configuration (please complete the following information):

  • OS: ubuntu 20.04
  • yarp version: v3.7.0
  • compiler:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04.1' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-Av3uEd/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1) 

Additional context This is a possible workaround

find_package(YARP REQUIRED COMPONENTS companion profiler)

however, I think find_package(YARP REQUIRED) should work as well if YARP::YARP_profiler is installed in the system

cc @traversaro

GiulioRomualdi avatar Jun 22 '22 10:06 GiulioRomualdi

however, I think find_package(YARP REQUIRED) should work as well if YARP::YARP_profiler is installed in the system

If I recall correctly, by design find_package(YARP REQUIRED) only imports a limited number of components/targets (in particular os, sig and dev) unless the components are explicitly listed in COMPONENTS. This is by design, see the logic in https://github.com/robotology/yarp/blob/c3b05bc6141156542228547aba78b14328c93c90/cmake/YarpDescribe.cmake#L13 and https://github.com/robotology/yarp/blob/bb647b69e084c295d6d7e31aeb36202abe42ccf9/cmake/template/YARPConfig.cmake.in#L106 . Clearly I am not saying that this is cannot be changed, especially if users expects something else if they call find_package(YARP REQUIRED). However, this is kind of not related to YARP_profiler.

Another story is that find_package(YARP REQUIRED COMPONENTS profiler) does not work out of the box. In theory calling find_package() should be handled by https://github.com/robotology/yarp/blob/8a30054a0784f56242c4e1ba7b2b7a806c6119cc/src/libYARP_profiler/src/CMakeLists.txt#L55, https://github.com/robotology/yarp/blob/8a30054a0784f56242c4e1ba7b2b7a806c6119cc/src/libYARP_profiler/src/CMakeLists.txt#L88 and https://github.com/robotology/yarp/blob/8a30054a0784f56242c4e1ba7b2b7a806c6119cc/src/libYARP_profiler/CMakeLists.txt#L15. However, this does not work as the logic for adding find_package for PRIVATE_DEPENDENCIES just checks if BUILD_SHARED_LIBS is defined (see https://github.com/robotology/ycm/blob/2583228ed11f0fe5ba32497943b112099cd1af81/modules/InstallBasicPackageFiles.cmake#L598), but in this case libYARP_profiler is always a static library, indipendently of the value of BUILD_SHARED_LIBS (see https://github.com/robotology/yarp/blob/8a30054a0784f56242c4e1ba7b2b7a806c6119cc/src/libYARP_profiler/src/CMakeLists.txt#L4).

Possible fixes are:

  • Make libYARP_profiler respect the BUILD_SHARED_LIBS, instead of hardcoding it to be static library in https://github.com/robotology/yarp/blob/8a30054a0784f56242c4e1ba7b2b7a806c6119cc/src/libYARP_profiler/src/CMakeLists.txt#L4 . The todo in the code suggest to do that with YARP_profiler_API/__declspec(dllimport/dllexport), but a possilbe alternative solution is just to use CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS as we do for all other libraries that are not YARP
  • Put YARP_companion in YARP_profiler_PUBLIC_DEPS
  • Fix InstallBasicPackageFiles YCM module to actually inspect if the exported targets are static or shared, instead of assuming that they respect BUILD_SHARED_LIBS (this is probably hard and with low benefit)

traversaro avatar Jun 24 '22 10:06 traversaro

Ok, we are going to consider one of these possibilities for the next release 3.8.

randaz81 avatar Jun 30 '22 11:06 randaz81