SDL CMake Error - compilation

When running cmake . in my project directory, I get the following error:
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find SDL (missing: SDL_LIBRARY SDL_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindSDL.cmake:176 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:4 (find_package)
My CMakeLists.txt is as follows:
cmake_minimum_required(VERSION 2.8)
project( MoakRaster )
add_executable( MoakRaster MoakRaster.c )
find_package (SDL REQUIRED)
include_directories(${SDL_INCLUDE_DIR})
target_link_libraries (MoakRaster ${SDL_LIBRARY})
I've installed and removed and reinstalled both libsdl2-2.0 and libsdl2-2.0dev a hundred times, and downloaded the source and installed all the dependencies the source had, just in case sudo apt-get install libsdl2-2.0 wasn't including all of the dependencies.
The only thing I haven't done yet is compile the binary from the source code, which I'd rather not do because I'd prefer to keep extraneous files out of my project for now. If this is a known issue with FindSDL.cmake however, I'll start looking into making my own binary :/
EDIT: Apparently I needed SDL1.2.
EDIT2: And apparently SDL1.2 is borked now, since most of the documentation out there is for SDL2.0. Plus, none of the SDL calls/types work. Back to where I started.
EDIT3: Forget it, switching back to gcc. cmake and SDL are borked. It works.

Related

How to find Google Test with find_package using CMake on Windows?

I have tried without success to use the find_package function in CMake to make use of a pre-built "system wide" version of GTest in Windows. Here is a minimal, reproducible example of my CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
find_package(GTest REQUIRED)
if(NOT GTEST_LIBRARY)
message("GTest not found!")
endif()
I try to generate build files using the following command:
cmake .. -G"Visual Studio 14 2015" -DGTEST_ROOT="c:\Libs\googletest"
The c:\Libs\googletest path contains my pre-built GTest (with header files and binaries). I have studied the FindGTest.cmake file in my CMake installation (I use CMake version 3.13.3) and tried all kinds of folder structure, but I always get the following error message:
CMake Error at C:/Program Files/CMake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR
GTEST_MAIN_LIBRARY)
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.13/Modules/FindGTest.cmake:196 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:2 (find_package)
Has anyone succeeded in using find_package for GTest in Windows? If so, how did you do it?
First you must build AND install Googletest using CMake build system
Then try to locate the GTestConfig.cmake file in the installation directory
So now you can add this path to the CMAKE_PREFIX_PATH variable.
Thus configuring your project using CMake, it should be able to find_package(GTest) using the usual search procedure.
So you just have to use GTest::GTest to consume it (i.e. target_link_libraries(.... GTest::GTest) ).
note: For people using FetchContent/add_subdirectory(googletest) beware google/googletest still not provide ALIAS target see https://github.com/google/googletest/issues/2429

Cmake won't find correct version of Boost

I am trying to build some code using cmake. The code uses some Boost libraries. Because of that I try to find Boost in the cmakefile:
find_package(Boost 1.65.1 REQUIRED COMPONENTS unit_test_framework program_options )
I have installed boost version 1.58 via apt (I am using Linux Mint 18.3), so I obviously get the error message when trying to cmake the code:
CMake Error at /usr/share/cmake-3.5/Modules/FindBoost.cmake:1677 (message):
Unable to find the requested Boost libraries.
Boost version: 1.58.0
Boost include path: /usr/include
Detected version of Boost is too old. Requested version was 1.65.1 (or newer).
Call Stack (most recent call first):
CMakeLists.txt:14 (find_package)
-- Configuring incomplete, errors occurred!
So I went on and downloaded Boost 1.65.1 by source and built it the intended way and installed it with the prefix
sudo ./b2 install --prefix=/usr/include
When I try to build the code again, it still gives the exact same error message as before, stating that it didn't find the newer version. I have tried to uninstall version 1.58 and build, but then cmake doesn't find Boost at all.
How can I install Boost in a way, that cmake is able to find it?
Thanks in advance,
cheers!
When changing the version information of Boost in a find_package(Boost) call you need to clear the CMakeCache.txt file. Otherwise the cached information from the previous run is used.

How to compile libgit2 on windows using cmake?

I am trying to compile libgit2 and followed the instruction on https://libgit2.github.com/docs/guides/build-and-link/ but lock so far.
Can someone tell me what to do?
Here is the result from my command line:
-- Building for: Visual Studio 12 2013
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
-- zlib was not found; using bundled 3rd-party sources.
-- LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.
CMake Error at d:/cmake/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE)
Call Stack (most recent call first):
d:/cmake/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
d:/cmake/share/cmake-3.3/Modules/FindPythonInterp.cmake:162 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:594 (FIND_PACKAGE)
-- Configuring incomplete, errors occurred!
See also "D:/temp/gitlib/libgit2-master/build/CMakeFiles/CMakeOutput.log".
See also "D:/temp/gitlib/libgit2-master/build/CMakeFiles/CMakeError.log".
Thanks,
libgit2 uses python (works both with versions 2 and 3 of the language) to build the tests. You can install python or ask CMake not to build the tests.
IIRC CMake will look in a few standard locations you don't necessarily need python in your path, though it doesn't hurt.
If you would rather not build the tests, you can pass -DBUILD_CLAR=OFF so it doesn't bother looking for python.
Download Python from Paython.org and install it (i.e. d:\python). Then Open your VS command line and type PATH D:\Python\Python35-32;d:\cmake\bin;%PATH%
That's all set now, go to your build folder run cmake .. and then cmake --build .

CMake reports 'Boost_DIR-NOT_FOUND' when trying to find Boost

I want to build a library called CSWNet on my machine. Cmake can find Boost_INCLUDE_DIR and Boost_LIB_DIR but it cannot find an option called Boost_DIR which is a directory containing a CMake configuration file for Boost. Where is it? Please help, thanks ahead. The error I got is shown below and I installed boost from ubuntu repository and it's installed in /usr/local.
CMake Error at /usr/local/share/cmake-2.8/Modules/FindBoost.cmake:429 (message):
When requesting a specific version of Boost, you must provide at least the
major and minor version numbers, e.g., 1.34
Call Stack (most recent call first):
demos/CMakeLists.txt:149 (find_package)
It seems you misunderstood the meaning of Boost_DIR.
Boost_DIR is an environment variable used as a hint by CMake to find the boost installation directory. If this is set to Boost_DIR-NOTFOUND that does not mean that it did not find Boost. Boost_FOUND is used to indicate whether the search was successful:
find_package(Boost REQUIRED thread)
if(Boost_FOUND)
message(STATUS "Success!")
endif()
In case of a successful search, CMake will also print a diagnostic message during the configure phase which looks something like
Boost version: 1.53.0
Found the following Boost libraries:
thread
Hope its not too late to post this.
Passing it in the command line along with cmake command would resovle it
cmake -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=dist -DBOOST_DIR="boost installation location"

cmake cannot find glib2

On OS X 10.8.2, I have macports and have installed:
glib2
pkg-config
among other things. The cmake I run tries to use pkg-config to find glib2. Running pkg-config --libs glib-2.0:
-L/opt/local/lib -lglib-2.0 -lintl
and --cflags:
-I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include
Yet, when I try to enter these in (individually, or all of them using ; or :), and all sorts of combinations, or when I tried downloading gtk and using the glib2 dirs of that: cmake complains it can't find the directories:
checking for module 'gstreamer-0.10'
found gstreamer-0.10, version 0.10.36
checking for module 'glib-2.0'
found glib-2.0, version 2.34.3
CMake Error at /Applications/CMake 2.8-10.app/Contents/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (message):
Could NOT find GLib2 (missing: GLIB2_LIBDIR GLIB2_INCLUDE_DIRS)
Call Stack (most recent call first):
/Applications/CMake 2.8-10.app/Contents/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:291 (_FPHSA_FAILURE_MESSAGE)
cmake/Modules/FindGLib2.cmake:127 (find_package_handle_standard_args)
cmake/Modules/FindGStreamer.cmake:12 (find_package)
CMakeLists.txt:32 (find_package)
I saw this page about conflicting pkg-config's with MonoDevelop. I uninstalled Mono, don't have any other pkg-config binaries that I can find, and cleared the cmake cache without any luck. I've looked at the cmake specifics, and its looking for glib.h and glibconfig.h, which are in those directories. Why can't it just behave?
Try to use this file: http://svn.opensync.org/branches/3rd-party-cmake-modules/modules/FindGLIB2.cmake
In your main CMakeLists.txt file, enter the following line:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/helper/")
This is assuming that the above FindGLIB2.cmake is stored in directory /helper off the src.
The contents of this file will help CMake to better find GLIB2.
This link will help you understand how these files work: http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries#Writing_find_modules
I faced this problem while building wireshark-3.4.2 from source using cmake on Centos8.2/RHEL8.2. The error was
Could NOT find GLIB2 (missing: GLIB2_LIBRARY GLIB2_MAIN_INCLUDE_DIR GLIB2_INTERNAL_INCLUDE_DIR) Required is at least version "2.32.0")
while my system had preinstalled glib-2.56.4
Solution: Installed glib2-devel package. Then cmake found the glib-2.0 properly.
The cmake output looked like:
-- Checking for one of the modules 'glib-2.0'
-- Found GLIB2: /usr/lib64/libglib-2.0.so (found suitable version "2.56.4", minimum required is "2.32.0")

Resources