Use find_package for SDL libraries

CMake already distributes FindSDL*.cmake files for SDL and SDL_mixer,
which support custom prefixes via environment variables, removing the
need for ad-hoc logic in Win9x builds.

Also, according to FindSDL.cmake, #include <SDL.h> is the preferred way
for portability reasons, instead of #include <SDL/SDL.h>, which is the
option that has been used so far.
This commit is contained in:
Xavier Del Campo Romero 2022-07-23 04:18:22 +02:00
parent 37ee2c11f3
commit 5829ef82c4
20 changed files with 37 additions and 51 deletions

View File

@ -14,11 +14,26 @@ if(CMAKE_TOOLCHAIN_FILE MATCHES "ps1")
set(PS1_BUILD 1)
elseif(CMAKE_TOOLCHAIN_FILE MATCHES "win9x")
set(WIN9X_BUILD 1)
set(SDL1_2_BUILD 1)
else()
set(HOST_BUILD 1)
set(SDL1_2_BUILD 1)
endif()
add_executable(${PROJECT_NAME} "src/main.c")
if(SDL1_2_BUILD)
find_package(SDL 1.2 REQUIRED)
find_package(SDL_gfx 2.0 REQUIRED)
find_package(SDL_mixer 1.2 REQUIRED)
# FindSDL_mixer.cmake does not export any target, so do it here instead.
add_library(SDL::SDL_mixer STATIC IMPORTED)
set_property(TARGET SDL::SDL_mixer PROPERTY
IMPORTED_LOCATION ${SDL_MIXER_LIBRARIES})
target_include_directories(SDL::SDL_mixer INTERFACE ${SDL_MIXER_INCLUDE_DIRS})
target_link_libraries(SDL::SDL_mixer INTERFACE SDL::SDL)
endif()
set(cdroot ${CMAKE_BINARY_DIR}/cdimg)
file(MAKE_DIRECTORY ${cdroot})
# Avoid C11 since it is not supported by the i386-mingw32 toolchain.

View File

@ -1,8 +1,3 @@
find_package(SDL 1.2 REQUIRED)
find_package(SDL_mixer 1.2 REQUIRED)
find_package(SDL_gfx 2.0 REQUIRED)
set(SDL1_2_BUILD 1)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(cflags ${cflags} -Og)
else()

View File

@ -1,11 +1,3 @@
if("$ENV{SDL_PATH}" STREQUAL "")
message(FATAL_ERROR "please define env variable SDL_PATH")
elseif("$ENV{SDL_MIXER_PATH}" STREQUAL "")
message(FATAL_ERROR "please define env variable SDL_MIXER_PATH")
elseif("$ENV{SDL_GFX_PATH}" STREQUAL "")
message(FATAL_ERROR "please define env variable SDL_GFX_PATH")
endif()
add_custom_command(OUTPUT ${cdroot}/${PROJECT_NAME}
COMMAND i386-mingw32-strip ${PROJECT_NAME} -o ${cdroot}/${PROJECT_NAME}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
@ -13,26 +5,9 @@ add_custom_command(OUTPUT ${cdroot}/${PROJECT_NAME}
VERBATIM)
add_custom_target(stripped-exe ALL DEPENDS ${cdroot}/${PROJECT_NAME})
add_library(SDL STATIC IMPORTED)
set_property(TARGET SDL PROPERTY IMPORTED_LOCATION $ENV{SDL_PATH}/lib/libSDL.a)
target_include_directories(SDL INTERFACE
$ENV{SDL_PATH}/include $ENV{SDL_PATH}/include/SDL)
target_link_libraries(SDL INTERFACE gdi32 user32 winmm dxguid)
add_library(SDL_mixer STATIC IMPORTED)
set_property(TARGET SDL_mixer PROPERTY IMPORTED_LOCATION
$ENV{SDL_MIXER_PATH}/lib/libSDL_mixer.a)
target_include_directories(SDL_mixer INTERFACE $ENV{SDL_MIXER_PATH}/include)
target_link_libraries(SDL_mixer INTERFACE SDL)
add_library(SDL_gfx STATIC IMPORTED)
set_property(TARGET SDL_gfx PROPERTY IMPORTED_LOCATION
$ENV{SDL_GFX_PATH}/lib/libSDL_gfx.a)
target_include_directories(SDL_gfx INTERFACE $ENV{SDL_GFX_PATH}/include)
target_link_libraries(SDL_gfx INTERFACE SDL)
target_link_libraries(SDL::SDL INTERFACE gdi32 user32 winmm dxguid)
add_compile_options(-march=i386)
set(SDL1_2_BUILD 1)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# i386-mingw32-gcc 3.4.5 does not support -Og.

View File

@ -24,8 +24,8 @@ elseif(SDL1_2_BUILD)
"sdl-1.2/src/rect.c"
"sdl-1.2/src/sprite.c"
"sdl-1.2/src/quad.c")
set(deps ${deps} SDL)
set(privdeps ${privdeps} header SDL_gfx)
set(deps ${deps} SDL::SDL)
set(privdeps ${privdeps} header SDL::SDL_gfx)
endif()
add_library(gfx ${src})

View File

@ -1,7 +1,7 @@
#ifndef GFX_SDL_H
#define GFX_SDL_H
#include <SDL/SDL.h>
#include <SDL.h>
#include <stdbool.h>
#ifdef __cplusplus

View File

@ -2,7 +2,7 @@
#define GFX_SDL_12_PRIVATE_H
#include <gfx.h>
#include <SDL/SDL.h>
#include <SDL.h>
#ifdef __cplusplus
extern "C"

View File

@ -1,7 +1,7 @@
#include <gfx.h>
#include <gfx_private.h>
#include <sdl-1.2/gfx_private.h>
#include <SDL/SDL.h>
#include <SDL.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>

View File

@ -1,7 +1,7 @@
#include <gfx.h>
#include <gfx/port.h>
#include <sdl-1.2/gfx_private.h>
#include <SDL/SDL.h>
#include <SDL.h>
void rect_sort(struct rect *const r)
{

View File

@ -2,8 +2,8 @@
#include <gfx/port.h>
#include <header.h>
#include <sdl-1.2/gfx_private.h>
#include <SDL/SDL.h>
#include <SDL/SDL_rotozoom.h>
#include <SDL.h>
#include <SDL_rotozoom.h>
#include <errno.h>
#include <stddef.h>
#include <stdlib.h>

View File

@ -6,7 +6,7 @@ if(PS1_BUILD)
set(privdeps ${privdeps} PSXSDK::PSXSDK)
elseif(SDL1_2_BUILD)
set(src ${src} "sdl-1.2/src/keyboard.c")
set(deps ${deps} SDL)
set(privdeps ${privdeps} SDL::SDL)
endif()
add_library(keyboard ${src})

View File

@ -1,6 +1,6 @@
#include <keyboard.h>
#include <keyboard_key.h>
#include <SDL/SDL.h>
#include <SDL.h>
#include <stdio.h>
static void append_key(const enum keyboard_key key, struct keyboard *const k)

View File

@ -6,7 +6,7 @@ if(PS1_BUILD)
set(privdeps ${privdeps} PSXSDK::PSXSDK)
elseif(SDL1_2_BUILD)
set(src ${src} "sdl-1.2/src/mouse.c")
set(deps ${deps} SDL)
set(privdeps ${privdeps} SDL::SDL)
endif()
add_library(mouse ${src})

View File

@ -1,5 +1,5 @@
#include <mouse.h>
#include <SDL/SDL.h>
#include <SDL.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>

View File

@ -9,7 +9,7 @@ if(PS1_BUILD)
elseif(SDL1_2_BUILD)
set(src ${src} "sdl-1.2/src/pad.c")
set(inc ${inc} "sdl-1.2/inc")
set(deps ${deps} SDL)
set(deps ${deps} SDL::SDL)
endif()
add_library(pad ${src})

View File

@ -1,5 +1,5 @@
#include <pad.h>
#include <SDL/SDL.h>
#include <SDL.h>
#include <stdio.h>
void pad_port_update(struct pad *const p)

View File

@ -9,8 +9,8 @@ elseif(SDL1_2_BUILD)
set(src
"sdl-1.2/src/sound.c")
set(inc ${inc} "sdl-1.2/inc")
set(deps ${deps} SDL_mixer)
set(privdeps ${privdeps} SDL header)
set(deps ${deps} SDL::SDL_mixer)
set(privdeps ${privdeps} SDL::SDL header)
endif()
add_library(sfx ${src})

View File

@ -1,7 +1,7 @@
#ifndef SFX_SDL1_2_H
#define SFX_SDL1_2_H
#include <SDL/SDL_mixer.h>
#include <SDL_mixer.h>
#include <stdbool.h>
#ifdef __cplusplus

View File

@ -1,8 +1,8 @@
#include <sfx.h>
#include <sfx/port.h>
#include <header.h>
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <SDL.h>
#include <SDL_mixer.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>

View File

@ -8,6 +8,7 @@ if(PS1_BUILD)
elseif(SDL1_2_BUILD)
set(src "sdl-1.2/src/system.c")
set(inc ${inc} "sdl-1.2/inc")
set(privdeps ${privdeps} SDL::SDL)
endif()
add_library(system ${src})

View File

@ -1,7 +1,7 @@
#include <gfx.h>
#include <sfx.h>
#include <system.h>
#include <SDL/SDL.h>
#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>