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)
Related
I am doing my first steps in CMake and I have a Hello World example where I would like to use libgit2. My directory structure is the following:
- main.cpp
- CMakeLists.txt
- cmake/Modules/Findlibgit2.cmake
- libs/libgit2/include/git2.h
- libs/libgit2/debug/git/git2.lib
- libs/libgit2/debug/git/git2.dll
I would like to link it either statically, or dynamically, at least it works for the beginning. But when I execute CMake, I receive the error message below. Could anyone help me with this?
Not searching for unused variables given on the command line.
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
[cmake] Could NOT find libgit2 (missing: GIT2_LIBRARY GIT2_INCLUDE_PATH)
[cmake] Call Stack (most recent call first):
[cmake] C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
[cmake] cmake/Modules/Findlibgit2.cmake:15 (find_package_handle_standard_args)
[cmake] CMakeLists.txt:6 (find_package)
Findlibgit2.cmake
# Find git2 Library
#
# GIT2_INCLUDE_DIRS - where to find git2.h, etc.
# GIT2_LIBRARIES - List of libraries when using libgit2.
# GIT2_FOUND - True if libgit2 is found.
# GIT2_INCLUDE_PATH
find_path(GIT2_INCLUDE_PATH NAMES git2.h)
# GIT2_LIBRARY
find_library(GIT2_LIBRARY NAMES git2)
# handle the QUIETLY and REQUIRED arguments and set GIT2_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(libgit2 REQUIRED_VARS GIT2_LIBRARY GIT2_INCLUDE_PATH)
if (GIT2_FOUND)
set(GIT2_INCLUDE_DIR ${GIT2_INCLUDE_PATH})
set(GIT2_INCLUDE_DIRS ${GIT2_INCLUDE_PATH})
set(GIT2_LIBRARIES ${GIT2_LIBRARY})
endif()
mark_as_advanced(
GIT2_INCLUDE_PATH
GIT2_LIBRARY
)
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.9)
project (backend)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
find_package(libgit2 REQUIRED)
include_directories(${LIBGIT2_INCLUDE_DIR})
link_directories("backend/libs/libgit2/debug")
add_executable(backend main.cpp)
It seems like libgit2 doesn't provide a CMake package configuration file, so it would be up to you to write a Find Module or find one on the internet. The Findlibgit2.cmake file you have is a good start.
I found another libgit2 Find Module online here: Findlibgit2.cmake. This one utilizes pkg-config, leveraging the .pc file provided by libgit2 itself, but, considering you're using Windows, would require you to install pkg-config manually. This may be more trouble than it's worth.
Regarding your error message:
Unless the libgit2 package is in the standard system path, CMake will not know where to look for it. So, you must explicitly tell CMake where to look. One simple way to do this is by modifying your Findlibgit2.cmake file, using HINTS for the find_* commands:
# GIT2_INCLUDE_PATH
find_path(GIT2_INCLUDE_PATH NAMES git2.h
HINTS ${GIT2_INCLUDEDIR}
)
# GIT2_LIBRARY
find_library(GIT2_LIBRARY NAMES git2
HINTS ${GIT2_LIBRARYDIR}
)
Now, we can populate these GIT2_INCLUDEDIR and GIT2_LIBRARYDIR variables to point to the installed libgit2 package. After doing so, find_package() should then succeed in finding the package components, and you can link to git2.lib using ${GIT2_LIBRARIES}.
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.9)
project (backend)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
# Set hints so CMake knows where libgit2 is located on your machine.
set(GIT2_INCLUDEDIR ${CMAKE_CURRENT_LIST_DIR}/libs/libgit2/include)
set(GIT2_LIBRARYDIR ${CMAKE_CURRENT_LIST_DIR}/libs/libgit2/debug/git)
find_package(libgit2 REQUIRED)
include_directories(${GIT2_INCLUDE_DIR})
# Don't need this line. Use of 'link_directories' is discouraged.
link_directories("backend/libs/libgit2/debug")
add_executable(backend main.cpp)
# Add this line to link against the libgit2 libraries.
target_link_libraries(backend PRIVATE ${GIT2_LIBRARIES})
A more portable way to set these HINTS variables is to instead set them when calling cmake on the command line:
cmake -DGIT2_INCLUDEDIR=C:/path/to/libgit2/include -DGIT2_LIBRARYDIR=D:/path/to/libgit2/lib ..
This way, if you have other developers working with the project, they can point to wherever they may have libgit2 installed on their machine, eliminating the need to modify the CMakeLists.txt file.
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.
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}")
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
I've been trying to use CMake with a project I'm doing in SDL, but am running into some problems. My sdl folder for the libraries etc is located at C:\SDL\SDL-1.2.14. The error states:
Could NOT find SDL (missing: SDL_LIBRARY SDL_INCLUDE_DIR) Could NOT find SDLIMAGE (missing: SDLIMAGE_LIBRARY SDLIMAGE_INCLUDE_DIR) CMake Error at C:/Program Files (x86)/CMake
2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE): Could NOT find SDL (missing: SDL_LIBRARY SDL_INCLUDE_DIR) Call Stack (most recent call first): C:/Program Files (x86)/CMake
2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:288 (_FPHSA_FAILURE_MESSAGE) C:/Program Files (x86)/CMake
2.8/share/cmake-2.8/Modules/FindSDL.cmake:172 (FIND_PACKAGE_HANDLE_STANDARD_ARGS) CMakeLists.txt:10 (Find_Package)
Here is my CMakeLists.txt file.
Project(SDLExample)
Include(FindSDL)
Include(FindSDL_image)
set(
SOURCES
example.cpp
)
Find_Package(SDL REQUIRED)
Find_Package(SDL_image REQUIRED)
if(NOT SDL_FOUND)
message( FATAL ERROR "SDL not found!")
endif(NOT SDL_FOUND)
link_libraries(
${SDL_LIBRARY}
${SDLIMAGE_LIBRARY}
SDLmain
)
add_executable(
Example
WIN32
MACOSX_BUNDLE
{$SOURCES}
)
Any ideas?
Edit: I got it to work now by editing fields for the SDL paths in the Windows GUI. The problem is of course I can't find a way to 'backport' this back into the cmake file, so I'd have to re-edit them each time, the generated VS10 file loaded into visual studio, but none of the include paths etc for SDL were correctly loaded into the project, so it won't compile saying it does not know where SDL.h is.
You dont need to include the Find<Lib> files. find_package( <Lib> ) finds and uses those files automatically.
If you are on Windows, I think you need to set the SDLDIR environment variable to the folder where the SDL /lib and /include folders are located.