| Summary: | [PATCH] Export SDL2 libraries with CMake | ||
|---|---|---|---|
| Product: | SDL | Reporter: | David Demelier <demelier.david> |
| Component: | build | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | enhancement | ||
| Priority: | P2 | CC: | tschwinger |
| Version: | HG 2.0 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Attachments: |
patch
Fixup commit 1 Fixup commit 2 Fixup commit 3 Fixup commit 4 |
||
Ryan, can you check this and include it if it looks good? This looks good and would be super nice for CMake users. I should bump the issue and add some background info: It's the "modern and recommended" way to package your lib with CMake. The best about it is, that it gives you what pkgconfig does on UNIX, just without the hassle and on all platforms, including Windows: Once you import via `find_package` (in CONFIG mode) you can just use the SDL targets via `target_link_libraries` and *everything* (include dir, required defines, propagated dependencies, libraries) is just available and can be used with a single line of code: ``` # this can happen just once for your entire build: find_package(SDL2 CONFIG) # now to let one of your projects use SDL: target_link_libraries(my_project PUBLIC SDL2::SDL SDL2::SDLmain) # yes, that's really all you need ``` https://cmake.org/cmake/help/v3.8/command/target_link_libraries.html https://cmake.org/cmake/help/v3.8/command/find_package.html?highlight=module%20mode https://cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets https://cmake.org/Wiki/CMake/Tutorials/Packaging Testing it. There still seems to be an issue with the installation directory. The `cmake` directory must either go into `share` or `lib` for `find_package` to find the config file when given the installation root... With that resolved, the include path is still off: ``` #include <SDL2/SDL.h> ``` is expected to work, and it's `<prefix>/include/SDL2/SDL.h`, so we just want the compiler to see something like `-I <prefix>/include`. More issues: - No include path is being advertised for SDLmain - We need a minimum CMake version of 2.8.11 for this stuff to work (should be quite reasonable nowadays) Will post fixup patches in a bit, after another test. Created attachment 2737 [details]
Fixup commit 1
Created attachment 2738 [details]
Fixup commit 2
Created attachment 2739 [details]
Fixup commit 3
Created attachment 2740 [details]
Fixup commit 4
(In reply to tschwinger from comment #4) > With that resolved, the include path is still off: > > ``` > #include <SDL2/SDL.h> > ``` > > is expected to work, and it's `<prefix>/include/SDL2/SDL.h`, so we just want > the compiler to see something like `-I <prefix>/include`. This isn't correct, the SDL convention is to include SDL.h with no prefix. This should be fixed by this commit: https://hg.libsdl.org/SDL/rev/c92070a96da5 |
Created attachment 2691 [details] patch If built with CMake, these exports will make easier to use find_package(SDL2) for developers. The next steps is to add CMake support as well to SDL_net,mixer,ttf,rtf,image thanks to that patch.