aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-07-23 04:18:22 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-07-23 04:23:05 +0200
commit5829ef82c45ce2ea7ed957917346a23acbd09e86 (patch)
treeee7b21b52359c5320a25675046623de5173fc56a
parent37ee2c11f34c55773c2afff5f8833d4bad7e4e8b (diff)
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.
-rw-r--r--CMakeLists.txt15
-rw-r--r--cmake/host.cmake5
-rw-r--r--cmake/win9x.cmake27
-rw-r--r--src/gfx/CMakeLists.txt4
-rw-r--r--src/gfx/sdl-1.2/inc/gfx/port.h2
-rw-r--r--src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h2
-rw-r--r--src/gfx/sdl-1.2/src/env.c2
-rw-r--r--src/gfx/sdl-1.2/src/rect.c2
-rw-r--r--src/gfx/sdl-1.2/src/sprite.c4
-rw-r--r--src/keyboard/CMakeLists.txt2
-rw-r--r--src/keyboard/sdl-1.2/src/keyboard.c2
-rw-r--r--src/mouse/CMakeLists.txt2
-rw-r--r--src/mouse/sdl-1.2/src/mouse.c2
-rw-r--r--src/pad/CMakeLists.txt2
-rw-r--r--src/pad/sdl-1.2/src/pad.c2
-rw-r--r--src/sfx/CMakeLists.txt4
-rw-r--r--src/sfx/sdl-1.2/inc/sfx/port.h2
-rw-r--r--src/sfx/sdl-1.2/src/sound.c4
-rw-r--r--src/system/CMakeLists.txt1
-rw-r--r--src/system/sdl-1.2/src/system.c2
20 files changed, 37 insertions, 51 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 37a6a94..f6f4fab 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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.
diff --git a/cmake/host.cmake b/cmake/host.cmake
index bb0827d..6fa47b9 100644
--- a/cmake/host.cmake
+++ b/cmake/host.cmake
@@ -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()
diff --git a/cmake/win9x.cmake b/cmake/win9x.cmake
index 46bb725..a4d8f79 100644
--- a/cmake/win9x.cmake
+++ b/cmake/win9x.cmake
@@ -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.
diff --git a/src/gfx/CMakeLists.txt b/src/gfx/CMakeLists.txt
index 619ce60..86f99c2 100644
--- a/src/gfx/CMakeLists.txt
+++ b/src/gfx/CMakeLists.txt
@@ -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})
diff --git a/src/gfx/sdl-1.2/inc/gfx/port.h b/src/gfx/sdl-1.2/inc/gfx/port.h
index 9e58498..cca4a3e 100644
--- a/src/gfx/sdl-1.2/inc/gfx/port.h
+++ b/src/gfx/sdl-1.2/inc/gfx/port.h
@@ -1,7 +1,7 @@
#ifndef GFX_SDL_H
#define GFX_SDL_H
-#include <SDL/SDL.h>
+#include <SDL.h>
#include <stdbool.h>
#ifdef __cplusplus
diff --git a/src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h b/src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h
index d095cc0..9d952d1 100644
--- a/src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h
+++ b/src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h
@@ -2,7 +2,7 @@
#define GFX_SDL_12_PRIVATE_H
#include <gfx.h>
-#include <SDL/SDL.h>
+#include <SDL.h>
#ifdef __cplusplus
extern "C"
diff --git a/src/gfx/sdl-1.2/src/env.c b/src/gfx/sdl-1.2/src/env.c
index 74ebb2f..c6239f3 100644
--- a/src/gfx/sdl-1.2/src/env.c
+++ b/src/gfx/sdl-1.2/src/env.c
@@ -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>
diff --git a/src/gfx/sdl-1.2/src/rect.c b/src/gfx/sdl-1.2/src/rect.c
index eab7145..bf4b54d 100644
--- a/src/gfx/sdl-1.2/src/rect.c
+++ b/src/gfx/sdl-1.2/src/rect.c
@@ -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)
{
diff --git a/src/gfx/sdl-1.2/src/sprite.c b/src/gfx/sdl-1.2/src/sprite.c
index 6dbfa96..4c1ecbc 100644
--- a/src/gfx/sdl-1.2/src/sprite.c
+++ b/src/gfx/sdl-1.2/src/sprite.c
@@ -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>
diff --git a/src/keyboard/CMakeLists.txt b/src/keyboard/CMakeLists.txt
index 3ef79aa..5fa8892 100644
--- a/src/keyboard/CMakeLists.txt
+++ b/src/keyboard/CMakeLists.txt
@@ -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})
diff --git a/src/keyboard/sdl-1.2/src/keyboard.c b/src/keyboard/sdl-1.2/src/keyboard.c
index fafa754..a688154 100644
--- a/src/keyboard/sdl-1.2/src/keyboard.c
+++ b/src/keyboard/sdl-1.2/src/keyboard.c
@@ -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)
diff --git a/src/mouse/CMakeLists.txt b/src/mouse/CMakeLists.txt
index 7cab57c..57525ec 100644
--- a/src/mouse/CMakeLists.txt
+++ b/src/mouse/CMakeLists.txt
@@ -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})
diff --git a/src/mouse/sdl-1.2/src/mouse.c b/src/mouse/sdl-1.2/src/mouse.c
index 4b95ae2..56b22f3 100644
--- a/src/mouse/sdl-1.2/src/mouse.c
+++ b/src/mouse/sdl-1.2/src/mouse.c
@@ -1,5 +1,5 @@
#include <mouse.h>
-#include <SDL/SDL.h>
+#include <SDL.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
diff --git a/src/pad/CMakeLists.txt b/src/pad/CMakeLists.txt
index c1cab30..6470865 100644
--- a/src/pad/CMakeLists.txt
+++ b/src/pad/CMakeLists.txt
@@ -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})
diff --git a/src/pad/sdl-1.2/src/pad.c b/src/pad/sdl-1.2/src/pad.c
index f6a96c1..57fdb25 100644
--- a/src/pad/sdl-1.2/src/pad.c
+++ b/src/pad/sdl-1.2/src/pad.c
@@ -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)
diff --git a/src/sfx/CMakeLists.txt b/src/sfx/CMakeLists.txt
index 099e65f..f503408 100644
--- a/src/sfx/CMakeLists.txt
+++ b/src/sfx/CMakeLists.txt
@@ -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})
diff --git a/src/sfx/sdl-1.2/inc/sfx/port.h b/src/sfx/sdl-1.2/inc/sfx/port.h
index 2279229..77383ad 100644
--- a/src/sfx/sdl-1.2/inc/sfx/port.h
+++ b/src/sfx/sdl-1.2/inc/sfx/port.h
@@ -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
diff --git a/src/sfx/sdl-1.2/src/sound.c b/src/sfx/sdl-1.2/src/sound.c
index c7ef240..fb58477 100644
--- a/src/sfx/sdl-1.2/src/sound.c
+++ b/src/sfx/sdl-1.2/src/sound.c
@@ -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>
diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt
index 28a7310..011aee6 100644
--- a/src/system/CMakeLists.txt
+++ b/src/system/CMakeLists.txt
@@ -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})
diff --git a/src/system/sdl-1.2/src/system.c b/src/system/sdl-1.2/src/system.c
index c1a79e9..24c3e18 100644
--- a/src/system/sdl-1.2/src/system.c
+++ b/src/system/sdl-1.2/src/system.c
@@ -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>