SFML community forums

Help => General => Topic started by: Ceylo on February 10, 2018, 03:06:55 pm

Title: FindSFML.cmake users, help test the new SFMLConfig.cmake
Post by: Ceylo on February 10, 2018, 03:06:55 pm
Hello :)

This topic is for users that already use the FindSFML.cmake script provided by SFML, or users that don't yet but would like to and whose project is also based on CMake.

What we would need from you

Since around 1 week ago the PR for supporting find_package(SFML) with a config file (https://github.com/SFML/SFML/pull/1335) is ready for testing but we're still missing feedbacks at the moment. So if you can help on testing this means the pull request can be merged earlier. In particular, we'd appreciate if you tried it with your current workflow to know if any use case is missing. If everything goes well FindSFML.cmake will be removed from future releases.

What does SFMLConfig improve for me?

In terms of use, the SFMLConfig means:
- you don't need to embed FindSFML.cmake in your project anymore, everything is stored in the SFML installation directory
- you're not dealing with variables like SFML_LIBRARIES or SFML_DEPENDENCIES anymore, you just link your library or executable with sfml-${component} where ${component} is one of system, network, audio, window, graphics
- you don't need to use SFML_INCLUDE_DIR anymore to include SFML headers, it is done automatically
- when linking static SFML libraries, you don't need to use SFML_DEPENDENCIES anymore, it is done automatically
- again with static SFML libraries, you don't need to explicitly build with SFML_STATIC, it's done automatically
- you don't need to care about dependencies between SFML modules, for example if you link against sfml-graphics, sfml-system and sfml-window get automatically linked too
- like with FindSFML.cmake, you still don't need to care about whether you're building in Debug or Release mode, the appropriate SFML library is used automatically

How do I test this?

You need to clone the branch (https://github.com/Ceylo/SFML/tree/feature/CMakeTargetExport), build SFML (https://www.sfml-dev.org/tutorials/2.4/compile-with-cmake.php) and install it (build install target).

You should rebuild and install for all the configurations that you want to use (debug/release, dynamic/static/frameworks) to the same target installation directory. Then remove FindSFML.cmake from your project to make sure it's not used, and clear your CMake cache.

After that in terms of use it's just something like
find_package(SFML 2.4 COMPONENTS system window graphics REQUIRED)
target_link_libraries(my_exe PRIVATE sfml-graphics)
in your own CMake code.

Detailed doc for SFMLConfig

(click to show/hide)

Thanks!
Ceylo
Title: Re: FindSFML.cmake users, help test the new SFMLConfig.cmake
Post by: Laurent on February 10, 2018, 06:21:35 pm
Your examples imply that find_package must contain the full list of SFML components, not just the final ones (ie. sfml-graphics sfml-window sfml-system instead of just sfml-graphics); whereas in target_link_libraries you can just give the final modules and all the dependant ones will automatically be linked. Is that the case?
Title: Re: FindSFML.cmake users, help test the new SFMLConfig.cmake
Post by: Ceylo on February 10, 2018, 06:27:34 pm
Your examples imply that find_package must contain the full list of SFML components, not just the final ones (ie. sfml-graphics sfml-window sfml-system instead of just sfml-graphics); whereas in target_link_libraries you can just give the final modules and all the dependant ones will automatically be linked. Is that the case?
Indeed. Do you find this disturbing?
Title: Re: FindSFML.cmake users, help test the new SFMLConfig.cmake
Post by: eXpl0it3r on February 10, 2018, 07:13:26 pm
What if the graphics module isn't installed? What's the point of having to specify it when you always have to mention them all anyways?
Title: Re: FindSFML.cmake users, help test the new SFMLConfig.cmake
Post by: Laurent on February 10, 2018, 07:18:23 pm
Quote
Indeed. Do you find this disturbing?
I can live with it if there's no way around it. But if we can make it consistent (ie. find_package(X Y) and target_link_libraries(X Y)) then I guess we should do it.

Quote
What if the graphics module isn't installed? What's the point of having to specify it when you always have to mention them all anyways?
It's not "all", it's what you want + their dependencies.
Title: Re: FindSFML.cmake users, help test the new SFMLConfig.cmake
Post by: Ceylo on February 10, 2018, 11:08:57 pm
What if the graphics module isn't installed?
Then it'll be reported as not found (if specified in components of the find_package() call)

What's the point of having to specify it when you always have to mention them all anyways?
I didn't understand what you mean here.

I can live with it if there's no way around it. But if we can make it consistent (ie. find_package(X Y) and target_link_libraries(X Y)) then I guess we should do it.
It's most likely possible to deduce that if the user asked for "graphics" component then we should also consider "window" and "system" to be among the requested components. Will fix that.
Title: Re: FindSFML.cmake users, help test the new SFMLConfig.cmake
Post by: Ceylo on February 11, 2018, 02:12:18 pm
It's most likely possible to deduce that if the user asked for "graphics" component then we should also consider "window" and "system" to be among the requested components. Will fix that.
Done. So now we can do
Code: [Select]
find_package(SFML COMPONENTS graphics REQUIRED)
target_link_libraries(my_exe PRIVATE sfml-graphics)
and have everything linked as needed.

This still means that the user will have to copy more DLLs next to his executable than what he actually specified in target_link_libraries() call. But I guess this is ok.
Title: Re: FindSFML.cmake users, help test the new SFMLConfig.cmake
Post by: Ceylo on February 16, 2018, 08:05:09 pm
Hello,
We still need people to test! Please help if you can.

Thanks,
Ceylo
Title: Re: FindSFML.cmake users, help test the new SFMLConfig.cmake
Post by: Hiura on March 04, 2018, 05:35:45 pm
I've tested the changes on mac, but others are welcome to try it on their end as well. ;-)
Title: Re: FindSFML.cmake users, help test the new SFMLConfig.cmake
Post by: Ceylo on March 13, 2018, 08:59:22 pm
Up!
Testing is done on Linux and macOS but we're still missing someone for Windows. If anyone could help unlock this PR… :)