SFML / CSFML

Official binding of SFML for C
https://www.sfml-dev.org
Other
349 stars 124 forks source link

How to build static libs using CMake #309

Closed jarroddavis68 closed 2 months ago

jarroddavis68 commented 2 months ago

Still, I cannot get this to work. I can build SFML static lib via Cmake (gui) no probelm, but when I try to then build CSFML, I get this:

image
eXpl0it3r commented 2 months ago

Are you using CSFML master?

Maybe it's because of #286 Try using SFML_ROOT instead

jarroddavis68 commented 2 months ago

Are you using CSFML master?

Maybe it's because of #286 Try using SFML_ROOT instead

yes, master. Hmm, don't see a SFML_ROOT branch. Looking at #286 comments, says it was removed.

eXpl0it3r commented 2 months ago

Sorry, it's not a branch, I meant use SFML_ROOT instead of SFML_DIR 😅

jarroddavis68 commented 2 months ago

Ok, thanks for you help, finally got it to work. Here are a few issues still when trying to build CSFML as a static:

ChrisThrasher commented 2 months ago

See https://github.com/SFML/CSFML/pull/311

the target ext remains as .dll rather than .lib (I have to manually change)

I took a look at this and am not sure what is causing it. As far as I'm aware we don't go out of our way to change the file extension of Windows static libs but perhaps I'm overlooking something.

EDIT: I think I know what is causing this and will find a fix.

I see the following could not find messages, but everything seem to build

This is expected and does not signify an error.

CSMFL_XXX_EXPORTS are not defined so you get inconsistent linkage error (I have to manually define each)

Fixed in #311

Finally, if you define a install location for CSFML and run install, as a shared lib build, it will move the files into the correct location, however for static you get this error:

The CI jobs I added in #311 seem to be able to install the static libraries without issue so I'm not sure why it's failing for you.

jarroddavis68 commented 2 months ago

@ChrisThrasher Thanks!

One thing I forgot, SFML will do /MT, of which I have it set, but CSFML defaults to /MD can you check on this as well?

ChrisThrasher commented 2 months ago

I'm not very familiar with those MSVC flags but perhaps CSFML needs to port this change from SFML: https://github.com/SFML/SFML/pull/1834

jarroddavis68 commented 2 months ago

I'm not very familiar with those MSVC flags but perhaps CSFML needs to port this change from SFML: SFML/SFML#1834

/MD (multi-thread DLL) Dynamically links the CRT /MT (Multi-threaded) Statically links the CRT

Yup, CSFML needs that for sure, should fix the issue. Works as expected when I build SFML. I tick the option to use /MT and all of them will be /MT.

ChrisThrasher commented 2 months ago

If I port SFML/SFML#1834 to CSFML would you be able to test it out for me?

jarroddavis68 commented 2 months ago

If I port SFML/SFML#1834 to CSFML would you be able to test it out for me?

absolutely 👍🏿

jarroddavis68 commented 2 months ago

@ChrisThrasher happy to report everything works, except /MD. CSFML still defaults all libs to /MD. Everything else, however, seems to work, even the installation, all moved over successfully.

jarroddavis68 commented 2 months ago

and do have to manually add SFML_ROOT

jarroddavis68 commented 2 months ago

Ok, correction, I just have to populate CMAKE_INSTALL_PREFIX with the install location of SFML and it will just work, so everything works except linking against static CRT (/MT). I still have to set those manually.

ChrisThrasher commented 2 months ago

@jarroddavis68 Try this out https://github.com/SFML/CSFML/tree/msvc_runtime_libs

and do have to manually add SFML_ROOT

This is to be expected. You have to tell CMake where to find SFML. If you don't install SFML to one of the default locations CMake checks then you'll have to set SFML_ROOT.

Ok, correction, I just have to populate CMAKE_INSTALL_PREFIX with the install location of SFML and it will just wor

This might work but it's very unconventional and I wouldn't recommend it. Using SFML_ROOT is the canonical solution.

jarroddavis68 commented 2 months ago

@jarroddavis68 Try this out https://github.com/SFML/CSFML/tree/msvc_runtime_libs

image Once the install location is set, everything "just works", yah!

But, sadly, still seem to default to /MD image

ChrisThrasher commented 2 months ago

Did you do a clean build? That will ensure all CMake cache variables get reset.

EDIT: I fixed a minor issue in my branch related to the STATIC_STD_LIBS option. Make sure you enable that if you want static runtime libs.

jarroddavis68 commented 2 months ago

EDIT: I fixed a minor issue in my branch related to the STATIC_STD_LIBS option. Make sure you enable that if you want static runtime libs.

YES! Works. ❤️ Many thanks!!

image

jarroddavis68 commented 2 months ago

Ahh for the first time I'm now able to automatic grabbing the latest sources, compiling to static libs, convert C headers to Delphi and build my Deps DLL that is used by Delphi for my CSFML based projects.

To @ChrisThrasher and @eXpl0it3r, many thanks for all your help! ✊🏿

https://www.youtube.com/watch?v=grc5nj7AILk

ChrisThrasher commented 1 month ago

https://github.com/SFML/CSFML/pull/352

Heads up, we changed the option name for static static library linking in CSFML 3 from STATIC_STD_LIBS to CSFML_USE_STATIC_STD_LIBS. This is in line with SFML and CSFML style.

jarroddavis68 commented 1 month ago

Ok thanks.👌