Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Sfml v3 with cmake  (Read 1155 times)

0 Members and 1 Guest are viewing this topic.

rednik

  • Newbie
  • *
  • Posts: 1
    • View Profile
Sfml v3 with cmake
« on: May 07, 2022, 01:00:12 pm »
So im trying to include latest sfml snapshot in clion, but it doesnt work

Normally, with sfml v2.5.1 (which works), my CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.22)
project(sfml)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS_RELEASE "-Ofast")
set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")

set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR "SFML-2.5.1/lib/cmake/SFML")


find_package(SFML COMPONENTS graphics audio REQUIRED)

add_executable(sfml main.cpp)

target_link_libraries(sfml sfml-graphics sfml-audio)
 

But with latest sfml and CMakeLists.txt looking like this
cmake_minimum_required(VERSION 3.22)
project(sus)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS_RELEASE "-Ofast")
set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")

set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR "sfml/lib/cmake/SFML")


find_package(SFML COMPONENTS Graphics Audio REQUIRED)

add_executable(sus main.cpp)

target_link_libraries(sus sfml-graphics sfml-audio)
 
when compiling it just gives me an error
FAILED: CMakeFiles/sus.dir/main.cpp.obj
C:\PROGRA~1\JETBRA~1\CLION2~1.1\bin\mingw\bin\G__~1.EXE   -g -std=gnu++20 -MD -MT CMakeFiles/sus.dir/main.cpp.obj -MF CMakeFiles\sus.dir\main.cpp.obj.d -o CMakeFiles/sus.dir/main.cpp.obj -c C:/Users/rednik/CLionProjects/sus/main.cpp
C:/Users/rednik/CLionProjects/sus/main.cpp:1:10: fatal error: SFML/Graphics.hpp: No such file or directory
    1 | #include <SFML/Graphics.hpp>
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
 

If Graphics and Audio are written in lowercase then cmake gives an error:
CMake Error at sfml/lib/cmake/SFML/SFMLConfig.cmake:150 (message):
  Found SFML but requested component 'audio' is missing in the config defined
  in sfml/lib/cmake/SFML.
Call Stack (most recent call first):
  CMakeLists.txt:12 (find_package)


CMake Error at CMakeLists.txt:12 (find_package):
  Found package configuration file:

    C:/Users/rednik/CLionProjects/sus/sfml/lib/cmake/SFML/SFMLConfig.cmake

  but it set SFML_FOUND to FALSE so package "SFML" is considered to be NOT
  FOUND.
 

Thanks in advance

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Sfml v3 with cmake
« Reply #1 on: May 09, 2022, 11:50:15 am »
With SFML 3 you'll, as you figured out, have to use component names that start with a capital letter (e.g. find_package(SFML COMPONENTS Graphics Audio REQUIRED)), but in addition to that, you also need to use the namespaced target names, when linking SFML, for example like this: target_link_libraries(sus SFML::Graphics SFML::Audio)

See the pull request that introduced said change: https://github.com/SFML/SFML/pull/1947
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything