We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4128

Summary: CMAKE: Generated target import file contains incorrect include path
Product: SDL Reporter: bastien.bouclet
Component: buildAssignee: 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

Description bastien.bouclet 2018-04-08 10:10:53 UTC
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.
Comment 1 Sam Lantinga 2018-04-10 15:05:44 UTC
The correct include statement is #include "SDL2/SDL.h"
Comment 2 bastien.bouclet 2018-04-10 16:37:31 UTC
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).
Comment 3 Sam Lantinga 2018-04-10 21:52:39 UTC
Whoops, you're right, my mistake.
Comment 4 Sam Lantinga 2018-04-10 21:54:50 UTC
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!
Comment 5 bastien.bouclet 2018-04-11 04:22:24 UTC
Created attachment 3219 [details]
Proposed fix

I've attached a patch that fixes the issue.
Comment 6 Sam Lantinga 2018-04-12 00:18:58 UTC
Added, thanks!
https://hg.libsdl.org/SDL/rev/4d843a32d74e
Comment 7 Mohamed 2020-02-16 02:57:14 UTC
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.
Comment 8 Sam Lantinga 2020-02-16 08:08:54 UTC
Nice addition, thanks!
https://hg.libsdl.org/SDL/rev/fab2cd7dee5b