Custom path for my libraries for find_library - cmake

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.

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"

How can I use cmake to locate jupyter notebook installation

Is there a way to use cmake find_package() to locate jupyter_notebook installation?
I tried
FIND_PACKAGE(jupyter-notebook REQUIRED)
but it errors out with
CMake Error at CMakeLists.txt:15 (FIND_PACKAGE):
By not providing "Findjupyter-notebook.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"jupyter-notebook", but CMake did not find one.
Could not find a package configuration file provided by "jupyter-notebook"
with any of the following names:
jupyter-notebookConfig.cmake
jupyter-notebook-config.cmake
Add the installation prefix of "jupyter-notebook" to CMAKE_PREFIX_PATH or
set "jupyter-notebook_DIR" to a directory containing one of the above
files. If "jupyter-notebook" provides a separate development package or
SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
However, it has been installed:
apt-cache show jupyter-notebook
There are a few options when using the find_package command, MODULE and CONFIG. For this case, you likely want the CONFIG setting. The error message is trying to help here. Did either of these files come with the jupyter-notebook installation?
jupyter-notebookConfig.cmake
jupyter-notebook-config.cmake
If so, try setting CMAKE_PREFIX_PATH or jupyter-notebook_DIR to the directory where jupyter-notebook was installed. So you might try something like the following:
list(APPEND CMAKE_PREFIX_PATH /path/to/your/installation) # Try this one.
# SET(jupyter-notebook_DIR /path/to/your/installation) # Or try this one.
FIND_PACKAGE(jupyter-notebook CONFIG REQUIRED)
If your installation does not appear to have the aforementioned CMake config files, nor does it appear to have any CMake support files (a cmake directory, etc.), the find_program command is likely more appropriate for jupyter-notebook.
I suggest spending some time with the documentation for find_package, as it explicitly lays out the search paths (in order) CMake uses to find your packages. Also, check out this answer.

PROTOBUF_GENERATE_CPP binary path

How does PROTOBUF_GENERATE_CPP know where to pick up the protoc binary from?
I have compiled protobuf locally and would like to point my CMakeLists.txt to the installed binary ( myfolder/protobuf-install/bin/protoc ) and not the system binary ( /usr/bin/protoc )
Normally for Boost, I would just set the BOOST_ROOT to my installed folder and it will find all the include_directories, libraries, etc.
How should it be done for Protobuf. I dont see any prefix option in the FindProtobuf.cmake.
set( Protobuf_SRC_ROOT_FOLDER "${CMAKE_SOURCE_DIR}/myfolder/")
find_package(Protobuf MODULE REQUIRED)
The error is
file STRINGS file "/usr/include/google/protobuf/stubs/common.h" cannot be read.
Call Stack (most recent call first):
CMakeLists.txt:17 (find_package)
Ofcourse, the above path is in myfolder/ and not in the system folder. But why is protobuf looking for includes in the system path, when I have explicitly declared the root path as myfolder/
Module FindProtobuf.cmake has a nice description of how to hint it with various things. E.g., hinting with executable could be performed with setting Protobuf_PROTOC_EXECUTABLE variable:
The following cache variables are also available to set or use:
...
Protobuf_PROTOC_EXECUTABLE
The protoc compiler
cmake -DProtobuf_PROTOC_EXECUTABLE=myfolder/protobuf-install/bin/protoc
Also, common CMAKE_PREFIX_PATH variable works well, see that question: Hinting Find<name>.cmake Files with a custom directory.

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