SFML 2.5+ and CMake

Viewed 594

With the removal of FindSFML.cmake in SFML 2.5, what is the preferred way of importing it?

I tried this, but it can't find SFMLConfig.cmake

cmake_minimum_required(VERSION 3.17)
project(untitled)

set(CMAKE_CXX_STANDARD 20)

find_package(SFML 2.5.1 COMPONENTS graphics REQUIRED)
add_executable(untitled "main.cpp")
target_link_libraries(untitled sfml-graphics)

The SFML directory is inside the project. I am using CMake with CLion on macOS Catalina

2 Answers

I'm also using clion and SFML inside a project directory and that's what I'm usually doing:

if(WIN32)
    set(LIB_DIR libraries/win)
    set(SHRD_EXT dll)
else()
    set(LIB_DIR libraries/unix)
    set(SHRD_EXT so)
endif(WIN32)

# find SFML 2.5
set(SFML_DIR ${LIB_DIR}/SFML-2.5.1/lib/cmake/SFML/)
find_package(SFML 2.5 COMPONENTS graphics window system audio network REQUIRED)```

In libraries/win and libraries/unix I have platform-specific sfml library.

I use sfml on both windows and linux depending on what device im on

My boiler plate CMakeLists.txt looks as follows:

cmake_minimum_required(VERSION 3.16)

project(AppName)

# Windows specific config
IF (WIN32)
    # Include local sfml cmake config
    set(SFML_DIR "C:/lib/SFML-2.5.1/lib/cmake/SFML")
    # Link sfml statically (Optional)
    set(SFML_STATIC_LIBRARIES TRUE)
ENDIF()

find_package(SFML 2.5.1 COMPONENTS graphics audio REQUIRED)

FILE(
    GLOB
    SOURCES
    "src/*.cpp"
)

add_executable(AppName ${SOURCES})

target_link_libraries(AppName sfml-graphics sfml-audio)

target_include_directories(AppName
    PRIVATE
    "${PROJECT_BINARY_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/include"
)
Related