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

Author Topic: SFML 2.5 CMake configuration  (Read 16917 times)

0 Members and 2 Guests are viewing this topic.

Grundkurs

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
SFML 2.5 CMake configuration
« on: February 19, 2020, 07:52:53 pm »
I have an issue with the new CMake Build Tool. It basically works, but there is a catch.
My CMakeLists.txt file of my SFML-Program looks as follows:
cmake_minimum_required(VERSION 3.10)
project(observer4)

set(CMAKE_CXX_STANDARD 17)
set(SFML_DIR "C:/SFML")
find_package(SFML COMPONENTS graphics window system)
add_executable(observer4 main.cpp )
target_link_libraries(observer4 sfml-graphics sfml-audio)
 
When run CMake everything works smoothly.
-- Found SFML 2.5.1 in C:/SFML
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Nextcloud/C++/observer4/cmake-build-debug


1. When I compile SFML Source-Code (v.2.5.1.) with CMAKE_BUILD_TYPE set to Debug and put everything to C:/SFML, and copy all newly created dll-files...
sfml-graphics-d-2.dll
sfml-audio-d-2.dll
sfml-network-d-2.dll
sfml-system-d-2.dll
sfml-window-d-2.dll
...to the cmake-build-debug-folder of my SFML-Program where the binary that is compiled in debug-mode will get created, everything works fine; the SFML-Application starts without hassle.

But when i now repeat compiling SFML with CMAKE_BUILD_TYPE set to Release, which adds the corresponding compiled "release-SFML-Files" to C:/SFML, the compilation of the SFML-Program in debug-mode suddenly breaks.
The compilation in debug-mode fails with:
Process finished with exit code -1073741515 (0xC0000135)

In the folder C:/SFML/libs this files resides:
libsfml-audio-d.a
libsfml-graphics-d.a
libsfml-main-d.a
libsfml-network-d.a
libsfml-system-d.a
libsfml-window-d.a
[all release and debug DLL-Files]
libsfml-audio.a
libsfml-graphics.a
libsfml-main.a
libsfml-network.a
libsfml-system.a
libsfml-window.a

I did not touch the debug-dll-files in the cmake-build-debug-folder of my SFML-Program where the binary is being compiled.

When i delete
libsfml-audio.a
libsfml-graphics.a
libsfml-main.a
libsfml-network.a
libsfml-system.a
libsfml-window.a
in C:/SFML/libs, which should be no problem, because i compile the SFML-Application in debug mode, the compiler throws this error:

mingw32-make.exe[2]: *** No rule to make target 'C:/SFML/lib/libsfml-graphics.a', needed by 'observer4.exe'.  Stop.
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:75: CMakeFiles/observer4.dir/all] Error 2
mingw32-make.exe: *** [Makefile:83: all] Error 2

Why does the compiler need C:/SFML/lib/libsfml-graphics.a' ? Im compiling in debug-mode...he should rely on C:/SFML/lib/libsfml-graphics-d.a'. Same goes for the other files. when i return libsfml-graphics.a from trash, he asks for libsfml-window.a, when i return the file, he asks for libsfml-system.a etc. until it finally throws
Process finished with exit code -1073741515 (0xC0000135)
when all release-files (libsfml-audio.a, libsfml-graphics.a, etc. are back.

The weirdest thing is:
Process finished with exit code -1073741515 (0xC0000135)
goes away and the SFMl-Program starts when i copy the release-dll-files (sfml-graphics-2.dll, sfml-window-2.dll etc.) to the cmake-build-debug-folder. In fact, i can even delete all the debug-dll-files.
The Application only needs the release-files though i compiled it in debug-mode.

This is default behaviour out of the box which does not occure when i use a FindSFML.cmake file. When using FindSFML.cmake i can have all SFML-files (debug & release) in C:/SFML/libs in one place and just use the debug-dll-files for the debug build and the release-dll-files for my release-build.
« Last Edit: February 19, 2020, 08:06:24 pm by Grundkurs »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: SFML 2.5 CMake configuration
« Reply #1 on: February 19, 2020, 09:55:34 pm »
My assumption is that since you're not specifying a CMAKE_BUILD_TYPE for your own CMake script, CMake is simply inferring the type based on the libraries it finds, which then leads to your build picking release libraries, if they are provided, but since you're not providing the release DLLs, it crashes. Once you do provide them, it runs fine.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Grundkurs

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: SFML 2.5 CMake configuration
« Reply #2 on: February 20, 2020, 07:52:29 pm »
My assumption is that since you're not specifying a CMAKE_BUILD_TYPE for your own CMake script, CMake is simply inferring the type based on the libraries it finds, which then leads to your build picking release libraries, if they are provided, but since you're not providing the release DLLs, it crashes. Once you do provide them, it runs fine.

I made a screenshot where you can see that although i set CMAKE_BUILD_TYPE to Release in CMD it still complains that sfml-graphics-d-2.dll is missing. This happens only when the last compilation of the sfml-source-code in "C:/SFML" is done in debug-mode to create the debug-libraries in C:/SFML.

The same applies the other way around: When the last compilation of the SFML-Source to C:/SFML is done in release-mode, the debug-compilation of my SFML-Application will only accept release-dll-files regardless if the CMAKE_BUILD_TYPE is set to Debug. 

When i change the CMakeLists.txt of the SFML-Program to FindSFML.cmake the compiled release-executable in the cmake-build-release-folder works fine with the release-dll-files in the same folder. Same goes for the debug-version in cmake-build-debug-folder with the corresponding debug-dll-files.

EDIT: You may need to open the attached Screenshot in a new Window to see the whole picture because of its size & thanks for the fast reply btw.
 
« Last Edit: February 20, 2020, 08:11:15 pm by Grundkurs »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.5 CMake configuration
« Reply #3 on: February 21, 2020, 09:35:02 am »
It's not clear what exactly you do. Do you properly run "make install" every time you recompile SFML? You should describe in detail the full procedure to reproduce the problem, starting from scratch.
Laurent Gomila - SFML developer

Grundkurs

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: SFML 2.5 CMake configuration
« Reply #4 on: February 21, 2020, 09:42:42 pm »
Hi Laurent,
i was able to tackle the issue further down. It seems to be not related to the new SFML CMake System but to my IDE (Clion). Here are the exact steps that lead to the error i encountered. I noticed that when i compile everything "by hand" via CMD the error does not occure. However compiling with CLion provokes the error.
In Detail:

Steps:
1.   Download SFML from Github


2.   Extract ZIP-Contents to Download-Folder

3.   Open Up CMake
-   Set „Where is the source code“ to SFML-Directory in Download-Folder
-   Set „Where to build the binaries“ to C:/SFML which will be the place to store all SFML libraries


4.   Click on „Configure“, specify the Generator to „MinGW Makefiles“ since i use mingw-w64-compiler, use checkbox „Use default native compilers“, click „Ok“


5.   Set „CMAKE_BUILD_TYPE“ to „Release“
and click on „Generate“


6.   Open CMD in administrator-mode, go to C:/SFML, compile the generated CMake-Makefile with command „mingw32-make“


7.   I receive this compiled Libraries in C:/SFML/libs


8.   I copy the received dll-files (for example „sfml-graphics-2.dll“) from C:/SFML/libs to the Destination-Folder where the release-version of my SFML-Application is going to be compiled. Here it is „D:\Nextcloud\C++\observer4\cmake-build-release“


9.   I open up CMD, go to that folder where the release version of my SFML-Application is going to be created and create a makefile with the command „cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release ..“


10.   Then i compile the project with „mingw32-make“ and run the executable. It starts without issues.


11.   I go back to CMake and repeat step 5. But this time i set CMAKE_BUILD_TYPE to „Debug“ and click on generate


12.   I repeat Step 6, after compilation i have not only the release-libraries, but also the debug-libararies of SFML in „C:/SFML/libs“


13.   I copy the received dll-files (for example „sfml-graphics-d-2.dll) from C:/SFML/libs to the Destination-Folder where the debug version of my SFML-Application is going to be compiled. Here it is „D:\Nextcloud\C++\observer4\cmake-build-release“

14.   Then i create a makefile with the command „cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug ..“ and compile.
The Program runs fine.


15.   When i open my IDE Clion and run the program in release mode, it suddenly does not work anymore. The same applies when i try to start the release-version from CMD after i have tried to run it from Clion.


16. Now when i switch the content of the CMakeLists.txt file in "„D:\Nextcloud\C++\observer4\" from
cmake_minimum_required(VERSION 3.10)
project(observer4)
set(CMAKE_CXX_STANDARD 17)
set(SFML_DIR "C:/SFML")
find_package(SFML COMPONENTS graphics window system)
add_executable(observer4 main.cpp etc. etc.)
target_link_libraries(observer4 sfml-graphics)
 
to
cmake_minimum_required(VERSION 3.10)
project(observer4)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/modules)
set(SFML_ROOT "C:/SFML")
find_package(SFML COMPONENTS graphics window system)
include_directories(${SFML_INCLUDE_DIR})
add_executable(observer4 main.cpp etc. etc.)
target_link_libraries(observer4 ${SFML_LIBRARIES})
and compile everything again, the SFML-Application starts running from Clion and CMD.
« Last Edit: February 22, 2020, 02:58:09 am by Grundkurs »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.5 CMake configuration
« Reply #5 on: February 22, 2020, 08:49:43 am »
So you never run "make install"? You can't point find_package(SFML) to a build directory, it must be an install directory.
Laurent Gomila - SFML developer

Grundkurs

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: SFML 2.5 CMake configuration
« Reply #6 on: February 22, 2020, 01:44:08 pm »
i altered step Nr.6 (and Nr.12) with the command „mingw32-make install". It builds the libs in "C:\Program Files (x86)\SFML". However the strange behaviour remains the same :-(

When i don't touch Clion everything works as expected. The Release-Build and Debug-Build of my SFML-Application both gets compiled and run fine.
However when the last Build of SFML with "mingw32-make install" is done with CMAKE_BUILD_TYPE=Debug and i additionally open up Clion and run my SFML-Application in "Release-Mode" the Release-Build of my Program breaks because he searches for *-d-2.dll files (as shown in Nr.15 above).

When i erase all files in the cmake-release-build-Folder and compile everything from scratch via CMD exactly how i done it before i opened and compiled it with Clion, it compiles fine, but the application still won't start because a "*-d-2.dll" is missing which makes no sense since i did run cmake with -DCMAKE_BUILD_TYPE=Release when invoking it from the cmake-release-build-Folder.

Clion seems to scramble something because when i don't touch the SFML-Application with Clion, everything works flawlessly and as expected.

What irritates me the most is that i can't get it to run properly after i compiled my SFML-Program with Clion, except i delete C:/SFML and build it again from scratch.
« Last Edit: February 22, 2020, 02:15:18 pm by Grundkurs »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.5 CMake configuration
« Reply #7 on: February 22, 2020, 06:54:46 pm »
Quote
i altered step Nr.6 (and Nr.12) with the command „mingw32-make install". It builds the libs in "C:\Program Files (x86)\SFML". However the strange behaviour remains the same :-(
Then you must set SFML_DIR to C:\Program Files (x86)\SFML, not C:\SFML.
Laurent Gomila - SFML developer

Grundkurs

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: SFML 2.5 CMake configuration
« Reply #8 on: February 22, 2020, 08:32:13 pm »
Quote
i altered step Nr.6 (and Nr.12) with the command „mingw32-make install". It builds the libs in "C:\Program Files (x86)\SFML". However the strange behaviour remains the same :-(
Then you must set SFML_DIR to C:\Program Files (x86)\SFML, not C:\SFML.
This finally did the trick, everything works now as expected in Clion. Thanks a lot!

 

anything