Work with the SFML in CLion

Here is how to easily link to his project the SFML with CMake under CLion

Published May 15, 2017

Many forums have people who have difficulty linking SFML to their C ++ project. If you have adopted the CLion IDE — that I highly recommend —, here is the very simple procedure to use the SFML.

Place FindSFML.cmake at the root of the project

If you are on Linux, go to the directory "[Your_SFML_location]/share/SFML/cmake/Modules/".

If you are on Windows or Mac OS X, go to "[Your_SFML Location]/cmake/Modules/".

Then, you copy the file FindSFML.cmake.
Finally, you paste it into the root of the CLion project.

Configure CMake

The CMake configuration file (CMakeLists.txt) is then presented in this form:

cmake_minimum_required(VERSION 3.7)
project([your_project])

# Define the source and the executable
set(EXECUTABLE_NAME "[name_executable]")
add_executable(${EXECUTABLE_NAME} [project_files])


# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}" ${CMAKE_MODULE_PATH})
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()

Work with peace of mind

That's it! You can now use the SFML. I hope this article will help you solve your problem.

Easily determine if a point belongs to a triangle
April 8, 2017