Control: reassign -1 libsdl2-dev 2.0.10+dfsg1-2 Control: retitle -1 libsdl2-dev: Packages that embed FindSDL2.cmake fail to find SDL2 Control: affects -1 + hedgewars openjk Control: tags -1 + patch
On Tue, 11 Feb 2020 at 01:45:15 +0100, Andreas Beckmann wrote: > openjk FTBFS against libsdl2 2.0.10+dfsg1-2 which has moved the headers > to an arch-dependent location: > > [ 53%] Building CXX object > code/CMakeFiles/openjo_sp.x86_64.dir/client/cl_cgame.cpp.o > cd "/build/openjk-0~20191030.4881be7~dfsg/obj/code" && /usr/bin/c++ > -DARCH_STRING=\"x86_64\" -DFINAL_BUILD -DJK2_MODE -DSOURCE_DATE="\"Nov 2 > 2019\"" -D_JK2EXE -I"/build/openjk-0~20191030.4881be7~dfsg/shared" -I" > /build/openjk-0~20191030.4881be7~dfsg/code" > -I"/build/openjk-0~20191030.4881be7~dfsg/lib/gsl-lite/include" > -I"/build/openjk-0~20191030.4881be7~dfsg/lib/minizip/include" -g -O2 > -fdebug-prefix-map=/build/openjk-0~2 > 0191030.4881be7~dfsg=. -fstack-protector-strong -Wformat > -Werror=format-security -Wall -Wno-unused-parameter > -Wno-missing-field-initializers -fno-strict-aliasing -Wno-strict-aliasing > -Wno-unused-but-set-variable > -Wdate-time -D_FORTIFY_SOURCE=2 -DNDEBUG -msse2 -std=c++11 -Wall > -Wno-invalid-offsetof -Wno-write-strings -Wno-comment -fsigned-char > -mstackrealign -mfpmath=sse -fvisibility=hidden -o > CMakeFiles/openjo_sp.x86_6 > 4.dir/client/cl_cgame.cpp.o -c > "/build/openjk-0~20191030.4881be7~dfsg/code/client/cl_cgame.cpp" > In file included from > /build/openjk-0~20191030.4881be7~dfsg/code/client/cl_cgame.cpp:34: > /build/openjk-0~20191030.4881be7~dfsg/shared/sys/sys_loadlib.h:39:11: fatal > error: SDL.h: No such file or directory > 39 | # include <SDL.h> > | ^~~~~~~ Reproducer attached. I think this is a regression in SDL2 with #909740. hedgewars seems to FTBFS on the reproducible-builds infrastructure for the same reason (no bug filed yet). Since SDL 2.0.6, the recommended way to link to a system copy of SDL2 from a CMake project is to behave like debian/tests/cmake-example in the current package - use find_package(SDL2) without a FindSDL2 macro. However, not all upstream projects that build using CMake have caught up with this yet. The reproducer for this bug adds a debian/tests/cmake-findsdl2 that represents this. The specific implementation of FindSDL2 in the reproducer was taken from openjk, but it's regularly copied around, and can be found in hedgewars, spring and many other packages: https://codesearch.debian.net/search?q=Other+versions+link+to+-lSDL2main&literal=1 I personally think the FindFoo modules are reminiscent of the worst parts of Autotools (from which the Unix world was able to escape by inventing pkg-config), but there's a significant amount of code that relies on them, much of which is not well-maintained, so it seems desirable to keep compatibility. Inclusion of a vaguely similar file in CMake was rejected in <https://github.com/Kitware/CMake/pull/149>. The solution I originally proposed for #909740 back in 2018 (MR !3) does not appear to suffer from this issue, but the alternatives I implemented in 2019 in response to reluctance to apply !3 (MRs !4 and !5) do suffer from it, and !5 is the implementation that was chosen for application in the end. I think the best solution for this is to revert !5 and go back to !3. Please consider <https://salsa.debian.org/sdl-team/libsdl2/merge_requests/3>. Or if you have other ideas for fixing this, I'm open to suggestions. I would recommend making sure that the new autopkgtest coverage passes. smcv
>From c9e77c8bbe148ded74aeacd3c9989deb115a53dd Mon Sep 17 00:00:00 2001 From: Simon McVittie <s...@debian.org> Date: Tue, 11 Feb 2020 08:55:20 +0000 Subject: [PATCH] d/tests: Assert that packages that embed FindSDL2.cmake can find us Since SDL 2.0.6, the recommended way to link to a system copy of SDL2 from a CMake project is to behave like debian/tests/cmake-example - use find_package(SDL2) without a FindSDL2 macro. However, not all upstream projects that build using CMake have caught up with this yet. This specific implementation was taken from openjk, but it's regularly copied around, and can be found in hedgewars, spring and many other packages: https://codesearch.debian.net/search?q=Other+versions+link+to+-lSDL2main&literal=1 Inclusion of a vaguely similar file in CMake was rejected in <https://github.com/Kitware/CMake/pull/149>. Reproduces: https://bugs.debian.org/951087 Signed-off-by: Simon McVittie <s...@debian.org> --- debian/copyright | 38 +++++ debian/tests/cmake | 21 ++- debian/tests/cmake-findsdl2/CMakeLists.txt | 14 ++ debian/tests/cmake-findsdl2/FindSDL2.cmake | 182 +++++++++++++++++++++ debian/tests/cmake-findsdl2/README.txt | 16 ++ debian/tests/cmake-findsdl2/hello.c | 20 +++ 6 files changed, 286 insertions(+), 5 deletions(-) create mode 100644 debian/tests/cmake-findsdl2/CMakeLists.txt create mode 100644 debian/tests/cmake-findsdl2/FindSDL2.cmake create mode 100644 debian/tests/cmake-findsdl2/README.txt create mode 100644 debian/tests/cmake-findsdl2/hello.c diff --git a/debian/copyright b/debian/copyright index 131eafa..9005364 100644 --- a/debian/copyright +++ b/debian/copyright @@ -114,6 +114,13 @@ Copyright: 2015, Gianfranco Costamagna <locutusofb...@debian.org> 2018, Simon McVittie License: LGPL-2.1+ +Files: debian/tests/cmake-findsdl2/FindSDL2.cmake +Copyright: 2003-2009 Kitware, Inc. +License: BSD-3-clause-kitware +Comment: + Taken from the openjk package. Similar files exist in hedgewars, spring, + megaglest, etc. + License: SGI-Free-Software-License-B SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. @@ -241,6 +248,37 @@ License: BSD-3-clause-chromium (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +License: BSD-3-clause-kitware + Copyright 2003-2009 Kitware, Inc. + . + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + . + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + . + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + . + * Neither the names of Kitware, Inc., the Insight Software Consortium, + nor the names of their contributors may be used to endorse or promote + products derived from this software without specific prior written + permission. + . + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + License: BSD-3-clause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/debian/tests/cmake b/debian/tests/cmake index b74ecf0..5764b47 100755 --- a/debian/tests/cmake +++ b/debian/tests/cmake @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright 2019 Collabora Ltd. +# Copyright 2019-2020 Collabora Ltd. # SPDX-License-Identifier: Zlib # (see "zlib/libpng" in debian/copyright) @@ -22,10 +22,21 @@ else fi srcdir="$(pwd)" + +mkdir "$WORKDIR/example" ( - cd "$WORKDIR" + cd "$WORKDIR/example" cmake $CCFILE "$srcdir/debian/tests/cmake-example" ) -make -C "$WORKDIR" VERBOSE=1 -"$WORKDIR/hello" -make -C "$WORKDIR" VERBOSE=1 clean +make -C "$WORKDIR/example" VERBOSE=1 +"$WORKDIR/example/hello" +make -C "$WORKDIR/example" VERBOSE=1 clean + +mkdir "$WORKDIR/findsdl2" +( + cd "$WORKDIR/findsdl2" + cmake $CCFILE "$srcdir/debian/tests/cmake-findsdl2" +) +make -C "$WORKDIR/findsdl2" VERBOSE=1 +"$WORKDIR/findsdl2/hello" +make -C "$WORKDIR/findsdl2" VERBOSE=1 clean diff --git a/debian/tests/cmake-findsdl2/CMakeLists.txt b/debian/tests/cmake-findsdl2/CMakeLists.txt new file mode 100644 index 0000000..d92a5f7 --- /dev/null +++ b/debian/tests/cmake-findsdl2/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright 2019 Collabora Ltd. +# SPDX-License-Identifier: Zlib +# (see "zlib/libpng" in debian/copyright) + +cmake_minimum_required(VERSION 3.13) +project(Hello) + +list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}") + +find_package(SDL2 REQUIRED) +include_directories(${SDL2_INCLUDE_DIR}) + +add_executable(hello hello.c) +target_link_libraries(hello SDL2) diff --git a/debian/tests/cmake-findsdl2/FindSDL2.cmake b/debian/tests/cmake-findsdl2/FindSDL2.cmake new file mode 100644 index 0000000..5be23d6 --- /dev/null +++ b/debian/tests/cmake-findsdl2/FindSDL2.cmake @@ -0,0 +1,182 @@ +# Locate SDL2 library +# This module defines +# SDL2_LIBRARY, the name of the library to link against +# SDL2_FOUND, if false, do not try to link to SDL2 +# SDL2_INCLUDE_DIR, where to find SDL.h +# +# This module responds to the the flag: +# SDL2_BUILDING_LIBRARY +# If this is defined, then no SDL2main will be linked in because +# only applications need main(). +# Otherwise, it is assumed you are building an application and this +# module will attempt to locate and set the the proper link flags +# as part of the returned SDL2_LIBRARY variable. +# +# Don't forget to include SDLmain.h and SDLmain.m your project for the +# OS X framework based version. (Other versions link to -lSDL2main which +# this module will try to find on your behalf.) Also for OS X, this +# module will automatically add the -framework Cocoa on your behalf. +# +# +# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration +# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library +# (SDL2.dll, libsdl2.so, SDL2.framework, etc). +# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again. +# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value +# as appropriate. These values are used to generate the final SDL2_LIBRARY +# variable, but when these values are unset, SDL2_LIBRARY does not get created. +# +# +# $SDL2DIR is an environment variable that would +# correspond to the ./configure --prefix=$SDL2DIR +# used in building SDL2. +# l.e.galup 9-20-02 +# +# Modified by Eric Wing. +# Added code to assist with automated building by using environmental variables +# and providing a more controlled/consistent search behavior. +# Added new modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). +# Also corrected the header search path to follow "proper" SDL guidelines. +# Added a search for SDL2main which is needed by some platforms. +# Added a search for threads which is needed by some platforms. +# Added needed compile switches for MinGW. +# +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of +# SDL2_LIBRARY to override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. +# +# Note that the header path has changed from SDL2/SDL.h to just SDL.h +# This needed to change because "proper" SDL convention +# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability +# reasons because not all systems place things in SDL2/ (see FreeBSD). + +#============================================================================= +# Copyright 2003-2009 Kitware, Inc. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the names of Kitware, Inc., the Insight Software Consortium, +# nor the names of their contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +SET(SDL2_SEARCH_PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +FIND_PATH(SDL2_INCLUDE_DIR SDL.h + NAMES SDL2 + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES include/SDL2 include + PATHS ${SDL2_SEARCH_PATHS} +) + +FIND_LIBRARY(SDL2_LIBRARY_TEMP + NAMES SDL2 + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES lib64 lib + PATHS ${SDL2_SEARCH_PATHS} +) + +IF(NOT SDL2_BUILDING_LIBRARY) + IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") + # Non-OS X framework versions expect you to also dynamically link to + # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms + # seem to provide SDL2main for compatibility even though they don't + # necessarily need it. + FIND_LIBRARY(SDL2MAIN_LIBRARY + NAMES SDL2main + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES lib64 lib + PATHS ${SDL2_SEARCH_PATHS} + ) + ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") +ENDIF(NOT SDL2_BUILDING_LIBRARY) + +# SDL2 may require threads on your system. +# The Apple build may not need an explicit flag because one of the +# frameworks may already provide it. +# But for non-OSX systems, I will use the CMake Threads package. +IF(NOT APPLE) + FIND_PACKAGE(Threads) +ENDIF(NOT APPLE) + +# MinGW needs an additional library, mwindows +# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows +# (Actually on second look, I think it only needs one of the m* libraries.) +IF(MINGW) + SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW") +ENDIF(MINGW) + +IF(SDL2_LIBRARY_TEMP) + # For SDL2main + IF(NOT SDL2_BUILDING_LIBRARY) + IF(SDL2MAIN_LIBRARY) + SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP}) + ENDIF(SDL2MAIN_LIBRARY) + ENDIF(NOT SDL2_BUILDING_LIBRARY) + + # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. + # CMake doesn't display the -framework Cocoa string in the UI even + # though it actually is there if I modify a pre-used variable. + # I think it has something to do with the CACHE STRING. + # So I use a temporary variable until the end so I can set the + # "real" variable in one-shot. + IF(APPLE) + SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa") + ENDIF(APPLE) + + # For threads, as mentioned Apple doesn't need this. + # In fact, there seems to be a problem if I used the Threads package + # and try using this line, so I'm just skipping it entirely for OS X. + IF(NOT APPLE) + SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) + ENDIF(NOT APPLE) + + # For MinGW library + IF(MINGW) + SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP}) + ENDIF(MINGW) + + # Set the final string here so the GUI reflects the final state. + SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found") + # Set the temp variable to INTERNAL so it is not seen in the CMake GUI + SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "") +ENDIF(SDL2_LIBRARY_TEMP) + +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR) diff --git a/debian/tests/cmake-findsdl2/README.txt b/debian/tests/cmake-findsdl2/README.txt new file mode 100644 index 0000000..f23abba --- /dev/null +++ b/debian/tests/cmake-findsdl2/README.txt @@ -0,0 +1,16 @@ +THIS IS NOT THE RECOMMENDED WAY TO USE SDL2 FROM CMAKE + +Since SDL 2.0.6, the recommended way to link to a system copy of SDL2 +from a CMake project is to behave like debian/tests/cmake-example - use +find_package(SDL2) without a FindSDL2 macro. However, not all upstream +projects that build using CMake have caught up with this yet. + +This specific implementation was taken from openjk, +but it's regularly copied around, and can be found +in hedgewars, spring and many other packages: +https://codesearch.debian.net/search?q=Other+versions+link+to+-lSDL2main&literal=1 + +Inclusion of a vaguely similar file in CMake was rejected in +<https://github.com/Kitware/CMake/pull/149>. + +Bug-Debian: https://bugs.debian.org/951087 diff --git a/debian/tests/cmake-findsdl2/hello.c b/debian/tests/cmake-findsdl2/hello.c new file mode 100644 index 0000000..fcf9bdb --- /dev/null +++ b/debian/tests/cmake-findsdl2/hello.c @@ -0,0 +1,20 @@ +/* + * Copyright 2019 Collabora Ltd. + * SPDX-License-Identifier: Zlib + * (see "zlib/libpng" in debian/copyright) + */ + +#include <SDL.h> + +int +main (int argc, char **argv) +{ + if (SDL_Init(0) != 0) { + SDL_Log("SDL_Init: %s", SDL_GetError()); + return 1; + } + + SDL_Log("Hello, world!"); + SDL_Quit(); + return 0; +} -- 2.25.0