Building static FormBuilder from most recent SFML from Github

Started by cuddlyogre, 15 November 2013, 14:24:17

cuddlyogre

In order to build FormBuilder using static libs, you need to add the following to the dependencies, on Windows at least. Without these, you get a host of unresolved symbols.

I am using the most recent SFML from Github.


[SFML_ROOT]\lib\jpeg.lib
[SFML_ROOT]\lib\glew.lib
[SFML_ROOT]\lib\freetype.lib
winmm.lib

texus

I'll look into this later today or tomorrow.
This must have been a result from a recent sfml change.

texus

I think I found a fix, but I need you to comfirm that it is working (I have dozens of tgui and sfml versions on my pc for various compilers, so it is easy for me to make a small mistake and point to the wrong directory).

First of all, you will need to copy the file SFML/cmake/Modules/FindSFML.cmake to TGUI/cmake/Modules (overwrite the file in there so that it becomes the latest version).

Then in TGUI/src/TGUI/FormBuilder/CMakeLists.txt copy the following code to line 17 (right after linking to sfml and tgui)
# When linking statically, also link the sfml dependencies
if (SFML_STATIC_LIBRARIES)
    target_link_libraries(FormBuilder ${SFML_GRAPHICS_DEPENDENCIES} ${SFML_WINDOW_DEPENDENCIES} ${SFML_SYSTEM_DEPENDENCIES})
endif()


Can you confirm that this solves the problem?
I had to set the location of the dependencies manually in cmake (they are in SFML/extlibs), so I still have to find a way to make cmake look there automatically. But I first want to make sure that it works for you too before making more changes to the cmake script.

By the way, when building the form builder yourself on windows it will be placed in TGUI/build/src/TGUI/FormBuilder, so don't forget to replace the one in TGUI/form-builder with this executable or you will still be using the older version.

cuddlyogre

That worked like a charm.

To simplify matters, in cmake-gui you can set CMAKE_MODULE_PATH to "SFML-Location/cmake/Modules" and as far as I can tell everything still builds and compiles like it should.

Would you be willing to add the formBuilder to the install process so that the executable and related files go to ${CMAKE_INSTALL_PREFIX}/formbuilder? I'm on Windows, so this doesn't happen automatically for me.

texus

QuoteTo simplify matters, in cmake-gui you can set CMAKE_MODULE_PATH to "SFML-Location/cmake/Modules" and as far as I can tell everything still builds and compiles like it should.
So if you just copy all the files from there into the TGUI/cmake/Modules and you build it with the current settings then it all works without manually setting the dependencies locations? Or do I really have to set it to the sfml folder?
(sorry for all these questions, I can't test it myself right now)

QuoteWould you be willing to add the formBuilder to the install process so that the executable and related files go to ${CMAKE_INSTALL_PREFIX}/formbuilder? I'm on Windows, so this doesn't happen automatically for me.
I once did but it didn't went well.
In visual studio I never got it working, I didn't know how to tell it to install it instead of just compiling it. This problem can be worked around though if I would tell in the tutorial to compile with NMake Makefiles instead of letting you create a visual studio project (because then I can tell to run 'nmake install').
In codeblocks you had to just change the target from 'all' to 'install' (which seemed to work for some time), but I started getting privilage problems later (it tried to install to Program Files and it failed).
I'd like to install it to the correct folder, but it would take a lot of work and time. And I don't have much time these days and I hate working on windows, so this doesn't seem like something that I will do very soon.

But why do you really need to build the latest version? The reason that I ship tgui with an already working windows executable is because I know that it is hard to compile it decently on windows.

cuddlyogre

Quote from: texus on 17 November 2013, 10:18:30So if you just copy all the files from there into the TGUI/cmake/Modules and you build it with the current settings then it all works without manually setting the dependencies locations? Or do I really have to set it to the sfml folder?

If you copy FindSFML.cmake from the SFML install location to the TGUI cmake/Modules it will build properly. If you're using cmake-gui, you can also manually set CMAKE_MODULE_PATH to the SFML/cmake/Modules path and it will build successfully too, since it winds up pointing to the same file. I like the second option because of its simplicity for the user, on Windows at least.

As for building on my own, I want to make sure I want to make sure I'm using the most up to date version of SFML with the form builder since it's also being used in my game. It's one less thing to think about.

If you want, I can look into making the install process how I was requesting. I've already kind of been working on it.

texus

QuoteIf you copy FindSFML.cmake from the SFML install location to the TGUI cmake/Modules it will build properly. If you're using cmake-gui, you can also manually set CMAKE_MODULE_PATH to the SFML/cmake/Modules path and it will build successfully too, since it winds up pointing to the same file.
I wasn't talking about just FindSFML.cmake, I was talking about the other files. I am trying to understand what I have to do to make cmake find the dependencies to jpeg, glew and freetype automatically.
The questions basically are:
- Does cmake find these dependencies automatically without changing the settings? (apparently not)
- Does cmake find them when setting CMAKE_MODULE_PATH to the sfml folder?
- If the above question is yes, is it enough to copy ALL the files from SFML/cmake/Modules to TGUI/cmake/Modules and then just leave CMAKE_MODULE_PATH to its default value?

QuoteI like the second option because of its simplicity for the user, on Windows at least.
Well, once this problem is solved, the necessary files will be in TGUI/cmake/Modules by default and you don't even have to change the CMAKE_MODULE_PATH option or copy any files at all.

QuoteAs for building on my own, I want to make sure I want to make sure I'm using the most up to date version of SFML with the form builder since it's also being used in my game. It's one less thing to think about.
Building the form builder against SFML 2.0 or against the github version of sfml isn't going to make any difference at all. It only makes a difference with which tgui version it is compiled, and the current form builder is only a few commits behind.
If you use the latest sfml version then you will of course need to compile tgui against this latest version, but recompiling the form builder isn't needed.

QuoteIf you want, I can look into making the install process how I was requesting.
That would be really kind. You probably have more experience with developing on windows than me, so maybe you can make it work.

cuddlyogre

Quote- Does cmake find them when setting CMAKE_MODULE_PATH to the sfml folder?
- If the above question is yes, is it enough to copy ALL the files from SFML/cmake/Modules to TGUI/cmake/Modules and then just leave CMAKE_MODULE_PATH to its default value?

FindSFML.cmake is the only file in the SFML/cmake/Modules folder. Copying it to the the TGUI/cmake/Modules folder allows cmake to find the the required dependencies and everything builds as it should.

I suppose it really doesn't make much sense to build the form builder now that you bring it up. I guess I'm doing it mostly for the sake of completeness.

texus

Quote from: cuddlyogre on 17 November 2013, 12:49:28
FindSFML.cmake is the only file in the SFML/cmake/Modules folder.
I use this as a reference: https://github.com/LaurentGomila/SFML/tree/master/cmake/Modules

Quote from: cuddlyogre on 17 November 2013, 12:49:28
Copying it to the the TGUI/cmake/Modules folder allows cmake to find the the required dependencies and everything builds as it should.
Really? When I tried that then cmake complained that it couldn't find the dependencies and I had to set them manually. I'm not sure what we are doing differently. Anyway, I guess I can already safely update the FindSFML.cmake script in tgui without breaking anything new.

cuddlyogre

Are you using the Github sources as SFML_ROOT or are you building then installing SFML and using that as your SFML_ROOT? For me, cmake complains about missing files if SFML_ROOT is set to the Github sources.

The process behind how I got everything to compile and build is as follows.

Download most recent SFML sources.
Use cmake-gui to create a Visual Studio solution that will build the static libraries.
Inside of the solution, I run Build on the INSTALL project, which creates an SFML distribution that I will use as SFML_ROOT

Download most recent TGUI sources with the FindSFML.cmake change.
I apply the line 17 patch you provided earlier.
I set SFML_ROOT to the location that I built and installed SFML to.
I untick TGUI_SHARED_LIBS and tick TGUI_BUILD_FORM_BUILDER.
I hit configure and it finds FREETYPE_LIBRARY GLEW_LIBRARY JPEG_LIBRARY
I hit configure again since those are showing red.
I hit Generate.

The solution that cmake spits out using this process works like a charm. No need to change the CMAKE_MODULE_PATH or copy any files. SFML_ROOT just needs to be set to a SFML source location that has been created through the install process.

texus

QuoteAre you using the Github sources as SFML_ROOT or are you building then installing SFML and using that as your SFML_ROOT? For me, cmake complains about missing files if it SFML_ROOT is set to the Github sources.
I just wanted to respond on that you said that FindSFML.cmake was the only file in that folder. I pointed to the contents of that folder in the latest sfml version to show that there should be multiple files. I didn't do anything, I haven't even opened cmake today :).

But anyway, I have now applied the patch in the master branch. So everything should work now without changes.
Thanks for your help.

But I think other people might still have problems with this. I think that it finds the dependencies because you install sfml. I don't install sfml which might explain why it didn't found the dependencies for me yesterday. But the automatically finding isn't really a big issue, especially because you shouldn't be building the form builder on windows in the first place. And at least I can just tell people to just try to install sfml.
And with a little luck, I just did something wrong yesterday, and it will just work out-of-the-box.