Pkgconfig cant find a package - cmake

I am using pkgconfig in cmake to link to an external library. Even though there exists a exteral_package.pc file (with apparently correct information), cmake is throwing me an error.
The CMakeLists file looks something like this:
project(juicer)
set(VERSION 1.0)
# Find packages
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
find_package(Tracter REQUIRED)
And the FindTracter file looks like this:
find_package(PkgConfig)
pkg_check_modules(TRACTER REQUIRED tracter)
Error:
-- checking for module 'tracter'
-- package 'tracter' not found
CMake Error at /usr/share/cmake-2.8/Modules/FindPkgConfig.cmake:279 (message):
A required package was not found
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPkgConfig.cmake:333 (_pkg_check_modules_internal)
cmake/FindTracter.cmake:10 (pkg_check_modules)
CMakeLists.txt:22 (find_package)
I am new to using CMake and your help is very much appreciated.
Thanks
Akshat

Related

Why does find_package(MPI) generate a warning message?

I'm using CMake 3.22.0-rc2. When I run:
find_package(MPI)
I get the warning:
CMake Warning (dev) at /opt/versions/cmake/3.22.0-rc2/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
The package name passed to `find_package_handle_standard_args` (PkgConfig)
does not match the name of the calling package (MPI). This can lead to
problems in calling code that expects `find_package` result variables
(e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
/opt/versions/cmake/3.22.0-rc2/share/cmake-3.22/Modules/FindPkgConfig.cmake:88 (find_package_handle_standard_args)
/opt/versions/cmake/3.22.0-rc2/share/cmake-3.22/Modules/FindMPI.cmake:270 (include)
examples/multi-gpu-programming-models/CMakeLists.txt:2 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
I realize I can suppress this error, but - does it have anything to do with what I've got in my CMakeLists.txt or is this some sort of internal CMake (semi-)bug?
This warning has recently been fixed in https://github.com/Kitware/CMake/commit/56d949f05f37c65401825a30be0d39bd152cc33c.
It was incorrect inclusion of module FindPkgConfig.cmake via
include(${CMAKE_CURRENT_LIST_DIR}/FindPkgConfig.cmake)
With such inclusion the call to find_package_handle_standard_args performed inside FindPkgConfig.cmake is interpreted as from the FindMPI.cmake module, because the latest find_package call has MPI argument instead of PkgConfig.
All modules like FindXXX.cmake should be included via find_package:
find_package(PkgConfig)

include library to clion project

I'm trying to include wxWidgets library in my project.
I'm working on Ubuntu 16.04. You can get wxWidgets from the repository (already compiled) and just include it by modifying a cmake file (included in CLion). It works fine doing just that.
However, I need to modify the sources and this means that I have to compile the library myself.
I followed the instructions from this file:
https://github.com/wxWidgets/wxWidgets/blob/v3.1.0/docs/gtk/install.txt
Now Cmake can't find the library.
What may be missing?
EDIT:
The part of CMake regarding wxWidgets :
find_package(wxWidgets 3.1.0 COMPONENTS core base media REQUIRED)
include(${wxWidgets_USE_FILE})
target_link_libraries(projectName ${wxWidgets_LIBRARIES})
Error:
CMake Error at /home/usrName/Clion/clion-2017.2/bin/cmake/share/cmake-
3.8/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find wxWidgets: Found unsuitable version "3.0.2", but required is
at least "3.1.0" (found
-L/usr/lib/x86_64-linux-gnu;-pthread;;;-lwx_gtk2u_core-3.0;-lwx_baseu-3.0;-
lwx_gtk2u_media-3.0)
Call Stack (most recent call first):
/home/usrName/Clion/clion-2017.2/bin/cmake/share/cmake-
3.8/Modules/FindPackageHandleStandardArgs.cmake:375 (_FPHSA_FAILURE_MESSAGE)
/home/usrName/Clion/clion-2017.2/bin/cmake/share/cmake-
3.8/Modules/FindwxWidgets.cmake:931 (find_package_handle_standard_args)
CMakeLists.txt:18 (find_package)

CMake can't find GLEW

I've read this [1], but in my case CMake says it can't find glew.
I'm on Windows and there is a FindGLEW.cmake file in my CMake modules folder, presumably put there when I installed CMake-3.6. I found GLEW on sourceforge and downloaded the zip file for Windows. I unzipped and installed in C:\Program Files\glew. When I've created my own libraries and used CMake to build and install them, this is the default location they are installed to so I am pretty confident I'm OK here.
The snippet from my CMakeLists.txt is:
find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})
link_libraries(${GLEW_LIBRARIES})
The actual error message from CMake is:
CMake Error at C:/Program Files/CMake/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find GLEW (missing: GLEW_INCLUDE_DIR GLEW_LIBRARY)
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.6/Modules/FindGLEW.cmake:44 (find_package_handle_standard_args)
source/CMakeLists.txt:5 (find_package)
Is it possible the FindGLEW.cmake is broken? I've looked at a couple of other FindXXXXX.cmake files and they are like snowflakes, each one pretty unique. So it's hard for me to say with any certainty that it's following convention.
[1] Linking GLEW with CMake
Looking in the sources, the package is looking for GLEW in relative paths. These relative paths are searched using different prefixes, including the content of the variable CMAKE_PREFIX_PATH:
<prefix>/include for find_path which is used to find include directories.
<prefix>/lib for find_library which is used to find libraries.
Assuming C:/Program Files/glew/include and C:/Program Files/glew/lib exist, add C:/Program Files/glew to your CMAKE_PREFIX_PATH variable. Something like:
list(APPEND CMAKE_PREFIX_PATH "C:/Program Files/glew")
find_package(GLEW REQUIRED)
Note that the following lines:
include_directories(${GLEW_INCLUDE_DIRS})
link_libraries(${GLEW_LIBRARIES})
may be dropped using imported target Glew::Glew:
add_executable(foo ...)
target_link_libraries(foo Glew::Glew)

Error with CMake to generate ITK Module VTKGlue

I want to generate makefiles for ITK module VTKGlue but I have a message error:
CMake Error at Modules/Bridge/VtkGlue/itk-module-init.cmake:7
(find_package): Could not find a configuration file for package
"VTK" that is compatible with requested version "".
The following configuration files were considered but not accepted:
C:/ITK/bin/VTK/VTKConfig.cmake, version: 6.2.0 (64bit)
Call Stack (most recent call first):
CMake/ITKModuleEnablement.cmake:315 (include) CMakeLists.txt:364
(include)
The content of Modules/Bridge/VtkGlue/itk-module-init.cmake is :
#
Find the packages required by this module
#
Needed VTK version set(VERSION_MIN "5.10.0")
Look for VTK find_package(VTK NO_MODULE REQUIRED COMPONENTS vtkCommonCore)
What should I do?
Thanks
The solution is to rebuild VTK...
It has been built with the generator VS, whereas ITK is built with the generator Eclipse CDT.

CMake find_package() Eclipse, OS X

I managed to create Make Target in Eclipse and add a CMakeListst.txt to a very simple project and it worked.
Now, my next step is to use two external libraries, Boost and Eigen.
My project is in /Users/MyUser/Documents/workspace/Test
The libraries are /Users/MyUser/Documents/MyLib/Libraries
Now, in the CMakeLists.txt file I try to find Boost and Eigen, which are in the libraries folder, but always the returned message is
CMake Error at CMake/TPLs/FindBoost.cmake:1126 (message): Unable to
find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the
root directory containing Boost or BOOST_INCLUDEDIR to the directory
containing Boost's headers. Call Stack (most recent call first):
CMakeLists.txt:23 (FIND_PACKAGE)
-- Configuring incomplete, errors occurred! CMake Error at /Applications/CMake
2.8-11.app/Contents/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108
(message): Could NOT find Eigen3 (missing: EIGEN3_INCLUDE_DIRS
EIGEN3_VERSION_OK) (Required is at least version "2.91.0") Call
Stack (most recent call first): /Applications/CMake
2.8-11.app/Contents/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315
(_FPHSA_FAILURE_MESSAGE) CMake/TPLs/FindEigen3.cmake:76
(find_package_handle_standard_args) CMakeLists.txt:30 (FIND_PACKAGE)
I am new to CMake, so I must be missing some way to tell CMake to search in my library folder. How can I find the packages with CMake when building the project?
BTW I'm working under Mac OS X Mavericks.
EDIT
Reading through the file FindEigen3.cmake there should be a variable called EIGEN3_INCLUDE_DIRS that points to the include directory of Eigen, is this true?
Now, from the following message
Could NOT find Eigen3 (missing: EIGEN3_INCLUDE_DIRS EIGEN3_VERSION_OK)
I would think that cmake is actually finding that directory as it says EIGEN3_VERSION_OK but then why can't cmake find the rest of the include files?
Am I still missing something? I created the environment variable within Eclipse and then add a line to the FindEigen3.cmake to test the value of the environment variable EIGEN3_INCLUDE_DIRS
message(STATUS "Eigen version: ${EIGEN3_INCLUDE_DIRS}")
But the message I'm getting is
--Eigen version: EIGEN3_INCLUDE_DIRS-NOTFOUND
Any advise?
EDIT
I tried with the question-related answers but none was able to make Eclipse+CMake find Boost and Eigen libraries. I guess the problem here is how to make Eclipse recognize the system variables.
When you do not believe in setting environment variables in Eclipse, you can pass Cmake-defines either directly to cmake command:
cmake -E chdir Release/ cmake -G "Unix Makefiles" ... -DBOOST_ROOT:PATHNAME=boost/install/dir ...
or define them in your CMakeLists.txt before find boost/eigen3
SET(BOOST_ROOT boost/install/dir)
...
FIND_PACKAGE(BOOST ... )
or use environment variables within your OS/shell. You must define them before launching the Eclipse. E.g. from bash, do
export BOOST_ROOT=boost/install/dir
eclipse
Note that you have to define all variables needed for both boost and eigen3. You can place some debugging messages in your CMakeLists.txt to confirm that you pass them correctly:
MESSAGE("Boost root: ${BOOST_ROOT}")