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 4970 - Configure generated sdl2-config.cmake should contain version
Summary: Configure generated sdl2-config.cmake should contain version
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: build (show other bugs)
Version: 2.0.10
Hardware: All All
: P2 major
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.12
Depends on:
Blocks:
 
Reported: 2020-02-07 15:43 UTC by alexander.grund
Modified: 2020-03-17 07:24 UTC (History)
2 users (show)

See Also:


Attachments
Patch with autogen (9.34 KB, patch)
2020-02-20 14:06 UTC, alexander.grund
Details | Diff
Patch without autogen changes (4.44 KB, patch)
2020-02-20 14:07 UTC, alexander.grund
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description alexander.grund 2020-02-07 15:43:39 UTC
The sdl2-config.cmake generated by configure does not contain the version.

The variables `PACKAGE_VERSION` (and optionally) `SDL2_VERSION` should be set there too. Otherwise e.g. `find_package(SDL2 2.0.10)` will fail as it finds the config but not the version

That is another issue which can be solved by generating it uniformly or use CMake for everything, see https://bugzilla.libsdl.org/show_bug.cgi?id=4116
Comment 1 Ryan C. Gordon 2020-02-14 18:38:21 UTC
This should be fixed by https://hg.libsdl.org/SDL/rev/d62544e5fa7a but let me know if I messed this up, please!

--ryan.
Comment 2 alexander.grund 2020-02-20 14:06:45 UTC
Created attachment 4223 [details]
Patch with autogen

Thanks ryan, that was what I meant but I was wrong in how it should look like. Apparently you need a separate version file, see the full description at https://cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html

I took a shot at this myself and additionally created the targets that would be created by the CMake scripts. The resulting files on my system look like this:

sdl2-config.cmake:
# sdl2 cmake project-config input for ./configure scripts

set(prefix "/tmp/sdl2") 
set(exec_prefix "${prefix}")
set(libdir "${exec_prefix}/lib")
set(SDL2_PREFIX "/tmp/sdl2")
set(SDL2_EXEC_PREFIX "/tmp/sdl2")
set(SDL2_LIBDIR "${exec_prefix}/lib")
set(SDL2_INCLUDE_DIRS "${prefix}/include/SDL2")
set(SDL2_LIBRARIES "-L${SDL2_LIBDIR} -Wl,-rpath,${libdir} -Wl,--enable-new-dtags -lSDL2")
string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)

if(NOT TARGET SDL2::SDL2)
  # Remove -lSDL2 as that is handled by CMake, note the space at the end so it does not replace e.g. -lSDL2main
  # This may require "libdir" beeing set (from above)
  string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS "-Wl,-rpath,${libdir} -Wl,--enable-new-dtags -lSDL2 ")
  string(STRIP "${SDL2_EXTRA_LINK_FLAGS}" SDL2_EXTRA_LINK_FLAGS)
  string(REPLACE "-lSDL2 " "" SDL2_EXTRA_LINK_FLAGS_STATIC "-Wl,-rpath,${libdir} -Wl,--enable-new-dtags -lSDL2  -Wl,--no-undefined -lm -ldl -lpthread -lrt ")
  string(STRIP "${SDL2_EXTRA_LINK_FLAGS_STATIC}" SDL2_EXTRA_LINK_FLAGS_STATIC)

  add_library(SDL2::SDL2 SHARED IMPORTED)
  set_target_properties(SDL2::SDL2 PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES "${prefix}/include/SDL2"
    IMPORTED_LINK_INTERFACE_LANGUAGES "C" 
    IMPORTED_LOCATION "${exec_prefix}/lib/libSDL2.so"
    INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS}")

  add_library(SDL2::SDL2-static STATIC IMPORTED)
  set_target_properties(SDL2::SDL2-static PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES "${prefix}/include/SDL2"
    IMPORTED_LINK_INTERFACE_LANGUAGES "C" 
    IMPORTED_LOCATION "${exec_prefix}/lib/libSDL2.a"
    INTERFACE_LINK_LIBRARIES "${SDL2_EXTRA_LINK_FLAGS_STATIC}")

  add_library(SDL2::SDL2main STATIC IMPORTED)
  set_target_properties(SDL2::SDL2main PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES "C" 
    IMPORTED_LOCATION "${exec_prefix}/lib/libSDL2main.a")
endif()

sdl2-config-version.cmake:
set(PACKAGE_VERSION "2.0.10")

if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
  set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
  set(PACKAGE_VERSION_COMPATIBLE TRUE)
  if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
    set(PACKAGE_VERSION_EXACT TRUE)
  endif()
endif()
Comment 3 alexander.grund 2020-02-20 14:07:21 UTC
Created attachment 4224 [details]
Patch without autogen changes
Comment 4 alexander.grund 2020-02-20 14:08:56 UTC
Note that the patch(es) were created on top of 2.0.10. Your changes from https://hg.libsdl.org/SDL/rev/d62544e5fa7a may need to be reverted first (not required after this patch as CMake will set SDL2_VERSION and SDL2_VERSION_* variables)
Comment 5 Ryan C. Gordon 2020-02-21 20:53:24 UTC
This patch is now https://hg.libsdl.org/SDL/rev/ef2d5382a887, thanks!

--ryan.
Comment 6 alexander.grund 2020-02-24 08:30:10 UTC
Seems the addition of sdl2-config-version.cmake.in is missing.

I suggest to test-build with autotools and compare the 2 generated files in the installation folder with my example in https://bugzilla.libsdl.org/show_bug.cgi?id=4970#c2
Comment 7 Sam Lantinga 2020-03-01 20:38:33 UTC
I just wanted to confirm that what's in the latest snapshot is correct?
http://www.libsdl.org/tmp/SDL-2.0.zip

Thanks!
Comment 8 alexander.grund 2020-03-02 09:25:10 UTC
Yes I successfully verified SDL-2.0.11-13563 is working with a CMake project. Thanks!
Comment 9 Sam Lantinga 2020-03-02 22:53:12 UTC
Great, thanks!
Comment 10 Joshua Root 2020-03-15 03:08:36 UTC
(In reply to Ryan C. Gordon from comment #5)
> This patch is now https://hg.libsdl.org/SDL/rev/ef2d5382a887, thanks!

This results in an incorrect library suffix being used on macOS (originally reported in https://github.com/macports/macports-ports/pull/6581).

Would you like me to open a new bug for this issue?
Comment 11 alexander.grund 2020-03-16 09:32:01 UTC
Sorry for the wrong suffix. Best would be to use CMAKE_SHARED_LIBRARY_SUFFIX and CMAKE_STATIC_LIBRARY_SUFFIX. But it needs double-checking with the code generating the library names. As I don't know autotools well enough, I'll leave this to someone else. But my bet would be that using CMAKE_*_LIBRARY_SUFFIX solves the problem already.
Comment 12 Sam Lantinga 2020-03-16 19:15:56 UTC
Ryan, this is a regression, can you look at this ASAP?
Comment 13 Sam Lantinga 2020-03-16 19:16:33 UTC
Actually, Joshua, can you open a new bug for the regression?

Thanks!
Comment 14 Joshua Root 2020-03-17 02:23:32 UTC
(In reply to Sam Lantinga from comment #13)
> Actually, Joshua, can you open a new bug for the regression?
Done: bug 5039.
Comment 15 alexander.grund 2020-03-17 07:24:46 UTC
FWIW: This is NOT a regression as only the new feature (the target) is affected. The old Variables which existed before are untouched

But yes should be changed ASAP