| Summary: | Trailing whitespace in SDL2_LIBRARIES causes CMAKE error CMP0004 | ||
|---|---|---|---|
| Product: | SDL | Reporter: | James Hogan <james> |
| Component: | build | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | manuel.montezelo, midovaloryn, philipp.wiesemann |
| Version: | 2.0.4 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Attachments: | bug_822210_fix_sdl2-config.cmake_whitespace.patch | ||
This has also been reported to Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=822210 There are a couple of tentative patches attached there, but not very well tested or very elegant, or robust; feel free to grab them from there and play. I will try to remember to attach them here when they are more tested or if we decide to apply them. Created attachment 2457 [details]
bug_822210_fix_sdl2-config.cmake_whitespace.patch
Patch created in Debian to address this issue
Will this patch make it into the next SDL release (2.0.5)? I'm not familiar with the bug lifecycle in the SDL2 ecosystem. In my case, OSX Yosemite, SDL2 (2.0.4), when installed from brew, wont work with CMake 3.6 without plumbing into the sdl-config.cmake in the brew Cellar and removing the trailing spaces manually. As previously stated in this thread the patches recommended in the debian thread look kind of messy but the string(STRIP) command in your patch attachment seems like a safe and risk-free cross-platform solution to me. With this applied in a commit included 2.0.5 [1], I think that this bug can be closed. Minor nitpick: The patch is from me / Debian, not Ubuntu, and it was already attached to this bug report many months ago ;-) [1] https://hg.libsdl.org/SDL/rev/e723c663ba58 Whoops, sorry for the mis-attribution. I had pulled it from Ubuntu, which I didn't realize had pulled it upstream from you. Cheers! |
When SDL2_LIBRARIES from sdl2-config.cmake is used directly in target_link_libraries, e.g. find_package(SDL2 REQUIRED) add_library(mylib STATIC lib.c) target_link_libraries(mylib ${SDL2_LIBRARIES}) Whitespace at end of SDL2_LIBRARIES causes CMake errors like below: CMake Error at CMakeLists.txt:8 (add_library): Target "mylib" links to item "-L/usr/lib64 -lSDL2 " which has leading or trailing whitespace. This is now an error according to policy CMP0004. My /usr/lib64/cmake/SDL2/sdl2-config.cmake looks like this (this is Gentoo Linux, from media-libs/libsdl2-2.0.4): # sdl2 cmake project-config input for ./configure scripts set(prefix "/usr") set(exec_prefix "${prefix}") set(libdir "/usr/lib64") set(SDL2_PREFIX "/usr") set(SDL2_EXEC_PREFIX "/usr") set(SDL2_LIBDIR "/usr/lib64") set(SDL2_INCLUDE_DIRS "${prefix}/include/SDL2") set(SDL2_LIBRARIES "-L${SDL2_LIBDIR} -lSDL2 ") You can see the trailing whitespace there. I presume this is due to configure having: SDL_LIBS="-lSDL2 $BASE_LDFLAGS" and BASE_LDFLAGS being empty