robotology / gz-sim-yarp-plugins

YARP plugins for Modern Gazebo (gz-sim).
BSD 3-Clause "New" or "Revised" License
9 stars 2 forks source link

Install headers and CMake config files to gzyarp::DeviceRegistry so that it can be used by downstream projects #160

Closed xela-95 closed 7 months ago

xela-95 commented 7 months ago

Closes #150

xela-95 commented 7 months ago

Up to now the CMake configuration is failing with message:

[cmake] CMake Error at /home/acroci/mambaforge/envs/walking/share/YCM/modules/InstallBasicPackageFiles.cmake:660 (export):
[cmake]   export Export set "gz-sim-yarp-plugins" not found.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:54 (Install_basic_package_files)
xela-95 commented 7 months ago

With https://github.com/robotology/gz-sim-yarp-plugins/pull/160/commits/45880a8cad9e8e284940f422b6e97b4827f0d04d the new CMake configuration is working and exporting the heders and configuration files.

xela-95 commented 7 months ago

This is the log of the installation:

[proc] Executing command: /home/acroci/mambaforge/envs/walking/bin/cmake --build /home/acroci/repos/gz-sim-yarp-plugins/build --config Debug --target install --
[build] [1/1   0% :: 0.010] Install the project...
[build] -- Install configuration: "Debug"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-commons.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-commons.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-device-registry.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-device-registry.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/include/gz-sim-yarp-device-registry/DeviceRegistry.hh
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-robotinterface-system.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-robotinterface-system.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-camera-singleton.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-camera-singleton.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-camera-system.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-camera-system.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-laser-singleton.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-laser-singleton.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-laser-system.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-laser-system.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-forcetorque-singleton.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-forcetorque-singleton.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-forcetorque-system.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-forcetorque-system.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-imu-singleton.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-imu-singleton.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-imu-system.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-imu-system.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-basestate-singleton.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-basestate-singleton.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-basestate-system.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-basestate-system.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-clock-system.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-clock-system.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-controlboard-singleton.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-controlboard-singleton.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-controlboard-system.so
[build] -- Set non-toolchain portion of runtime path of "/home/acroci/mambaforge/envs/walking/lib/libgz-sim-yarp-controlboard-system.so" to "$ORIGIN/:$ORIGIN/../lib"
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/cmake/gz-sim-yarp-plugins/gz-sim-yarp-pluginsConfigVersion.cmake
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/cmake/gz-sim-yarp-plugins/gz-sim-yarp-pluginsConfig.cmake
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/cmake/gz-sim-yarp-plugins/gz-sim-yarp-pluginsTargets.cmake
[build] -- Installing: /home/acroci/mambaforge/envs/walking/lib/cmake/gz-sim-yarp-plugins/gz-sim-yarp-pluginsTargets-debug.cmake
[driver] Build completed: 00:00:00.083
[build] Build finished with exit code 0
traversaro commented 7 months ago

Note that to check if the installed cmake config package file is working fine, you can run:

cmake-package-check gz-sim-yarp-plugins --targets gz-sim-yarp-plugins::gz-sm-yarp-device-registry

if you install cmake-package-check command (see https://github.com/ami-iit/cmake-package-check). You can also include this in the conda-based CI, see for example https://github.com/ami-iit/bipedal-locomotion-framework/blob/6dd640b73e6e2e6747fc2b9d96bddf7aee643d71/.github/workflows/conda-forge-ci.yml#L128 .

xela-95 commented 7 months ago

Note that to check if the installed cmake config package file is working fine, you can run:

cmake-package-check gz-sim-yarp-plugins --targets gz-sim-yarp-plugins::gz-sm-yarp-device-registry

if you install cmake-package-check command (see https://github.com/ami-iit/cmake-package-check). You can also include this in the conda-based CI, see for example https://github.com/ami-iit/bipedal-locomotion-framework/blob/6dd640b73e6e2e6747fc2b9d96bddf7aee643d71/.github/workflows/conda-forge-ci.yml#L128 .

Thanks! I tested that by manually creating a project with the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(TestProject
        LANGUAGES CXX C)

include(GNUInstallDirs)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

find_package(gz-sim-yarp-plugins REQUIRED)

add_executable(test_exe main.cpp)
target_link_libraries(test_exe gz-sim-yarp-plugins)

But for sure this approach is faster and more reliable. This is the output i get:

===================================
=== Generated CMakeLists.txt file: 
===================================
cmake_minimum_required(VERSION 3.12...3.29)

project(CMakePackageCheckTestCMakeProject)

find_package(gz-sim-yarp-plugins REQUIRED)

find_package(gz-sim-yarp-plugins REQUIRED)

# Create dummy executable
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cmake_package_check_dummy_executable.cpp "int main() {return 0;}")
add_executable(cmake_package_check_dummy_executable ${CMAKE_CURRENT_BINARY_DIR}/cmake_package_check_dummy_executable.cpp)

target_link_libraries(cmake_package_check_dummy_executable PRIVATE gz-sim-yarp-plugins::gz-sim-yarp-device-registry)

===================================
=== CMake configure output:        
===================================
-- The C compiler identification is GNU 12.3.0
-- The CXX compiler identification is GNU 12.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/acroci/mambaforge/envs/walking/bin/x86_64-conda-linux-gnu-cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/acroci/mambaforge/envs/walking/bin/x86_64-conda-linux-gnu-c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: /tmp/tmply3zog3t
===================================
=== Result:
===================================
cmake-package-check: SUCCESS.
xela-95 commented 7 months ago

@traversaro shoudl I add an alias target like it is done in https://github.com/robotology/how-to-export-cpp-library/blob/afb21efb655e7b1cc11636c3d42aad9e02fb626f/src/LibHeaderOnlyTemplateCMake/CMakeLists.txt#L41 to be able to refer to this target as gz-sim-yarp-plugins::gz-sim-yarp-device-registry?

xela-95 commented 7 months ago

After 4bff351a228767ce8324797b91d27476f432502f I now get an error related to the public YARP_dev dependency with cmake-package-check gz-sim-yarp-plugins --targets gz-sim-yarp-plugins::gz-sm-yarp-device-registry:

# Create dummy executable
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cmake_package_check_dummy_executable.cpp "int main() {return 0;}")
add_executable(cmake_package_check_dummy_executable ${CMAKE_CURRENT_BINARY_DIR}/cmake_package_check_dummy_executable.cpp)

target_link_libraries(cmake_package_check_dummy_executable PRIVATE gz-sim-yarp-plugins::gz-sim-yarp-device-registry)

===================================
=== CMake configure output:        
===================================
-- The C compiler identification is GNU 12.3.0
-- The CXX compiler identification is GNU 12.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/acroci/mambaforge/envs/walking/bin/x86_64-conda-linux-gnu-cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/acroci/mambaforge/envs/walking/bin/x86_64-conda-linux-gnu-c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.2s)
CMake Error at /home/acroci/mambaforge/envs/walking/lib/cmake/gz-sim-yarp-plugins/gz-sim-yarp-pluginsTargets.cmake:61 (set_target_properties):
  The link interface of target
  "gz-sim-yarp-plugins::gz-sim-yarp-device-registry" contains:

    YARP::YARP_dev

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  /home/acroci/mambaforge/envs/walking/lib/cmake/gz-sim-yarp-plugins/gz-sim-yarp-pluginsConfig.cmake:21 (include)
  CMakeLists.txt:5 (find_package)

-- Generating done (0.0s)
CMake Generate step failed.  Build files cannot be regenerated correctly.
Error occurred: Command '['cmake', '-GNinja', '-S.', '-B.']' returned non-zero exit status 1.
===================================
=== Result:
===================================
cmake-package-check: FAILURE.
traversaro commented 7 months ago

This is related to https://github.com/robotology/gz-sim-yarp-plugins/pull/160/files#r1561277217 . If you do not add DEPENDENCIES there, then the gz-sim-yarp-pluginsConfig.cmake file or similar (I suggest you to open it to get an idea of what it contains) does not contain a find_dependency(YARP) call, and hence that target is not defined. Once you add the DEPENDENCY argument, a find_dependency(YARP) call will be added, and you should not have any more problem.

xela-95 commented 7 months ago

This is related to https://github.com/robotology/gz-sim-yarp-plugins/pull/160/files#r1561277217 . If you do not add DEPENDENCIES there, then the gz-sim-yarp-pluginsConfig.cmake file or similar (I suggest you to open it to get an idea of what it contains) does not contain a find_dependency(YARP) call, and hence that target is not defined. Once you add the DEPENDENCY argument, a find_dependency(YARP) call will be added, and you should not have any more problem.

Sorry I forgot about that required update 🤦🏻‍♂️

Now it's working and I also added the cmake-package-check to the CI

xela-95 commented 7 months ago

The CI is failing on the test of installed package with the following error:

-- The C compiler identification is GNU 12.3.0
-- The CXX compiler identification is GNU 12.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/runner/micromamba/envs/gzyarppluginsdev/bin/x86_64-conda-linux-gnu-cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/runner/micromamba/envs/gzyarppluginsdev/bin/x86_64-conda-linux-gnu-c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:5 (find_package):
  By not providing "Findgz-sim-yarp-plugins.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "gz-sim-yarp-plugins", but CMake did not find one.

  Could not find a package configuration file provided by
  "gz-sim-yarp-plugins" with any of the following names:
-- Configuring incomplete, errors occurred!

    gz-sim-yarp-pluginsConfig.cmake
    gz-sim-yarp-plugins-config.cmake

  Add the installation prefix of "gz-sim-yarp-plugins" to CMAKE_PREFIX_PATH
  or set "gz-sim-yarp-plugins_DIR" to a directory containing one of the above
  files.  If "gz-sim-yarp-plugins" provides a separate development package or
  SDK, be sure it has been installed.

===================================
=== Generated CMakeLists.txt file: 
===================================
cmake_minimum_required(VERSION 3.[12](https://github.com/robotology/gz-sim-yarp-plugins/actions/runs/8661043984/job/23750156856?pr=160#step:14:13)...3.29)

project(CMakePackageCheckTestCMakeProject)

find_package(gz-sim-yarp-plugins REQUIRED)

find_package(gz-sim-yarp-plugins REQUIRED)

# Create dummy executable
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cmake_package_check_dummy_executable.cpp "int main() {return 0;}")
add_executable(cmake_package_check_dummy_executable ${CMAKE_CURRENT_BINARY_DIR}/cmake_package_check_dummy_executable.cpp)

target_link_libraries(cmake_package_check_dummy_executable PRIVATE gz-sim-yarp-plugins::gz-sim-yarp-device-registry)

===================================
=== CMake configure output:        
===================================
Error occurred: Command '['cmake', '-GNinja', '-S.', '-B.']' returned non-zero exit status 1.
===================================
=== Result:
===================================
cmake-package-check: FAILURE.
xela-95 commented 7 months ago

Ok now the CI is passing! Merging 🚀