pkg_config_modules dependency fails because version in "Uncontrolled" - cmake

The Problem
I've got a CMakeLists.txt file with this content:
pkg_check_modules(FOO REQUIRED foo>=0.1.0.1)
When I run Cmake v3.17.2 with cmake3 -G Ninja . in that directory:
Checking for module 'foo>=0.1.0.1'
Requested 'foo >= 0.1.0.1' but version of foo is Uncontrolled
Details
This is running inside RHEL7
yum info foo | grep Version returns Version : 0.1.0.1.20200417git602d018
The foo module is created by the team I'm on
The Question
How can I tell CMake what version my foo library is so that it isn't "Uncontrolled"?

In the output of the foo project, inside of the generated lib64 directory, there's a pkgconfig directory which contains foo.pc.
Inside of that file, version info is as follows:
Version: HEAD
Change this to be the intended version. In my case this was automated by the build process of foo, so what was required was to add a git tag for the current version and rebuild.

Related

How do I tell meson setup about the location of a dependency?

I'm trying to build celluloid, which uses meson. I ran meson, but it failed to find an appropriate version of mpv:
Determining dependency 'mpv' with pkg-config executable '/usr/bin/pkg-config'
Called `/usr/bin/pkg-config --modversion mpv` -> 1
Found CMake: /usr/bin/cmake (3.13.4)
Determining dependency 'mpv' with CMake executable '/usr/bin/cmake'
Try CMake generator: auto
Called `/usr/bin/cmake --trace-expand -DNAME=mpv .` in /tmp/celluloid-0.20/build/meson-private/cmake_mpv -> 0
Dependency mpv found: NO (tried pkgconfig and cmake)
src/meson.build:125:0: ERROR: Dependency "mpv" not found, tried pkgconfig and cmake
so I downloaded and built the latest mpv release (0.33.0), built and installed it at /opt/mpv.
Now - how do I tell meson to take mpv from this new path?
Note: The relevant snippet of the meson files seems to be:
executable('celluloid', sources,
dependencies: [
libgtk,
libgio,
meson.get_compiler('c').find_library('m', required: false),
dependency('mpv', version: '>= 1.107'),
dependency('epoxy')
],
link_with: extra_libs,
include_directories: includes,
c_args: cflags,
install: true
)
You tell meson about your dependency by letting pkgconfig know about your dependency...
and that can be done by adding your dependency's path to the PKG_CONFIG_PATH environment variable; it is delimited by colons, just like PATH, e.g. /opt/foo:/opt/extra/baz.
Remember that you may also need to add associated paths to LD_LIBRARY_PATH after building and installing with a custom-built directory.

create the symlink failed in yocto project

Error log, do_package_qa:
QA Issue: non -dev/-dbg/nativesdk- package contains symlink .so
source code, CMakeList.txt:
SET_TARGET_PROPERTIES(${TARGETNAME} PROPERTIES VERSION 1.0 SOVERSION 1)
Whether I need to add some parameter like -dev or -dbg??
You need to either manually install those *.so files and symlinks to them in do_install() for PACKAGE_${PN}-dev, or add the following to the recipe:
FILES_SOLIBSDEV = ""
SOLIBS = ".so"

Catkin cannot find gtest

Since yesterday none of my packages containing tests build. Catkin complains it cannot find gtest when using catkin_add_gtests(), since GTEST_FOUND is FALSE. You can see this in the error msg below, with the custom output I added to my CMakeLists. Up to yesterday, GTEST_FOUND was TRUE when catkin_add_gtests() was called.
This is the error I always get. In this case I'm trying to build a mockup package on a clean catkin workspace:
Errors << silly_pkg:cmake /home/paco/catkin_ws2/logs/silly_pkg/build.cmake.002.log
Not searching for unused variables given on the command line.
Re-run cmake no build system arguments
-- Using CATKIN_DEVEL_PREFIX: /home/paco/catkin_ws2/devel/.private/silly_pkg
-- Using CMAKE_PREFIX_PATH: /home/paco/catkin_ws2/devel;/opt/ros/kinetic
-- This workspace overlays: /home/paco/catkin_ws2/devel;/opt/ros/kinetic
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/paco/catkin_ws2/build/silly_pkg/test_results
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.11
-- GTEST_FOUND: FALSE
CMake Warning at /opt/ros/kinetic/share/catkin/cmake/test/gtest.cmake:149 (message):
skipping gtest 'test_silly_pkg' in project 'silly_pkg' because gtest was
not found
Call Stack (most recent call first):
/opt/ros/kinetic/share/catkin/cmake/test/gtest.cmake:79 (_catkin_add_executable_with_google_test)
/opt/ros/kinetic/share/catkin/cmake/test/gtest.cmake:28 (_catkin_add_google_test)
CMakeLists.txt:28 (catkin_add_gtest)
CMake Error at /home/paco/catkin_ws2/src/silly_pkg/CMakeLists.txt:33 (target_link_libraries):
Cannot specify link libraries for target "test_silly_pkg" which is not
built by this project.
-- Configuring incomplete, errors occurred!
See also "/home/paco/catkin_ws2/build/silly_pkg/CMakeFiles/CMakeOutput.log".
See also "/home/paco/catkin_ws2/build/silly_pkg/CMakeFiles/CMakeError.log".
cd /home/paco/catkin_ws2/build/silly_pkg; catkin build --get-env silly_pkg | catkin env -si /usr/bin/cmake /home/paco/catkin_ws2/src/silly_pkg --no-warn-unused-cli -DCATKIN_DEVEL_PREFIX=/home/paco/catkin_ws2/devel/.private/silly_pkg -DCMAKE_INSTALL_PREFIX=/home/paco/catkin_ws2/install; cd -
I am using catkin 0.7.11, libgtest-dev 1.7.0 and cmake 3.5.1. I use ROS Kinetic with Ubuntu 16.04. The only thing I did yesterday was reinstalling ROS Kinetic, but the package versions are exactly the same. Did anybody have this problem? Do you have any ideas on what could be happening?
EDIT 3/09/18:
By comparing with a functional catkin+gtest workspace in a different computer, I found out that the main difference is in the results of /opt/ros/kinetic/share/catkin/cmake/test/gtest.cmake. In the functional workspace, line 292 evaluates to TRUE (gtest/gmock is not a target) while in my workspace it evaluates to FALSE. This is because in my workspace running find_package(GMock QUIET) (line 287) sets gmock and gtest as imported targets, which does not happen in the other computer. Why is this different?
Thanks TikO for your help!
Since you wrote that cmake does not find the libraries and that you have reinstalled Kinetic, I assume that you have a freshly installed machine or wiped out gtest libraries by accident.
If you install libgtest-dev, you only get the sources which you need to build and install like this:
sudo apt-get install libgtest-dev
mkdir /tmp/gtest_build && cd /tmp/gtest_build
cmake /usr/src/gtest
make
#copy or symlink libgtest.a and ligtest_main.a to /usr/lib folder
sudo cp *.a /usr/lib
After this routine, you should be able to build again without cmake complaining.
Optional
If you have limited rights on your machine and you are not allowed to install the libraries in that way, just copy them into some home folder like
mkdir ~/lib && cp *.a ~/lib
But be aware of the fact, that you have to call catkin in the following way:
LIBRARY_PATH=~/lib GTEST_ROOT=~/lib catkin_make
LIBRARY_PATH tells the linker where to find the libraries, while GTEST_ROOT gives cmake the location hints for it's checks.
Reference: https://github.com/tik0/gtest_ros_example
SOLUTION FOUND
gmock and gtest were being set to imported target because the suggested manual compilation of libgtest had created a FindGMock.cmake file inside /usr/share/cmake-3.5/Modules. This file was being called by the find(GMock QUIET)
in catkin_add_gtests(), therefore setting the imported target. Just deleting FindGMock.cmake solved the issue.

The libgit2 examples are not building properly

I have built libgit2 on my Ubuntu 16.04 machine, and everything seemed fine. I ran make in the /examples directory and when I try to run ./log I get the following:
./log: error while loading shared libraries: libgit2.so.26: cannot open shared object file: No such file or directory
But, in the /build folder I indeed have both libgit2.so and libgit2.so.26 so I am not really sure what I am missing. I can post more info if it is needed. I am using cmake version 3.5.1.
The Makefile in the examples will provide guidelines for usage, which should be suitable when you have actually installed libgit2 into system library locations.
To build the examples within the source directory, you should use cmake to build the examples. Given a fresh configuration:
$ mkdir build
$ cd build
$ cmake .. -DBUILD_EXAMPLES=ON
$ cmake --build .
...truncated...
$ examples/log
commit 8ac8c78c35905f7f9cc37f240c3d633a7cc5a5e3
Merge: 34ec6f3 4955125
Author: Edward Thomson <ethomson#edwardthomson.com>
Date: Mon Oct 9 15:15:08 2017 +0100
Merge pull request #4356 from pks-t/pks/static-clar
cmake: use static dependencies when building static libgit2
...truncated...

cmake could not find required package TIFF

I'm trying to build an application via cmake 3.9.0. Cmake keeps complaining about the inability to find the tiff library: CMake error at CMakeModules/FindPackageHandleStandardArgs.cmake:51 (Message): Could not find REQUIRED package TIFF). I tried to install the library via sudo apt-get install libtiff5-dev but was still getting the same message. Then I checked-out the source code for libtiff 4 and built it from the source. Now I think we can hint the cmake with the location where to look for the libtiff via setting the variables TIFF_INCLUDE_DIR, TIFF_INCLUDE_DIRS, etc as described here: https://cmake.org/cmake/help/v3.6/module/FindTIFF.html. However I have failed in wiring the right values for the variables. Can somebody show me an example of sample libtiff instalation and the sample values for the configuration variable in order cmake would find the TIFF. Or is here another option how to show CMake where does the TIFF library lie?
cd build
cmake -DTIFF_INCLUDE_DIR=<dir> -DTIFF_LIBRARY=<filename> -GNinja ..
cmake --build .
Alternatively, you can modify the variables in your CMakeLists.txt before calling find_package():
set(TIFF_INCLUDE_DIR "<dir>")
set(TIFF_LIBRARY "<filename>")
find_package(TIFF)
add_executable(myexe TIFF::TIFF)
where <dir> is the include directory path and <filename> is the exact file path to the library.