From 8222bfe56d4dabe8d92fc4b25ea1b0163b16f3e1 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 4 May 2024 16:51:29 -0700 Subject: Initial commit. --- src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt | 124 +++++++++++++++++++++ src/contrib/SDL-2.30.2/cmake/test/jni/Android.mk | 11 ++ src/contrib/SDL-2.30.2/cmake/test/main_cli.c | 14 +++ src/contrib/SDL-2.30.2/cmake/test/main_gui.c | 28 +++++ src/contrib/SDL-2.30.2/cmake/test/main_lib.c | 33 ++++++ .../SDL-2.30.2/cmake/test/test_pkgconfig.sh | 51 +++++++++ .../SDL-2.30.2/cmake/test/test_sdlconfig.sh | 51 +++++++++ 7 files changed, 312 insertions(+) create mode 100644 src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt create mode 100644 src/contrib/SDL-2.30.2/cmake/test/jni/Android.mk create mode 100644 src/contrib/SDL-2.30.2/cmake/test/main_cli.c create mode 100644 src/contrib/SDL-2.30.2/cmake/test/main_gui.c create mode 100644 src/contrib/SDL-2.30.2/cmake/test/main_lib.c create mode 100755 src/contrib/SDL-2.30.2/cmake/test/test_pkgconfig.sh create mode 100755 src/contrib/SDL-2.30.2/cmake/test/test_sdlconfig.sh (limited to 'src/contrib/SDL-2.30.2/cmake/test') diff --git a/src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt b/src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt new file mode 100644 index 0000000..388e86c --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/test/CMakeLists.txt @@ -0,0 +1,124 @@ +# 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 SDL2 outside of sysroot +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER) + +include(FeatureSummary) + +option(TEST_SHARED "Test linking to shared SDL2 library" ON) +add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library") + +option(TEST_STATIC "Test linking to static SDL2 library" ON) +add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library") + +if(TEST_SHARED) + find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2) + if(EMSCRIPTEN OR (WIN32 AND NOT WINDOWS_STORE)) + find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main) + endif() + add_executable(gui-shared WIN32 main_gui.c) + if(TARGET SDL2::SDL2main) + target_link_libraries(gui-shared PRIVATE SDL2::SDL2main) + endif() + target_link_libraries(gui-shared PRIVATE SDL2::SDL2) + if(WIN32) + add_custom_command(TARGET gui-shared POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different "$" "$" + ) + endif() + + add_library(sharedlib-shared SHARED main_lib.c) + target_link_libraries(sharedlib-shared PRIVATE SDL2::SDL2) + 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(gui-shared-vars WIN32 main_gui.c) + target_link_libraries(gui-shared-vars PRIVATE ${SDL2_LIBRARIES}) + target_include_directories(gui-shared-vars PRIVATE ${SDL2_INCLUDE_DIRS}) + + add_executable(cli-shared main_cli.c) + target_link_libraries(cli-shared PRIVATE SDL2::SDL2) + if(WIN32) + add_custom_command(TARGET cli-shared POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different "$" "$" + ) + endif() + + # SDL2_LIBRARIES does not support creating a cli SDL2 application + # (it is possible that SDL2main is a stub, but we don't know for sure) + if(NOT TARGET SDL2::SDL2main) + add_executable(cli-shared-vars main_cli.c) + target_link_libraries(cli-shared-vars PRIVATE ${SDL2_LIBRARIES}) + target_include_directories(cli-shared-vars PRIVATE ${SDL2_INCLUDE_DIRS}) + endif() + + add_library(sharedlib-shared-vars SHARED main_lib.c) + target_link_libraries(sharedlib-shared-vars PRIVATE ${SDL2_LIBRARIES}) + target_include_directories(sharedlib-shared-vars PRIVATE ${SDL2_INCLUDE_DIRS}) + generate_export_header(sharedlib-shared-vars EXPORT_MACRO_NAME MYLIBRARY_EXPORT) + target_compile_definitions(sharedlib-shared-vars PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-shared-vars_export.h\"") + set_target_properties(sharedlib-shared-vars PROPERTIES C_VISIBILITY_PRESET "hidden") +endif() + +if(TEST_STATIC) + find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2-static) + if(EMSCRIPTEN OR (WIN32 AND NOT WINDOWS_STORE)) + find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main) + endif() + add_executable(gui-static WIN32 main_gui.c) + if(TARGET SDL2::SDL2main) + target_link_libraries(gui-static PRIVATE SDL2::SDL2main) + endif() + target_link_libraries(gui-static PRIVATE SDL2::SDL2-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 SDL2::SDL2-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() + + add_executable(gui-static-vars WIN32 main_gui.c) + target_link_libraries(gui-static-vars PRIVATE ${SDL2MAIN_LIBRARY} ${SDL2_STATIC_LIBRARIES}) + target_include_directories(gui-static-vars PRIVATE ${SDL2_INCLUDE_DIRS}) + + add_executable(cli-static main_cli.c) + target_link_libraries(cli-static PRIVATE SDL2::SDL2-static) + + # SDL2_LIBRARIES does not support creating a cli SDL2 application (when SDL2::SDL2main is available) + # (it is possible that SDL2main is a stub, but we don't know for sure) + if(NOT TARGET SDL2::SDL2main) + add_executable(cli-static-vars main_cli.c) + target_link_libraries(cli-static-vars PRIVATE ${SDL2_STATIC_LIBRARIES}) + target_include_directories(cli-static-vars PRIVATE ${SDL2_INCLUDE_DIRS}) + endif() +endif() + +message(STATUS "SDL2_PREFIX: ${SDL2_PREFIX}") +message(STATUS "SDL2_INCLUDE_DIR: ${SDL2_INCLUDE_DIR}") +message(STATUS "SDL2_INCLUDE_DIRS: ${SDL2_INCLUDE_DIRS}") +message(STATUS "SDL2_LIBRARIES: ${SDL2_LIBRARIES}") +message(STATUS "SDL2_STATIC_LIBRARIES: ${SDL2_STATIC_LIBRARIES}") +message(STATUS "SDL2MAIN_LIBRARY: ${SDL2MAIN_LIBRARY}") +message(STATUS "SDL2TEST_LIBRARY: ${SDL2TEST_LIBRARY}") + +feature_summary(WHAT ALL) diff --git a/src/contrib/SDL-2.30.2/cmake/test/jni/Android.mk b/src/contrib/SDL-2.30.2/cmake/test/jni/Android.mk new file mode 100644 index 0000000..c4956d6 --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/test/jni/Android.mk @@ -0,0 +1,11 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := main_gui_androidmk +LOCAL_SRC_FILES := ../main_gui.c +LOCAL_SHARED_LIBRARIES += SDL2 +include $(BUILD_SHARED_LIBRARY) + +$(call import-module,SDL2main) +$(call import-module,SDL2) diff --git a/src/contrib/SDL-2.30.2/cmake/test/main_cli.c b/src/contrib/SDL-2.30.2/cmake/test/main_cli.c new file mode 100644 index 0000000..f6b0836 --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/test/main_cli.c @@ -0,0 +1,14 @@ +#define SDL_MAIN_HANDLED +#include "SDL.h" +#include + +int main(int argc, char *argv[]) { + SDL_SetMainReady(); + if (SDL_Init(0) < 0) { + fprintf(stderr, "could not initialize sdl2: %s\n", SDL_GetError()); + return 1; + } + SDL_Delay(100); + SDL_Quit(); + return 0; +} diff --git a/src/contrib/SDL-2.30.2/cmake/test/main_gui.c b/src/contrib/SDL-2.30.2/cmake/test/main_gui.c new file mode 100644 index 0000000..ca2d92e --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/test/main_gui.c @@ -0,0 +1,28 @@ +#include "SDL.h" +#include + +int main(int argc, char *argv[]) { + SDL_Window *window = NULL; + SDL_Surface *screenSurface = NULL; + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + fprintf(stderr, "could not initialize sdl2: %s\n", SDL_GetError()); + return 1; + } + window = SDL_CreateWindow( + "hello_sdl2", + SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + 640, 480, + SDL_WINDOW_SHOWN + ); + if (!window) { + fprintf(stderr, "could not create window: %s\n", SDL_GetError()); + return 1; + } + screenSurface = SDL_GetWindowSurface(window); + SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xff, 0xff, 0xff)); + SDL_UpdateWindowSurface(window); + SDL_Delay(100); + SDL_DestroyWindow(window); + SDL_Quit(); + return 0; +} diff --git a/src/contrib/SDL-2.30.2/cmake/test/main_lib.c b/src/contrib/SDL-2.30.2/cmake/test/main_lib.c new file mode 100644 index 0000000..9801ed5 --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/test/main_lib.c @@ -0,0 +1,33 @@ +#include "SDL.h" +#include + +#include EXPORT_HEADER + +#if defined(_WIN32) +#include +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) { + fprintf(stderr, "could not initialize sdl2: %s\n", SDL_GetError()); + return 1; + } + return 0; +} + +void mylibrary_quit(void) { + SDL_Quit(); +} + +int mylibrary_work(void) { + SDL_Delay(100); + return 0; +} diff --git a/src/contrib/SDL-2.30.2/cmake/test/test_pkgconfig.sh b/src/contrib/SDL-2.30.2/cmake/test/test_pkgconfig.sh new file mode 100755 index 0000000..500cd09 --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/test/test_pkgconfig.sh @@ -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="$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 sdl2 --cflags )" +SDL_LDFLAGS="$( pkg-config sdl2 --libs )" +SDL_STATIC_LDFLAGS="$( pkg-config sdl2 --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 diff --git a/src/contrib/SDL-2.30.2/cmake/test/test_sdlconfig.sh b/src/contrib/SDL-2.30.2/cmake/test/test_sdlconfig.sh new file mode 100755 index 0000000..fa41dbb --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/test/test_sdlconfig.sh @@ -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="$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="$( sdl2-config --cflags )" +SDL_LDFLAGS="$( sdl2-config --libs )" +SDL_STATIC_LDFLAGS="$( sdl2-config --static-libs )" + +compile_cmd="$CC -c "$testdir/main_gui.c" -o main_gui_sdlconfig.c.o $CFLAGS $SDL_CFLAGS" +link_cmd="$CC main_gui_sdlconfig.c.o -o ${EXEPREFIX}main_gui_sdlconfig${EXESUFFIX} $SDL_LDFLAGS $LDFLAGS" +static_link_cmd="$CC main_gui_sdlconfig.c.o -o ${EXEPREFIX}main_gui_sdlconfig_static${EXESUFFIX} $SDL_STATIC_LDFLAGS $LDFLAGS" + +echo "-- CC: $CC" +echo "-- CFLAGS: $CFLAGS" +echo "-- LDFLAGS: $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 -- cgit v1.2.3