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

Author Topic: cmake 3.0: Config-file Packages  (Read 2664 times)

0 Members and 1 Guest are viewing this topic.

SrTobi

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
cmake 3.0: Config-file Packages
« on: December 21, 2014, 09:44:36 pm »
Hi,

cmake offers a new way to easily export/import targets: Config-file Packages. With them we could export the SFML-Targets into a config file. When using find_package(SFML ...), the exported targets will be imported automatically and can easily be used with target_link_library:

Code: [Select]
find_package(sfml COMPONENTS system window graphics REQUIERD)
add_executable(sfml-prog ${SOURCE})

# "sfml::" is a namespace
target_link_libraries(sfml::system sfml::window sfml::graphics)

Using this will also set the include directories for the target. Also cmake comes with a user- and system-registry, which will keep a list of all cmake-built libraries in one place. Especially on windows, SFML-builds could be found more easily, even on non standard paths. The FindSFML.cmake file is then no longer needed (expect for backward compatibility).

Is there any development going on to integrate the config-file packages? I could do that, but I don't want do unnecessary work, which will be rejected anyway.

A sample could be found here http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: cmake 3.0: Config-file Packages
« Reply #1 on: December 21, 2014, 10:31:56 pm »
Quote
Is there any development going on to integrate the config-file packages?
It has already been discussed in the distant past, but I don't think anybody is working on it.

I'd love to see such an improvement, config files are definitely easier to use.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: cmake 3.0: Config-file Packages
« Reply #2 on: December 23, 2014, 12:23:30 am »
Feel free to add an issue to GitHub so this doesn't get lost.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

SrTobi

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: cmake 3.0: Config-file Packages
« Reply #3 on: December 23, 2014, 01:56:03 am »
Ok, so I forked SFML and made a first attempt to implement config file packages. You can find a first version here. I have tested it with the example code from the docs and the following CMakeLists.txt:

Code: [Select]
cmake_minimum_required(VERSION 2.8)
project(sfml-test)


find_package(SFML COMPONENTS audio system graphics window REQUIRED)

add_executable(sfml-test test.cpp)
target_link_libraries(sfml-test
                      sfml::sfml-system
                      sfml::sfml-graphics
                      sfml::sfml-window
                      sfml::sfml-audio)

That works fine with windows and linux (archlinux), but linux was not able to find the local exported build tree, although it was registered in the user package registry (on windows this works fine). I also made an attempt to achieve backward compatibility (here). When the the sfml-config.cmake is found it also includes the FindSFML.cmake, so that all classic variables are set and the following CMakeLists.txt is still possible:

Code: [Select]
cmake_minimum_required(VERSION 2.8)
project(old-sfml-test)

find_package(SFML COMPONENTS audio system graphics window REQUIRED)

include_directories(${SFML_INCLUDE_DIR})
add_executable(old-sfml-test test.cpp)
target_link_libraries(old-sfml-test ${SFML_LIBRARIES})

However, there are a few problems I ran into:

- Because targets are named sfml-<comp>, all exported targets will be called sfml::sfml-<comp>. I haven't figured out a way to name them sfml::<comp>, like sfml::graphics

- The external dependencies are kinda problem. Currently they are linked privately, so that they won't be listed in the exported targets. However... static linking is then not possible. In the backward-compatibility branch i tried to add the dependencies to the targets manually, after they were found by FindSFML.cmake. In another branch I have tried to import all external dependencies as imported libraries and install them along the sfml libraries, but that does not work (cmake does not allow to install imported taregts). This solution would be very nice, because we could get rid of the OS-dependent install section in the main cmake and all other problems with external libraries.

- I don't knwo how to handle components... I think it makes no sense to treat them specially, because sfml-targets.cmake will only contain components that are present anyway. One could however add a check to test if all given components are present.

- I don't know if backward-compatibility is possible when using the exported local build. Because there is not the classic directory structure, that FindSFML.cmake expects. We would have to change FindSFML.cmake and I do not want to do that ;)

- I have not looked at versioning for now

- I have not  and can not  test it under ios, because I don't have a mac^^ ( ohh maybe I could download a VM...)

Maybe you can list a few criteria, that must be fulfilled, to merge back. Also leave a comment on the code style.

 

anything