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

Author Topic: SFML Integration in QTCreator with CMake  (Read 2429 times)

0 Members and 1 Guest are viewing this topic.

Nirodha_Dukkha

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
SFML Integration in QTCreator with CMake
« on: March 16, 2019, 07:28:41 am »
Hi all,

I'm trying to get a project built using QTCreator and CMake.

I've successfully run the CMake gui and mingw-32 to build SFML in D:/SFML, and now I'm trying to make a simple QTCreator project that includes some SFML libraries.  My CMakeLists is as follows:

cmake_minimum_required(VERSION 3.1)
project(Learning)

set(SFML_DIR "D:/SFML/lib/cmake/SFML")
find_package(SFML 2.5 COMPONENTS graphics audio system REQUIRED)

add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(SFMLTest sfml-graphics sfml-audio)


When I ask QTCreator to run CMake, it gives me the following error:

Could not find a configuration file for package "SFML" that is compatible
  with requested version "2.5".

The following configuration files were considered but not accepted:

D:/SFML/lib/cmake/SFML/SFMLConfig.cmake, version: 2.5.1 (32bit)



As far as I can tell, I've exactly followed the sticky post in this forum about migrating to SFML 2.5+... any ideas what could be going wrong?  I'm a few days into google searching for help, with no luck.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: SFML Integration in QTCreator with CMake
« Reply #1 on: March 16, 2019, 09:20:08 am »
Are you using a different compiler as part of the QtCreator (e.g. x86 vs x64 mismatch)?
Are the SFML libraries located at D:\SFML\lib?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

NirodhaDukkha

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: SFML Integration in QTCreator with CMake
« Reply #2 on: March 23, 2019, 01:59:52 am »
I've advanced the problem a bit, but still can't get a simple program to run.

I did the following, in order:

1) Got SFML source from github
2) Ran CMake, producing mingw32 makefile
3) Ran mingw32-make in the build directory, successfully building SFML
4) Created a QTCreator project, picked mingw32 as the compiler
5) Produced the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.1)

project(LearnCMake)
set(SFML_DIR D:/Programming/Libraries/SFML)
find_package(SFML COMPONENTS window system REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} sfml-window sfml-system)


6) Successfully built the program with QTCreator

When I run the project from QTCreator, it says:

"The program has unexpectedly finished."


Do I need to move/copy the libraries of interest out of the SFML build directory and into my project or something? So many hours... so close...

@eXplo0it3r:  Following your response and some other reading, I've made sure to use the same compiler for both. My SFML libraries are located at D:\Programming\Libraries\SFML\lib

NirodhaDukkha

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: SFML Integration in QTCreator with CMake
« Reply #3 on: March 23, 2019, 04:37:05 am »
Update:

I ran CMake again to configure it to build static libraries and included

set(SFML_STATIC_LIBRARIES TRUE)


in my CMakeLists.txt file and, voila, the program runs and I have a window!

I'm still curious to know what I was doing wrong with dynamic libraries, though.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: SFML Integration in QTCreator with CMake
« Reply #4 on: March 23, 2019, 07:12:10 am »
Did you copy the SFML DLLs next to your application when linking dynamically?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

NirodhaDukkha

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: SFML Integration in QTCreator with CMake
« Reply #5 on: March 23, 2019, 05:34:14 pm »
I did. I copied
sfml-system-2.dll
and
sfml-window-2.dll
into my build directory.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: SFML Integration in QTCreator with CMake
« Reply #6 on: March 23, 2019, 06:02:41 pm »
Did you build in release mode then?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

NirodhaDukkha

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: SFML Integration in QTCreator with CMake
« Reply #7 on: March 23, 2019, 06:47:55 pm »
Yep.

 

anything