Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure a sdl2-config.cmake.in together with sdl2.pc.in #1415

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

Configure a sdl2-config.cmake.in together with sdl2.pc.in #1415

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.3
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2014-03-26 03:47:53 +0000, Leonardo wrote:

Despite having a CMakeLists.txt file, SDL2 seems to be mainly built using the autotools system by package-managers. It is nice to have it but it is only useful if you are building SDL2 by yourself.

People that want to use CMake to find their already-installed SDL2 are using a FindSDL2.cmake module based on the old FindSDL.cmake. This is not deprecated but it is discouraged by the CMake devs (see http://www.cmake.org/Bug/view.php?id=14826), as these modules needs maintainers to be included in the official CMake installation.

To fix that, SDL and its accompanying libraries could configure a simple sdl2-config.cmake file, much like it does with sdl2.pc.in. We don't need to configure a full sdl2-config.cmake as in this post, http://forums.libsdl.org/viewtopic.php?t=10068&sid=ccf8abbf0d73fb03ae9cded991e60959 (because it depends on it being built with CMake). Using something as simple as http://www.cmake.org/Wiki/CMake/Tutorials/Packaging#Package_Configuration_Files is deemed enough. Here is another: http://quickgit.kde.org/?p=prison.git&a=blob&f=lib%2Fprison%2FPrisonConfig.cmake.in

I could have done this myself and submitted a patch but I don't have any skills with autotools. It seems to me that the variables we need to configure are somewhat the same in sdl2.pc.in, so maybe ./configure can do it?

Thanks in advance.

On 2014-03-26 03:53:13 +0000, Leonardo wrote:

We would also need a sdl2-version.cmake, but I think that would be as easy as sdl2-config.cmake to configure.

The links I provided have more information on them.

On 2014-04-06 19:37:33 +0000, Leonardo wrote:

Created attachment 1607
Configure and install sdl2-config.cmake

On 2014-04-06 19:38:04 +0000, Leonardo wrote:

Created attachment 1608
Input file for generating sdl2-config.cmake

On 2014-04-06 19:39:32 +0000, Leonardo wrote:

Here is a basic sdl2-config.cmake.in and a changeset that configures and installs it.

I've tested with cmake --find-package mode and it is properly working.

There is a way of producing a sdl2-config.cmake that is prefix-independent, but since users are already relying on pkgconfig (which is prefix-bound), I am not sure if its a good idea.

On 2014-07-13 22:30:28 +0000, Jean-Pierre Gygax wrote:

I support this request (thanks, Leonardo, for bringing this up). but I do have a related suggestion/question.

I'm still a beginner with CMake, so it's quite possible that I'm misunderstanding something here. However, in one of my own projects, I have used the following combination to make my library available to other CMake projects without having to use the install() commands:


export(TARGETS ${PROJECT_NAME} FILE ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config.cmake)
export(PACKAGE ${PROJECT_NAME})

In a dependent CMake-managed project, I can then use the following to access my library (called "LSApplication"):


find_package(LSApplication CONFIG REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE $<TARGET_PROPERTY:LSApplication,INTERFACE_INCLUDE_DIRECTORIES>)
target_link_libraries(${PROJECT_NAME} LSApplication)

I made this work through much experimentation. But unless I made some mistake, this is the simplest way to mesh together CMake-based projects.

(I'm using CMake 3.0 btw, having started using CMake very recently.)

On 2014-07-15 20:05:15 +0000, Leonardo wrote:

(In reply to Jean-Pierre Gygax from comment # 5)

I support this request (thanks, Leonardo, for bringing this up). but I do
have a related suggestion/question.

I'm still a beginner with CMake, so it's quite possible that I'm
misunderstanding something here. However, in one of my own projects, I have
used the following combination to make my library available to other CMake
projects without having to use the install() commands:


export(TARGETS ${PROJECT_NAME} FILE
${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config.cmake)
export(PACKAGE ${PROJECT_NAME})

In a dependent CMake-managed project, I can then use the following to access
my library (called "LSApplication"):


find_package(LSApplication CONFIG REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE
$<TARGET_PROPERTY:LSApplication,INTERFACE_INCLUDE_DIRECTORIES>)
target_link_libraries(${PROJECT_NAME} LSApplication)

I made this work through much experimentation. But unless I made some
mistake, this is the simplest way to mesh together CMake-based projects.

(I'm using CMake 3.0 btw, having started using CMake very recently.)

Well, that also works, but both of your projects are using CMake already and built using them as build system. SDL2, most of the time (including major distro builds) is built using autotools, which doesn't create the files created by the export() commands you mentioned.

This patch address that by having a file that can be configured and installed by the autotools system, making it easly available to CMake projects.

I appreciate your support :)

On 2014-07-15 20:12:02 +0000, Jean-Pierre Gygax wrote:

Thanks for the response. What I meant was: why not use this method instead of creating config (and possibly version) files?

On 2015-05-07 13:29:45 +0000, Daniel Gibson wrote:

using SDL2 in programs using cmake is a pain currently (because everyone has to ship a hacked FindSDL2.cmake).

this patch should improve the situation, so I hope it gets merged

On 2015-05-08 20:11:58 +0000, Martin Gerhardy wrote:

+1 from my side, too. it would make my life a lot easier.

On 2015-06-29 14:25:20 +0000, Jan Henke wrote:

This is really needed. CMake is the tool of choice for many consumers of SDL2, while at the same time on of few major projects not providing a out-of-the-box way to configure CMake. Please consider inclusion of this patch.

On 2015-06-30 05:24:31 +0000, Sam Lantinga wrote:

This has been applied for 2.0.4, thanks!
https://hg.libsdl.org/SDL/rev/6e87ae760e6d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant