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

Author Topic: CMake Issue - Unable to link statically  (Read 11478 times)

0 Members and 1 Guest are viewing this topic.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
CMake Issue - Unable to link statically
« on: April 29, 2014, 12:52:18 am »
Alright, so in my attempt to compile CSFML with SFML linked dynamically/shared I noticed an issue. The CSFML configuration on windows for some reason will not accept a shared build of SFML. However manually pointing each *.lib file to the shared version worked fine. I even took a look through the CMakeLists.txt file, but me not really knowing CMake I didn't see anything wrong. For the record I defined SFML_STATIC_LIBRARIES and it had no affect.

To be clear, the CSFML CMakeLists.txt will not accept a shared build of SFML, even with SFML_STATIC_LIBRARIES set to false.
« Last Edit: May 08, 2014, 04:13:08 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: CMake Issue
« Reply #1 on: April 29, 2014, 07:43:25 am »
Since CSFML is meant to use static libraries, I'm not sure it's worth investigating. Why do you want to link SFML dynamically?
Laurent Gomila - SFML developer

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: CMake Issue
« Reply #2 on: April 29, 2014, 01:20:52 pm »
I would investigate it if you gave me some pointers of where to look. The reason I needed to link SFML dynamically is because I am playing with a C wrapper for SFGUI. However I ran into an issue of text not rendering properly, and after some investigation I found out the statically linked SFML inside CSFGUI was clashing with the other statically linked copy of SFML inside CSFML.

So I decided for the heck of it, lets try compiling SFML and CSFML statically together in my CSFGUI dll. Then I manually imported the CSFML functions and tried a test program. Well now it all worked with SFML being linked statically only once. So then I recompiled CSFML with dynamically linked SFML and CSFGUI with a dynamic copy of SFML and it all worked like a charm.

Anyways, enough of what I was doing... I would look into this if you could point me at where I should start.
« Last Edit: April 29, 2014, 01:41:09 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: CMake Issue
« Reply #3 on: April 29, 2014, 01:22:34 pm »
Sure. What's the error?
Laurent Gomila - SFML developer

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: CMake Issue
« Reply #4 on: April 29, 2014, 01:39:51 pm »
Simply that it couldn't find SFML installed because there isn't any -s libs built. However as soon as I build or rename the existing libs to have the -s all works as planned.

Notice now how I renamed the sfml-audio.lib to sfml-audio-s.lib and CMake isn't asking for the audio module. But it still wants the other modules with -s even with SFML_STATIC_LIBRARIES set to false.

[sorry for the long paths, my flash drive kinda died]

Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: CMake Issue
« Reply #5 on: April 29, 2014, 02:10:15 pm »
What if you completely remove these instructions, instead of defining SFML_STATIC_LIBRARIES to false?

if(SFML_OS_WINDOWS)
    set(SFML_STATIC_LIBRARIES TRUE)
    add_definitions(-DSFML_STATIC)
endif()
Laurent Gomila - SFML developer

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: CMake Issue
« Reply #6 on: April 29, 2014, 02:21:10 pm »
Yes that fixed it, I also went and checked the FindSFML.cmake and saw that -DSFML_STATIC should be set by that depending the state of SFML_STATIC_LIBRARIES. I understand the idea behind why it should be set to true by default, but shouldn't CMake override it with what the user has set?

EDIT

Changing it to the following works also and gives the user an option to set it as they wish.

Quote
if(SFML_OS_WINDOWS)
    set(SFML_STATIC_LIBRARIES ON CACHE BOOL "Build CSFML linked to static SFML")
endif()
« Last Edit: April 29, 2014, 02:31:45 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: CMake Issue
« Reply #7 on: May 01, 2014, 08:34:22 pm »
Laurent, do you want me to make a pull request for this? Or is there a better solution?
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: CMake Issue
« Reply #8 on: May 01, 2014, 10:39:29 pm »
Sorry, you lost me. What's broken?
Laurent Gomila - SFML developer

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: CMake Issue
« Reply #9 on: May 08, 2014, 03:47:30 pm »
Sorry, you lost me. What's broken?

Let me summarize....

In the CMakeLists.txt file for CSFML, the following script exists.

Quote
if(SFML_OS_WINDOWS)
    set(SFML_STATIC_LIBRARIES TRUE)
    add_definitions(-DSFML_STATIC)
endif()

This forces SFML_STATIC_LIBRARIES to true, making it impossible to build CSFML with dynamic SFML libraries on windows. Even if the user sets SFML_STATIC_LIBRARIES to false the above script will override the user settings.

So changing the above to the following allows the user to specify dynamic linking, but still defaults to static.

Quote
if(SFML_OS_WINDOWS)
    set(SFML_STATIC_LIBRARIES ON CACHE BOOL "Build CSFML linked to static SFML")
endif()

So do you want me to make a pull request to fix it?
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: CMake Issue
« Reply #10 on: May 08, 2014, 03:52:50 pm »
Don't forget to add the SFML_STATIC definition though, or does the find script add that?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: AW: CMake Issue
« Reply #11 on: May 08, 2014, 03:55:05 pm »
Don't forget to add the SFML_STATIC definition though, or does the find script add that?

The FindSFML.cmake script adds that.
« Last Edit: May 08, 2014, 03:58:13 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: CMake Issue
« Reply #12 on: May 08, 2014, 04:00:54 pm »
CSFML is meant to link SFML statically. This was not supposed to be an option. But since you provided a valid use case, and I guess it can't hurt to expose this option, let's do it ;)

However:
- there's a macro that you can use to define a CSFML CMake option (see the root CMakeLists.txt)
- you should create a new variable (like CSFML_LINK_SFML_STATICALLY), for consistency with other options, and link it to SFML_STATIC_LIBRARIES internally
Laurent Gomila - SFML developer

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: CMake Issue - Unable to link statically
« Reply #13 on: June 06, 2014, 10:36:46 pm »
I have made a PR to add the option, let me know if there is anything I should change.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor