How to point cmake to zlib include path? - cmake

Or any include directory/library.
I use cmake gui tool so I run it and usually the gui will highlight the include or library it can't find and let you open a open dialog to set the path however it doesn't do that for this cmake cofig it tell you in red text in the output in the gui tool, so,
CMake Error at C:/Program Files/CMake/share/cmake-3.0/Modules/FindPackageHandleStandardArgs.cmake:136 (message):
Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.0/Modules/FindPackageHandleStandardArgs.cmake:343 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.0/Modules/FindZLIB.cmake:101 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
src/CMakeLists.txt:7 (find_package)
So still using the gui how do I point cmake to the zlib include dir?

Quick solution: apt-get install zlib1g-dev

I'll first assume you have ZLib installed somewhere, and my guess is that it's in a non-standard location since CMake find it. If that's true, you can set the location in CMake-gui. You'll need to first click the 'Advanced' checkbox near the top, because the FindZLIB.cmake file has the following line "mark_as_advanced(ZLIB_LIBRARY ZLIB_INCLUDE_DIR)".
Now you should be able to see the ZLIB_LIBRARY ZLIB_INCLUDE_DIR options and set the correct path.

For future googlers, according to the docs:
An includer may set ZLIB_ROOT to a zlib installation root to tell this module where to look.

When you make and build zlib library, you need zlib.lib static library and zlib.h and zconf.h header files to make minizip libray.
So, after building zlib you have the following that are need for minizip :
zlib.lib in Release or Debug folder.
zlib.h and zconf.h header files in zlib root directory.
Now set DZLIB_LIBRARY and DZLIB_INCLUDE_DIR like this :
cmake -G "Visual Studio 14 2015" -A Win32 -DZLIB_LIBRARY="zlib-master\Release" -DZLIB_INCLUDE_DIR="zlib-master"
This solution does worked for me when i need minizip library and hope this could help you.

To add to Elhanan Ilani's answer (for any novices, like myself), this should be declared near the top of the CMakeLists.txt file. For example:
set(ZLIB_ROOT /home/foo/zlib-1.2.11/)
set(CURL_ROOT /home/foo/anaconda3/)

in my case, set ZLIB_ROOT, ZLIB_LIBRARY
c:\zlib - include
- lib

Related

How to set up CMakeLists.txt to find a .PC file (pkg-config with pkg_search_module) in a non-default path?

I am trying to create a simple project using SDL2 and SDL2_image extension. As SDL2_image doesn't provide official support for Find*.cmake modules, my alternative was to use pkg-config to find those libraries.
However, I built SDL2 and SDL2_image myself and installed them in a custom path (~/Library/SDL2 and ~/Library/SDL2_image).
CMake seems to be able to find SDL2 properly, but it can't find SDL2_image, even if I put the .PC file in the system default path (/usr/share/pkgconfig).
How do I tell CMake to look for a .PC file in a non-default (system) path? I need that to build a simple project using SDL2 and SDL2_image.
I've tried to put the SDL2_image.pc file in the default system path for .PC files (/usr/share/pkgconfig), but it seems not to be changing anything.
find_package(PkgConfig)
# SDL2 can be found and included
pkg_search_module(SDL2 REQUIRED sdl2)
# SDL2_image cannot be found and thus the project doesn't configure/generate.
pkg_search_module(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
Error message when running "cmake":
-- Checking for one of the modules 'SDL2_image>=2.0.0'
CMake Error at /usr/share/cmake-3.7/Modules/FindPkgConfig.cmake:637 (message):
None of the required 'SDL2_image>=2.0.0' found
Call Stack (most recent call first):
CMakeLists.txt:12 (pkg_search_module)
Find pkg-config *.pc file, and export the path:
export PKG_CONFIG_PATH="/path/lib/pkgconfig"

Custom path for my libraries for find_library

I am trying to compile openimageio(oiio) on Linux but it's a mess since I know almost nothing about cmake. I don't want and I can't install them on my computer directly in the /usr/local/ directory and that's the problem. I successfully compiled dependencies by executing these bash commands in each library directory :
export workingdir=<path_to_my_project>
./configure --prefix=$workingdir/sdks/deploy
make install
And this works fine, my headers are in a include directory and my libraries are in a lib directory.
Here is the structure of my project :
../<path_to_my_project>
/sdks
/build
/oiio
/png # Successfully compiled
/jpeg # Successfully compiled
/zlib # Successfully compiled
/boost # Successfully compiled
/ilmbase # Successfully compiled
/openexr # Successfully compiled
/deploy
/lib # all .a, .la and .so of successfully compiled libraries
/include # all headers of successfully compiled libraries
The problem is that there is no ./configure available in the oiio library directory so I don't know how to set the prefix path, when I execute the make command, I have errors like this :
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find PNG (missing: PNG_LIBRARY) (found version "1.6.21")
Call Stack (most recent call first):
/usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake/Modules/FindPNG.cmake:105 (find_package_handle_standard_args)
src/libOpenImageIO/CMakeLists.txt:120 (find_package)
So I set variables and it makes no errors but this is not clean and I'm not sure that my libraries are correctly referenced (If I mes up the variable content, it is still working...).
set (PNG_PNG_INCLUDE_DIR "<workingdir>/sdks/deploy/include/libpng16")
set (PNG_LIBRARY_DIR "<workingdir>/sdks/deploy/lib")
Then I tried to create my own FindXXX.cmake files but some don't have a Root variable for the library so anyway I'm not sure if it correctly found the needed files, moreover, it makes errors :
CMake Error at src/cmake/modules/FindPNG.cmake:104 (include):
include could not find load file:
<workingdir>/sdks/build/oiio/src/cmake/modules/FindPackageHandleStandardArgs.cmake
Call Stack (most recent call first):
src/libOpenImageIO/CMakeLists.txt:120 (find_package)
But it finds the cmake file it anyway since other errors are correctly referenced to my file and if I print something in the cmake file it shows up when I run the make command.
Up to know, the command I am running in the oiio directory is make but I would like something that tells to the find_library function to looks other where. I could recall the function with other parameters but I can't use my own FindXXX.cmake files.
In the oiio repository, in the INSTALL file, paragraph line 43, it says to set environment variable for custom libraries, like PNGDIR, but should it point to the deploys directory or the build directory ? And they say to see CMake configuration output, maybe to know what environment variables to set, but I don't know what file they are talking.
I tried so set PNGDIR but it doesn't work, how to know if the variable name should be PNGDIR ? It can also be PNGROOT ?
export PNGDIR=<workingdir>/sdks/deploy # doesn't work
export PNGDIR=<workingdir>/sdks/build/png # doesn't work
It would be nice if someone could help me, I need this library to be compiled to use it, hope someone understood me.
Use CMAKE_PREFIX_PATH to indicate paths where find_library, find_path et al. should have a look (documentation)
Stuff like PNGDIR should no longer be used and is considered legacy that is kept for backwards compatibility. Patches for FindXXX provided by CMake to add XXX_DIR or XXX_ROOT are rejected by the CMake developers.

Building a VS2015 x64 project using glew 1.13.0 and CMake 3.4.0

How do I build a VS2015 x64 project using glew 1.13.0 and CMake 3.4.0?
I prepared a minimal demo that can be found here: https://bitbucket.org/Vertexwahn/cmakedemos/src/2fbbc02b2c0567319d7be070b34391b1ef35048d/GlewDemo/?at=default
CMakeLists.txt:
cmake_minimum_required ( VERSION 2.8)
project ( GlewDemo )
find_package(GLEW REQUIRED)
set ( SRCS main.cpp )
add_executable(GlewDemo ${SRCS})
target_link_libraries(GlewDemo glew32s)
I downloaded the prebuilt binaries from here: http://sourceforge.net/projects/glew/files/glew/1.13.0/glew-1.13.0-win32.zip/download
And set the path of GLEW_INCLUDE_DIR to the corresponding directory ("C:\Users\no68koc\Downloads\glew-1.13.0\include")
But CMake gives me some errors:
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find GLEW (missing: GLEW_LIBRARY)
Call Stack (most recent call first):
C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/FindGLEW.cmake:44 (find_package_handle_standard_args)
CMakeLists.txt:4 (find_package)
Configuring incomplete, errors occurred!
See also "C:/build/vs2015/GlewDemo/CMakeFiles/CMakeOutput.log".
How does it work properly?
Error message
Could NOT find GLEW (missing: GLEW_LIBRARY)
is a standard message generated by FindXXX.cmake script (called via find_package(XXX)), that it is failed to set(deduce) some CMake variables, so whole package is assumed to be not found.
Most of FindXXX.cmake scripts descibes(in the comment), which variables are set by the script for user.
But only several of them describes, how user can help script in case when the script failed to find needed package at all, or if user wants script to find specific package installation instead of default one.
There is no universal approach in helping to the FindXXX.cmake script, in most cases one should analize code of the script for know variables, which can help.
In the given case (with GLEW package) analizing CMake-provided FindGLEW.cmake script reveals, that both find_path() call (which set GLEW_INCLUDE_DIR variable) and find_library() call (which set GLEW_LIBRARY variable) use no hints (HINT or PATH options) for search. But there are standard hints, which are used by both of this commands. One of these hints is ${CMAKE_PREFIX_PATH}/include directory for find_path and similar directory for find_library.
So you can use
list(APPEND CMAKE_PREFIX_PATH "C:\Users\no68koc\Downloads\glew-1.13.0")
for hint to find_library() and find_path() to search under this directory too.
Alternatively, you may set CMAKE_PREFIX_PATH variable in CMake cache either in GUI (e.g. inside Visual Studio) or via command line:
cmake -DCMAKE_PREFIX_PATH:PATH=C:\Users\no68koc\Downloads\glew-1.13.0
(Note, that using list(APPEND ...) instead of set(...) within CMakeLists.txt does not override variable in case it is set in cache too).
You may use another, 3d-party FindGLEW.cmake script
You can download it into your project (e.g., to cmake/FindGLEW.cmake) and issue
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
for tell find_package() to use this script instead of default one.
Given script uses
${GLEW_LOCATION}
directory (and its subdirectories) as hint for searching in find_path() and find_library() (under PATH command's option). So you can set GLEW_LOCATION variable to installation directory:
set(GLEW_LOCATION "C:\Users\no68koc\Downloads\glew-1.13.0")
for make things work. Alternatively(and preferrably), this variable can be set in cache.
Also, given FindGLEW.cmake script uses
$ENV{GLEW_LOCATION}
directory as hint. This means that setting GLEW_LOCATION environment variable will also helps.
CMake cannot locate your GLEW. Thus you have to hint CMake.
Either include GLEW to some place, where CMake looks for components. Installing GLEW comes to mind.
Or you define the variables manually. You already did that for GLEW_INCLUDE_DIR. You have to define GLEW_LIBRARY, too.
It must be the path to the library named glew32, glew, or glew32s. With Unices it should be lib*.so maybe with some additional version numbers. With Windows it should be *.dll or *.lib.

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}")

"OpenCV" is considered to be NOT FOUND

Linux Flavor: Debian (Crunch Bang)
Problem Occurred: When attempting to build cvblobs with the following command
cd ~/cvblob
cmake .
Error:
CMake Error at cvBlob/CMakeLists.txt:20 (find_package):
Found package configuration file:
/usr/local/share/OpenCV/OpenCVConfig.cmake
but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be
NOT FOUND.
-- Configuring incomplete, errors occurred!
Well I met a similar problem when I was going with some other open source face detection modules rather than cvblobs.
Actually you will find that before these lines of error-info, there are:
CMake Warning at /usr/local/opencv-2.4.13/cmake/OpenCVConfig.cmake:163 (message):
Found OpenCV Windows Pack but it has not binaries compatible with your configuration.
You should manually point CMake variable OpenCV_DIR to your build of OpenCV library.
Call Stack (most recent call first):
CMakeLists.txt:57 (find_package)
CMake Warning at CMakeLists.txt:57 (find_package):
Found package configuration file:
/usr/local/opencv-2.4.13/cmake/OpenCVConfig.cmake
but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be NOT FOUND.
So you may notice that it asks you to manually point out the directory of you build version of OpenCV library.
For me, my source codes are at
/usr/local/opencv-2.4.13/
but I make and install my release build of OpenCV at
/usr/local/opencv-2.4.13/release/
so I use:
cmake -D OpenCV_DIR=/usr/local/opencv-2.4.13/release/ ..
and everything works:)
When I compile a program that use OpenCV lib, vision 2.4.8, occurs the similar error, when I point manually Opencv_DIR path to opencv/build ,visio 3.1.0, error occurred like you.
Then I point Opencv_DIR path to opencv/build whose vision is same to the program used. It works.
One of the reason could be the another OpenCV package in another path, that you had installed before. In my case, I had already installed OpenCV for Python in Anaconda package, and the CMake always wanted to refer me to that package.
I simply added:
set(OpenCV_FOUND 1)
to my CMakeList.txt file, this command simply override the other package you may had installed. The final version of CMakeList file which is working for me would be this:
set( OpenCV_FOUND 1 )
find_package(OpenCV 2.4.13 REQUIRED PATHS "C:/opencv")
set(SOURCE_FILES main.cpp)
add_executable(OpenCV_Test ${SOURCE_FILES})
Note:
1- I am using the CMakeList.txt file for Clion IDE
2- I am using it under windows. Probably you may set the relevant path if you use other OS
3- You need also change the OpenCV version if you use other version