| Summary: | CMAKE: Generated target import file contains incorrect include path | ||
|---|---|---|---|
| Product: | SDL | Reporter: | bastien.bouclet |
| Component: | build | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | mohd.akram |
| Version: | HG 2.0 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Attachments: |
Test program
Proposed fix Allow both types of #include |
||
The correct include statement is #include "SDL2/SDL.h" But then, it's not consistent with the include path provided to CMake applications using SDL2 built using autotools, see https://hg.libsdl.org/SDL/file/bfb936894a9d/sdl2-config.cmake.in Also applications have been doing `#include "SDL.h"` for years, it seems a bit harsh breaking their build when distributions decide to switch SDL2 from autotools to CMake (which is what happened with ArchLinux recently, and the reason I am opening this bug). Whoops, you're right, my mistake. I don't use CMake myself, and I don't see where this is configured in the SDL source files. Can you attach a patch you've tested there? Thanks! Created attachment 3219 [details]
Proposed fix
I've attached a patch that fixes the issue.
Added, thanks! https://hg.libsdl.org/SDL/rev/4d843a32d74e Created attachment 4218 [details]
Allow both types of #include
It would be useful to be able to do either `#include "SDL2/SDL.h"` or `#include "SDL.h"`. This patch allows that and adds compatibility with other build systems. It also allows differentiating between SDL1 and SDL2.
Nice addition, thanks! https://hg.libsdl.org/SDL/rev/fab2cd7dee5b |
Created attachment 3216 [details] Test program When building SDL2 using the CMake build system, the generated `SDL2Targets.cmake` file sets the include path to `${_IMPORT_PREFIX}/include` instead of `${_IMPORT_PREFIX}/include/SDL2`. This causes applications using the following in their CMakeLists.txt to detect and include SDL2 to fail building: ``` Find_Package(SDL2 REQUIRED) target_link_libraries(test SDL2::SDL2) ``` Steps to reproduce: 1. Build and install SDL2 using CMake 2. Try to build the attached reproducer (cmake . && make) This fails with the error `test.c:1:10: SDL.h : No such file or directory` Edit the installed `SDL2Targets.cmake`, replace: ``` set_target_properties(SDL2::SDL2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include" ) ``` with: set_target_properties(SDL2::SDL2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/SDL2" ) the reproducer now builds as expected.