Frnake
Frnake

Reputation: 9

Missing sfml libraries for cmake

C++ newbie here, I'm trying to implement SFML library for CLion (Win 10).

I followed this http://www.sfml-dev.org/tutorials/2.0/compile-with-cmake.php guidelines and installed sfml using cmake gui and mingw.

Now when I try to include SMF libraries to project in CMakeLists.txt

cmake_minimum_required(VERSION 3.6)
project(untitled2)
set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
add_executable(untitled2 ${SOURCE_FILES})

set(CMAKE_MODULE_PATH "C:/Program Files (x86)/SFML/cmake/Modules"${CMAKE_MODULE_PATH})

set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML COMPONENTS graphics window system REQUIRED)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(First ${SFML_Libraries})

Howewer, i'm getting an error

CMake Error at C:/Program Files (x86)/SFML/cmake/Modules/FindSFML.cmake:355 (message):
  SFML found but some of its dependencies are missing ( FreeType libjpeg)
Call Stack (most recent call first):
CMakeLists.txt:13 (find_package)

But I thought those libs are included in Windows. I am doing something wrong? Where should I place FreeType and libjpeg files if I were to download them?

Upvotes: 1

Views: 2765

Answers (1)

Mario
Mario

Reputation: 36497

You shouldn't set any local system specific things (like paths) in your CMakeLists.txt. This defeats the whole purpose of a build system.

First, I'd suggest you create a sub directory "cmake" in your project and copy SFML's FindSFML.cmake module in there.

Then update your CMAKE_MODULE_PATH accordingly:

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

This will ensure the module is found. CMake's default modules are always found, you don't have to preserve the previous value of the variable (should typically be empty anyway).

Next, when creating your actual project files, you'll just have to pass SFML_ROOT to CMake, for example:

cmake "-DSFML_ROOT=C:/Program Files (x86)/SFML" path/to/source

In a similar way, you shouldn't set SFML_STATIC_LIBRARIES in your CMakeLists.txt unless you're somehow forced to use static libraries. So I'd actually add that to the command line as well:

cmake "-DSFML_ROOT=C:/Program Files (x86)/SFML" -DSFML_STATIC_LIBRARIES=TRUE path/to/source

You only have to set these once, they're stored in your CMakeCache.txt file later.

Last but not least, if you'd like to support static linking with SFML, you'll have to link SFML's dependencies as well:

target_link_libraries(First ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})

Note that all these won't fix the error message you're getting. For some reason SFML's prebuilt dependencies aren't in C:\Program Files (x86)\SFML\lib. Are you sure you've got the correct prebuilt package?

Upvotes: 1

Related Questions