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

Author Topic: Compiling SFML program with CMake on windows  (Read 6416 times)

0 Members and 1 Guest are viewing this topic.

Ryngetsu

  • Guest
Compiling SFML program with CMake on windows
« on: October 26, 2018, 11:57:29 pm »
Hello,

For the past few days I've been searching everywhere and can't seem to fix this problem or maybe I just didn't understand some answers.

I have an application (a game to be precise) built with SFML that I managed to compile on Linux with 2.4.2 version. I want to migrate to 2.5.1 and be able to compile on Windows so I changed the CMakeLists.txt file to this:

(click to show/hide)

The cmake works and generates the VS solution, that I can build with msbuild (note that I don't want to launch Visual Studio, but only use msbuild). But once I try to run it, it asks for dlls and I don't want that.

I thought that would be solved by linking statically (I don't know much about static or dynamic linking) but it still asks for them.

How can I avoid that? I want to be completely independant from DLL's or at least be able to include the bin directory installed from SFML compiled and installed binaries (that I compiled, not the precompiled).

Thank you.
« Last Edit: October 27, 2018, 10:53:45 am by Ryngetsu »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Compiling SFML program with CMake on windows
« Reply #1 on: October 30, 2018, 09:52:40 am »
target_link_libraries(${PROJECT_NAME} sfml-system sfml-window sfml-graphics sfml-network sfml-audio)

You should link the sfml-*-s targets and define the symbol SFML_STATIC to get static linkage.
set(SFML_USE_STATIC_STD_LIBS TRUE)

I think this has no effect (cmake should give you a warning), since SFML is already compiled and therefore you cannot change this behavior afterwards.


AlexAUT

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Compiling SFML program with CMake on windows
« Reply #2 on: October 30, 2018, 10:25:15 am »
Quote
You should link the sfml-*-s targets and define the symbol SFML_STATIC to get static linkage.
In CMake this is done with set(SFML_STATIC_LIBRARIES TRUE), but it must be called before find_package(SFML).

Quote
I think this has no effect (cmake should give you a warning)
Indeed, but no warning from CMake, this is creating a (useless) variable and is thus perfectly valid ;)
Laurent Gomila - SFML developer

Ryngetsu

  • Guest
Re: Compiling SFML program with CMake on windows
« Reply #3 on: October 30, 2018, 07:07:06 pm »
With set(SFML_STATIC_LIBRARIES TRUE), SFML_FOUND is set to false and I cannot go on.

Is there a CMake variable referencing to the bin directory where dll's are located so I can copy paste each of them with cmake?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Compiling SFML program with CMake on windows
« Reply #4 on: October 30, 2018, 08:14:19 pm »
Quote
With set(SFML_STATIC_LIBRARIES TRUE), SFML_FOUND is set to false and I cannot go on.
Do you have the static libraries in your SFML folder? Did you download it, or build it?

Quote
Is there a CMake variable referencing to the bin directory where dll's are located so I can copy paste each of them with cmake?
I don't think so. Maybe with some tricks, using one of the provided paths. Anyway, all you have to know is explained there.
Laurent Gomila - SFML developer

Ryngetsu

  • Guest
Re: Compiling SFML program with CMake on windows
« Reply #5 on: October 30, 2018, 10:30:23 pm »
That is another question I have, how do I build the static libraries?

Then how can I automatically copy paster the dll's into the executable directory?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Compiling SFML program with CMake on windows
« Reply #6 on: October 31, 2018, 08:06:01 am »
Quote
how do I build the static libraries?
It is explained in the tutorial about building SFML ;)

Quote
Then how can I automatically copy paster the dll's into the executable directory?
Have you tried something, based on what I said?
Laurent Gomila - SFML developer

Ryngetsu

  • Guest
Re: Compiling SFML program with CMake on windows
« Reply #7 on: October 31, 2018, 11:36:33 am »
I didn't see the part about BUIL_SHARED_LIBS, thank you it's now working.

Quote
Have you tried something, based on what I said?

I tried using ${SOME_PATH}\..\.. but it doesn't work. Anyway now I'm using the static libs so no need to do that.

It's now working
Thank you for your help.