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.
Related
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)
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)
I'm trying to generate a Visual Studio 2013 project like this:
cmake -G "Visual Studio 12" -T "v100" ..
My project is using some static Boost libraries like system. With Boost_DEBUG enabled, I get the following output:
[ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:930 ] Searching for SYSTEM_LIBRARY_RELEASE: libboost_system-vc120-mt-1_53;libboost_system-vc120-mt;libboost_system-mt-1_53;libboost_system-mt;libboost_system;libboost_system-vc120-mt-s-1_53;libboost_system-vc120-mt-s;libboost_system-mt-s-1_53;libboost_system-mt-s
[ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:966 ] Searching for SYSTEM_LIBRARY_DEBUG: libboost_system-vc120-mt-gd-1_53;libboost_system-vc120-mt-gd;libboost_system-mt-gd-1_53;libboost_system-mt-gd;libboost_system-mt;libboost_system;libboost_system-vc120-mt-s-gd-1_53;libboost_system-vc120-mt-s-gd;libboost_system-mt-s-gd-1_53;libboost_system-mt-s-gd
[...]
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1111 (message):
Unable to find the requested Boost libraries.
Boost version: 1.53.0
Boost include path: C:/Boost/boost_1_53_0
Could not find the following static Boost libraries:
boost_system
boost_thread
boost_date_time
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the
directory containing Boost libraries or BOOST_ROOT to the location of
Boost.
Call Stack (most recent call first):
CMakeLists.txt:8 (find_package)
I guess that cmake doesn't find the boost libraries because it searches for wrong file names. I tell it to generate a project with target platform v100, so it should search for libboost_system-vc100-mt-1_53, not libboost_system-vc120-mt-1_53, right? My installed Boost release does not include vc120 libraries, and I use other libraries that are only available as vc100. So how do I fix this?
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