Remove FindSDL2 find-module, use sdl2-config.cmake instead
This requires SDL >= 2.0.4.
Since <https://bugzilla.libsdl.org/show_bug.cgi?id=2464> was fixed in
SDL 2.0.4, SDL behaves as a CMake "config-file package", even if it was
not itself built using CMake: it installs a sdl2-config.cmake file to
${libdir}/cmake/SDL2, which tells CMake where to find SDL's headers and
library, analogous to a pkg-config .pc file.
As a result, we no longer need to copy/paste a "find-module package"
to be able to find a system copy of SDL >= 2.0.4 with find_package(SDL2).
Find-module packages are now discouraged by the CMake developers, in
favour of having upstream projects behave as config-file packages.
This results in a small API change: FindSDL2 used to set SDL2_INCLUDE_DIR
and SDL2_LIBRARY, but the standard behaviour for config-file packages is
to set <name>_INCLUDE_DIRS and <name>_LIBRARIES. Use the CONFIG keyword
to make sure we search in config-file package mode, and will not find a
FindSDL2.cmake in some other directory that implements the old interface.
In addition to deleting redundant code, this avoids some assumptions in
FindSDL2 about the layout of a SDL installation. The current libsdl2-dev
package in Debian breaks those assumptions; this is considered a bug
and will hopefully be fixed soon, but it illustrates how fragile these
assumptions can be. We can be more robust against different installation
layouts by relying on SDL's own CMake integration.
When linking to a copy of CMake in a non-standard location, users can
now set the SDL2_DIR or CMAKE_PREFIX_PATH environment variable to point
to it; previously, these users would have used the SDL2DIR environment
variable. This continues to be unnecessary if using matching system-wide
installations of CMake and SDL2, for example both from Debian.
@echo off
setlocal
::CONFIG START
::edit these variables if necessary
::change between Debug and Release
set BUILD_TYPE=Release
::path where Hedgewars will be installed to
::default is %ProgramFiles%\hedgewars and requires running this script as administrator
set INSTALL_LOCATION=
::set if vcpkg is not on path
set VCPKG_PATH=%VCPKG_ROOT%
::set if CMake is not on path
set CMAKE_PATH=
::set if FPC is not on path
set PASCAL_PATH=
::set to 1 if x86 to x64 cross-compiler is not enabled automatically
set FORCE_X64_CROSS_COMPILE=
::set to 1 to build the game server
set BUILD_SERVER=
::CONFIG END
:setup
set CURRDIR="%CD%"
cd %CURRDIR%\..\
set PATH=%PASCAL_PATH%;%VCPKG_PATH%;%CMAKE_PATH%;%PATH%
if "%VSCMD_ARG_TGT_ARCH%" == "x64" (
set FORCE_X64_CROSS_COMPILE=1
)
if "%FORCE_X64_CROSS_COMPILE%" NEQ "" (
set CROSS_COMPILE_FLAG=-DWIN32_WIN64_CROSS_COMPILE=1
if "%INSTALL_LOCATION%" == "" (
set INSTALL_LOCATION=%ProgramFiles%/hedgewars
)
) else (
set CROSS_COMPILE_FLAG=
)
if "%INSTALL_LOCATION%" NEQ "" (
set PREFIX_FLAG=-DCMAKE_INSTALL_PREFIX=%INSTALL_LOCATION%
) else (
set PREFIX_FLAG=
)
if "%BUILD_SERVER%" == "" (
set BUILD_SERVER_FLAG=-DNOSERVER=1
) else (
set BUILD_SERVER_FLAG=
)
echo Running cmake...
set ERRORLEVEL=
cmake . -DCMAKE_TOOLCHAIN_FILE="%VCPKG_PATH%\scripts\buildsystems\vcpkg.cmake" -G"NMake Makefiles" %CROSS_COMPILE_FLAG% %BUILD_SERVER_FLAG% "%PREFIX_FLAG%" -DCMAKE_BUILD_TYPE="%BUILD_TYPE%" -DSDL2_BUILDING_LIBRARY=1
if %ERRORLEVEL% NEQ 0 goto exitpoint
echo Configuration completed successfully
echo Building...
set ERRORLEVEL=
nmake
if %ERRORLEVEL% NEQ 0 goto exitpoint
echo Build completed successfully
nmake install
:exitpoint
cd %CURRDIR%
endlocal
pause