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

Author Topic: Using SFML with CLion on Windows with MSVC2022 x64 toolchain CMake and Ninja  (Read 2652 times)

0 Members and 1 Guest are viewing this topic.

junglie85

  • Newbie
  • *
  • Posts: 4
    • View Profile
I'm trying to use SFML on Windows 10 with CLion as my IDE - this is CMake based with the Ninja generator. I'm using the MSVC2022 x64 toolchain. Although I can build the SFML library (from source - master branch, which I believe is version 3.0) I can't get my project to build.

I get the following error:

Code: [Select]
"C:\Program Files\JetBrains\CLion 2022.1\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2022.1/bin/ninja/win/ninja.exe" -G Ninja -S D:\cs4300\a2 -B D:\cs4300\a2\cmake-build-debug
CMake Error at D:/Software/SFML/sfml-install/lib/cmake/SFML/SFMLConfig.cmake:150 (message):
  Found SFML but requested component 'audio' is missing in the config defined
  in D:\Software\SFML\SFML-install\lib\cmake\SFML.
Call Stack (most recent call first):
  CMakeLists.txt:11 (find_package)


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

    D:/Software/SFML/SFML-install/lib/cmake/SFML/SFMLConfig.cmake

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


-- Configuring incomplete, errors occurred!
See also "D:/cs4300/a2/cmake-build-debug/CMakeFiles/CMakeOutput.log".

My CMakeLists.txt includes:

Code: [Select]
find_package(SFML 3 COMPONENTS system window network graphics audio REQUIRED)

list(APPEND THIRD_PARTY_LIBS sfml-system)
list(APPEND THIRD_PARTY_LIBS sfml-window)
list(APPEND THIRD_PARTY_LIBS sfml-network)
list(APPEND THIRD_PARTY_LIBS sfml-graphics)
list(APPEND THIRD_PARTY_LIBS sfml-audio)

add_executable(sfml_game main.cpp ..others..)

target_link_libraries(sfml_game PRIVATE ${THIRD_PARTY_LIBS})

If I compile the SFML 2.5.1 source, I get different errors. I can run the program (obviously changing the SFML version for find_package) but it crashes as unable to load a font and spits out a load of odd symbols in the error message too.

I'm compiling with (and also tried -DBUILD_SHARED_LIBS=OFF):

Code: [Select]
mkdir SFML-build
cd SFML-build
cmake -GNinja ..\SFML-master
ninja all
cmake --install . --prefix ..\SFML-install

I've spent all day trying to get this to work, which is extremely frustrating as my other computer as a mac where it just works. Any assistance getting this to compile and link would be much appreciated.

burn.it.all.down

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
I use MSVC2019 + CLion 2022.1 (using CMake 3.21) + SFML 2.5.1 and here's the CMake project template I use for it:

# use static libs
set( SFML_STATIC_LIBRARIES TRUE )

#directory where the cmake files for SFML are. You will want to change this to wherever your SFML installation is
set( SFML_DIR "D:/projects/SFML-2.5.1/lib/cmake/SFML" )
find_package(SFML 2.5 COMPONENTS graphics window main network audio REQUIRED)

target_link_libraries( ${PROJECT_NAME}
    PRIVATE

    sfml-graphics
    sfml-window
    sfml-main
    sfml-network
    sfml-audio
    )
 

Unless you're altering the source, have some system-specific optimizations you require, or want to perform testing on the (unstable) master branch, I wouldn't bother building from source. There are binaries available for Windows here: https://www.sfml-dev.org/download/sfml/2.5.1. In your case, both the 2015 and 2017 versions will work.

junglie85

  • Newbie
  • *
  • Posts: 4
    • View Profile
Ah, perfect, thank you! I had tried that but without setting the SFML_DIR - I completely missed that for some reason. I appreciate your help and thanks for sharing the CMake snippet.

 

anything