SFML community forums

Help => General => Topic started by: Nirodha_Dukkha on March 16, 2019, 07:28:41 am

Title: SFML Integration in QTCreator with CMake
Post by: Nirodha_Dukkha 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.
Title: Re: SFML Integration in QTCreator with CMake
Post by: eXpl0it3r 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?
Title: Re: SFML Integration in QTCreator with CMake
Post by: NirodhaDukkha 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
Title: Re: SFML Integration in QTCreator with CMake
Post by: NirodhaDukkha 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.
Title: Re: SFML Integration in QTCreator with CMake
Post by: eXpl0it3r on March 23, 2019, 07:12:10 am
Did you copy the SFML DLLs next to your application when linking dynamically?
Title: Re: SFML Integration in QTCreator with CMake
Post by: NirodhaDukkha 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.
Title: Re: SFML Integration in QTCreator with CMake
Post by: eXpl0it3r on March 23, 2019, 06:02:41 pm
Did you build in release mode then?
Title: Re: SFML Integration in QTCreator with CMake
Post by: NirodhaDukkha on March 23, 2019, 06:47:55 pm
Yep.