Squashed 'external/sdl/SDL/' content from commit b8d91252c
git-subtree-dir: external/sdl/SDL git-subtree-split: b8d91252c6488cf9c645aba447b56bb9dbd9609a
This commit is contained in:
91
cmake/test/CMakeLists.txt
Normal file
91
cmake/test/CMakeLists.txt
Normal file
@ -0,0 +1,91 @@
|
||||
# This cmake build script is meant for verifying the various CMake configuration script.
|
||||
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(sdl_test LANGUAGES C)
|
||||
|
||||
include(GenerateExportHeader)
|
||||
|
||||
if(ANDROID)
|
||||
macro(add_executable NAME)
|
||||
set(args ${ARGN})
|
||||
list(REMOVE_ITEM args WIN32)
|
||||
add_library(${NAME} SHARED ${args})
|
||||
unset(args)
|
||||
endmacro()
|
||||
endif()
|
||||
|
||||
cmake_policy(SET CMP0074 NEW)
|
||||
|
||||
# Override CMAKE_FIND_ROOT_PATH_MODE to allow search for SDL3 outside of sysroot
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)
|
||||
|
||||
include(FeatureSummary)
|
||||
|
||||
option(TEST_SHARED "Test linking to shared SDL3 library" ON)
|
||||
add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library")
|
||||
|
||||
option(TEST_STATIC "Test linking to static SDL3 library" ON)
|
||||
add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library")
|
||||
|
||||
option(TEST_TEST "Test linking to SDL3_test library" ON)
|
||||
add_feature_info("TEST_TEST" TEST_STATIC "Test linking to SDL test library")
|
||||
|
||||
find_package(SDL3 REQUIRED CONFIG COMPONENTS Headers)
|
||||
add_library(headers_test OBJECT inc_sdl_slash.c inc_sdl_noslash.c)
|
||||
target_link_libraries(headers_test PRIVATE SDL3::Headers)
|
||||
|
||||
if(TEST_SHARED)
|
||||
find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3-shared)
|
||||
add_executable(gui-shared WIN32 main_gui.c)
|
||||
target_link_libraries(gui-shared PRIVATE SDL3::SDL3-shared)
|
||||
if(WIN32)
|
||||
add_custom_command(TARGET gui-shared POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:SDL3::SDL3-shared>" "$<TARGET_FILE_DIR:gui-shared>"
|
||||
)
|
||||
endif()
|
||||
|
||||
add_library(sharedlib-shared SHARED main_lib.c)
|
||||
target_link_libraries(sharedlib-shared PRIVATE SDL3::SDL3-shared)
|
||||
generate_export_header(sharedlib-shared EXPORT_MACRO_NAME MYLIBRARY_EXPORT)
|
||||
target_compile_definitions(sharedlib-shared PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-shared_export.h\"")
|
||||
set_target_properties(sharedlib-shared PROPERTIES C_VISIBILITY_PRESET "hidden")
|
||||
|
||||
add_executable(cli-shared main_cli.c)
|
||||
target_link_libraries(cli-shared PRIVATE SDL3::SDL3-shared)
|
||||
if(WIN32)
|
||||
add_custom_command(TARGET cli-shared POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:SDL3::SDL3-shared>" "$<TARGET_FILE_DIR:cli-shared>"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(TEST_TEST)
|
||||
add_executable(sdltest-shared sdltest.c)
|
||||
target_link_libraries(sdltest-shared PRIVATE SDL3::SDL3_test SDL3::SDL3-shared)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(TEST_STATIC)
|
||||
find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3-static)
|
||||
add_executable(gui-static WIN32 main_gui.c)
|
||||
target_link_libraries(gui-static PRIVATE SDL3::SDL3-static)
|
||||
|
||||
option(SDL_STATIC_PIC "SDL static library has been built with PIC")
|
||||
if(SDL_STATIC_PIC OR WIN32)
|
||||
add_library(sharedlib-static SHARED main_lib.c)
|
||||
target_link_libraries(sharedlib-static PRIVATE SDL3::SDL3-static)
|
||||
generate_export_header(sharedlib-static EXPORT_MACRO_NAME MYLIBRARY_EXPORT)
|
||||
target_compile_definitions(sharedlib-static PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-static_export.h\"")
|
||||
set_target_properties(sharedlib-static PROPERTIES C_VISIBILITY_PRESET "hidden")
|
||||
endif()
|
||||
|
||||
if(TEST_TEST)
|
||||
add_executable(sdltest-static sdltest.c)
|
||||
target_link_libraries(sdltest-static PRIVATE SDL3::SDL3_test SDL3::SDL3-static)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package(SDL3 REQUIRED CONFIG COMPONENTS SDL3)
|
||||
add_executable(gui-whatever WIN32 main_gui.c)
|
||||
target_link_libraries(gui-whatever PRIVATE SDL3::SDL3)
|
||||
|
||||
feature_summary(WHAT ALL)
|
8
cmake/test/inc_sdl_noslash.c
Normal file
8
cmake/test/inc_sdl_noslash.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include "SDL.h"
|
||||
#include "SDL_main.h"
|
||||
|
||||
void inc_sdl_noslash(void) {
|
||||
SDL_SetMainReady();
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
SDL_Quit();
|
||||
}
|
8
cmake/test/inc_sdl_slash.c
Normal file
8
cmake/test/inc_sdl_slash.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include "SDL3/SDL.h"
|
||||
#include "SDL3/SDL_main.h"
|
||||
|
||||
void inc_sdl_slash(void) {
|
||||
SDL_SetMainReady();
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
SDL_Quit();
|
||||
}
|
15
cmake/test/main_cli.c
Normal file
15
cmake/test/main_cli.c
Normal file
@ -0,0 +1,15 @@
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_SetMainReady();
|
||||
if (SDL_Init(0) < 0) {
|
||||
SDL_Log("Could not initialize SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
SDL_Delay(100);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
24
cmake/test/main_gui.c
Normal file
24
cmake/test/main_gui.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Surface *screenSurface = NULL;
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_Log("Could not initialize SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
window = SDL_CreateWindow("Hello SDL", 640, 480, 0);
|
||||
if (window == NULL) {
|
||||
SDL_Log("could not create window: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
screenSurface = SDL_GetWindowSurface(window);
|
||||
SDL_FillSurfaceRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xff, 0xff, 0xff));
|
||||
SDL_UpdateWindowSurface(window);
|
||||
SDL_Delay(100);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
34
cmake/test/main_lib.c
Normal file
34
cmake/test/main_lib.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#define SDL_MAIN_HANDLED /* don't drag in header-only SDL_main implementation */
|
||||
#include <SDL3/SDL_main.h>
|
||||
|
||||
#include EXPORT_HEADER
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
int MYLIBRARY_EXPORT mylibrary_init(void);
|
||||
void MYLIBRARY_EXPORT mylibrary_quit(void);
|
||||
int MYLIBRARY_EXPORT mylibrary_work(void);
|
||||
|
||||
int mylibrary_init(void) {
|
||||
SDL_SetMainReady();
|
||||
if (SDL_Init(0) < 0) {
|
||||
SDL_Log("Could not initialize SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mylibrary_quit(void) {
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
int mylibrary_work(void) {
|
||||
SDL_Delay(100);
|
||||
return 0;
|
||||
}
|
9
cmake/test/sdltest.c
Normal file
9
cmake/test/sdltest.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_test.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
SDLTest_CommonState state;
|
||||
SDLTest_CommonDefaultArgs(&state, argc, argv);
|
||||
return 0;
|
||||
}
|
51
cmake/test/test_pkgconfig.sh
Executable file
51
cmake/test/test_pkgconfig.sh
Executable file
@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
|
||||
if test "x$CC" = "x"; then
|
||||
CC=cc
|
||||
fi
|
||||
|
||||
machine="$($CC -dumpmachine)"
|
||||
case "$machine" in
|
||||
*mingw* )
|
||||
EXEPREFIX=""
|
||||
EXESUFFIX=".exe"
|
||||
;;
|
||||
*android* )
|
||||
EXEPREFIX="lib"
|
||||
EXESUFFIX=".so"
|
||||
LDFLAGS="$EXTRA_LDFLAGS -shared"
|
||||
;;
|
||||
* )
|
||||
EXEPREFIX=""
|
||||
EXESUFFIX=""
|
||||
;;
|
||||
esac
|
||||
|
||||
set -e
|
||||
|
||||
# Get the canonical path of the folder containing this script
|
||||
testdir=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)")
|
||||
SDL_CFLAGS="$( pkg-config sdl3 --cflags )"
|
||||
SDL_LDFLAGS="$( pkg-config sdl3 --libs )"
|
||||
SDL_STATIC_LDFLAGS="$( pkg-config sdl3 --libs --static )"
|
||||
|
||||
compile_cmd="$CC -c "$testdir/main_gui.c" -o main_gui_pkgconfig.c.o $SDL_CFLAGS $CFLAGS"
|
||||
link_cmd="$CC main_gui_pkgconfig.c.o -o ${EXEPREFIX}main_gui_pkgconfig${EXESUFFIX} $SDL_LDFLAGS $LDFLAGS"
|
||||
static_link_cmd="$CC main_gui_pkgconfig.c.o -o ${EXEPREFIX}main_gui_pkgconfig_static${EXESUFFIX} $SDL_STATIC_LDFLAGS $LDFLAGS"
|
||||
|
||||
echo "-- CC: $CC"
|
||||
echo "-- CFLAGS: $CFLAGS"
|
||||
echo "-- LDFLASG: $LDFLAGS"
|
||||
echo "-- SDL_CFLAGS: $SDL_CFLAGS"
|
||||
echo "-- SDL_LDFLAGS: $SDL_LDFLAGS"
|
||||
echo "-- SDL_STATIC_LDFLAGS: $SDL_STATIC_LDFLAGS"
|
||||
|
||||
echo "-- COMPILE: $compile_cmd"
|
||||
echo "-- LINK: $link_cmd"
|
||||
echo "-- STATIC_LINK: $static_link_cmd"
|
||||
|
||||
set -x
|
||||
|
||||
$compile_cmd
|
||||
$link_cmd
|
||||
$static_link_cmd
|
Reference in New Issue
Block a user