From 78a37516593dbcedb2b0d1a5177f37c348dbb528 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 16 Jun 2022 16:38:58 +0200 Subject: [PATCH] cmake+ci: fix+test sdl2-config + sdl2.pc for all supported platforms --- .github/workflows/android.yml | 27 +++++++++++++++++--- .github/workflows/main.yml | 10 ++++++++ .github/workflows/ps2.yaml | 38 ++++++++++++++++++++++++++--- .github/workflows/psp.yaml | 14 ++++++++++- .github/workflows/vita.yaml | 14 +++++++++-- CMakeLists.txt | 34 +++++++++++--------------- cmake/macros.cmake | 4 +-- cmake/test/jni/Android.mk | 11 +++++++++ cmake/test/test_pkgconfig.sh | 46 +++++++++++++++++++++++++++++++++++ cmake/test/test_sdlconfig.sh | 46 +++++++++++++++++++++++++++++++++++ sdl2-config.in | 2 +- 11 files changed, 212 insertions(+), 34 deletions(-) create mode 100644 cmake/test/jni/Android.mk create mode 100755 cmake/test/test_pkgconfig.sh create mode 100755 cmake/test/test_sdlconfig.sh diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 65820ee66..6c417da08 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -12,7 +12,7 @@ jobs: matrix: platform: - { name: Android.mk } - - { name: CMake, cmake: '-DCMAKE_SYSTEM_PROCESSOR=aarch64 -DANDROID_PLATFORM=android-23 -DCMAKE_SYSTEM_VERSION=23 ' } + - { name: CMake, cmake: 1, android_abi: "arm64-v8a", android_platform: 23, arch: "aarch64" } steps: - uses: actions/checkout@v2 @@ -28,13 +28,14 @@ jobs: if: ${{ matrix.platform.name == 'CMake' }} run: | sudo apt-get update - sudo apt-get install ninja-build + sudo apt-get install ninja-build pkg-config - name: Configure (CMake) if: ${{ matrix.platform.name == 'CMake' }} run: | cmake -B build \ -DCMAKE_TOOLCHAIN_FILE=${{ steps.setup_ndk.outputs.ndk-path }}/build/cmake/android.toolchain.cmake \ - ${{ matrix.platform.cmake }} \ + -DANDROID_PLATFORM=${{ matrix.platform.android_platform }} \ + -DANDROID_ABI=${{ matrix.platform.android_abi }} \ -DSDL_STATIC_PIC=ON \ -DCMAKE_INSTALL_PREFIX=prefix \ -DCMAKE_BUILD_TYPE=Release \ @@ -54,7 +55,25 @@ jobs: run: | cmake -S cmake/test -B cmake_config_build -G Ninja \ -DCMAKE_TOOLCHAIN_FILE=${{ steps.setup_ndk.outputs.ndk-path }}/build/cmake/android.toolchain.cmake \ - ${{ matrix.platform.cmake }} \ + -DANDROID_PLATFORM=${{ matrix.platform.android_platform }} \ + -DANDROID_ABI=${{ matrix.platform.android_abi }} \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_PREFIX_PATH=${{ env.SDL2_DIR }} cmake --build cmake_config_build --verbose + - name: Verify sdl2-config + if: ${{ matrix.platform.name == 'CMake' }} + run: | + export CC="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=${{ matrix.platform.arch }}-none-linux-androideabi${{ matrix.platform.android_platform }}" + export PATH=${{ env.SDL2_DIR }}/bin:$PATH + cmake/test/test_sdlconfig.sh + - name: Verify sdl2.pc + if: ${{ matrix.platform.name == 'CMake' }} + run: | + export CC="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=${{ matrix.platform.arch }}-none-linux-androideabi${{ matrix.platform.android_platform }}" + export PKG_CONFIG_PATH=${{ env.SDL2_DIR }}/lib/pkgconfig + cmake/test/test_pkgconfig.sh + - name: Verify Android.mk + if: ${{ matrix.platform.name == 'CMake' }} + run: | + export NDK_MODULE_PATH=${{ env.SDL2_DIR }}/share/ndk-modules + ndk-build -C ${{ github.workspace }}/cmake/test APP_PLATFORM=android-${{ matrix.platform.android_platform }} APP_ABI=${{ matrix.platform.android_abi }} NDK_OUT=$PWD NDK_LIBS_OUT=$PWD V=1 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f49f54a8a..7cfc3f20a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -189,6 +189,16 @@ jobs: -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_PREFIX_PATH=${{ env.SDL2_DIR }} cmake --build cmake_config_build --verbose + - name: Verify sdl2-config + run: | + export CC=${{ matrix.platform.cc || 'gcc' }} + export PATH=${{ env.SDL2_DIR }}/bin:$PATH + cmake/test/test_sdlconfig.sh + - name: Verify sdl2.pc + run: | + export CC=${{ matrix.platform.cc || 'gcc' }} + export PKG_CONFIG_PATH=${{ env.SDL2_DIR }}/lib/pkgconfig + cmake/test/test_pkgconfig.sh - name: Distcheck (Autotools) if: matrix.platform.autotools run: | diff --git a/.github/workflows/ps2.yaml b/.github/workflows/ps2.yaml index da777cddd..a8f9ce2cb 100644 --- a/.github/workflows/ps2.yaml +++ b/.github/workflows/ps2.yaml @@ -11,11 +11,41 @@ jobs: - name: Setup dependencies run: | apk update - apk add cmake gmp mpc1 mpfr4 make - - name: Configure CMake - run: cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$PS2DEV/ps2sdk/ps2dev.cmake -DSDL_TESTS=ON + apk add cmake gmp mpc1 mpfr4 ninja pkgconf + - name: Configure (CMake) + run: | + cmake -S . -B build -G Ninja\ + -DCMAKE_TOOLCHAIN_FILE=$PS2DEV/ps2sdk/ps2dev.cmake \ + -DSDL_TESTS=ON \ + -DCMAKE_INSTALL_PREFIX=cmake_prefix \ + -DCMAKE_BUILD_TYPE=Release - name: Build - run: cmake --build build + run: cmake --build build --config Release --verbose --parallel + - name: Install (CMake) + run: | + set -eu + cmake --install build/ --config Release + echo "SDL2_DIR=$(pwd)/cmake_prefix" >> $GITHUB_ENV + ( cd cmake_prefix; find ) | LC_ALL=C sort -u + + - name: Verify CMake configuration files + run: | + cmake -S cmake/test -B cmake_config_build -G Ninja \ + -DCMAKE_TOOLCHAIN_FILE=$PS2DEV/ps2sdk/ps2dev.cmake \ + -DTEST_SHARED=FALSE \ + -DCMAKE_PREFIX_PATH=${{ env.SDL2_DIR }} \ + -DCMAKE_BUILD_TYPE=Release + cmake --build cmake_config_build --verbose + - name: Verify sdl2-config + run: | + export CC=mips64r5900el-ps2-elf-gcc + export PATH=${{ env.SDL2_DIR }}/bin:$PATH + cmake/test/test_sdlconfig.sh + - name: Verify sdl2.pc + run: | + export CC=mips64r5900el-ps2-elf-gcc + export PKG_CONFIG_PATH=${{ env.SDL2_DIR }}/lib/pkgconfig + cmake/test/test_pkgconfig.sh - name: Get short SHA id: slug diff --git a/.github/workflows/psp.yaml b/.github/workflows/psp.yaml index 1ca74f6e8..9a9267730 100644 --- a/.github/workflows/psp.yaml +++ b/.github/workflows/psp.yaml @@ -11,7 +11,7 @@ jobs: - name: Setup dependencies run: | apk update - apk add cmake gmp mpc1 mpfr4 make + apk add cmake gmp mpc1 mpfr4 make pkgconf - name: Configure CMake run: | cmake -S . -B build \ @@ -35,3 +35,15 @@ jobs: -DTEST_SHARED=FALSE \ -DCMAKE_BUILD_TYPE=Release cmake --build cmake_config_build --verbose + - name: Verify sdl2-config + run: | + export CC=psp-gcc + export PATH=${{ env.SDL2_DIR }}/bin:$PATH + export EXTRA_LDFLAGS="-L$PSPDEV/lib -L$PSPDEV/psp/lib -L$PSPDEV/psp/sdk/lib" + cmake/test/test_sdlconfig.sh + - name: Verify sdl2.pc + run: | + export CC=psp-gcc + export PKG_CONFIG_PATH=${{ env.SDL2_DIR }}/lib/pkgconfig + export EXTRA_LDFLAGS="-L$PSPDEV/lib -L$PSPDEV/psp/lib -L$PSPDEV/psp/sdk/lib" + cmake/test/test_pkgconfig.sh diff --git a/.github/workflows/vita.yaml b/.github/workflows/vita.yaml index 4e2a02661..9b27370ba 100644 --- a/.github/workflows/vita.yaml +++ b/.github/workflows/vita.yaml @@ -13,10 +13,10 @@ jobs: image: vitasdk/vitasdk:latest steps: - uses: actions/checkout@v2 - - name: Install CMake and GNU Make + - name: Install build requirements run: | apk update - apk add cmake make ninja + apk add cmake ninja pkgconf - name: Configure CMake run: | cmake -S . -B build -G Ninja \ @@ -40,3 +40,13 @@ jobs: -DCMAKE_PREFIX_PATH=${{ env.SDL2_DIR }} \ -DCMAKE_BUILD_TYPE=Release cmake --build cmake_config_build --verbose + - name: Verify sdl2-config + run: | + export CC=arm-vita-eabi-gcc + export PATH=${{ env.SDL2_DIR }}/bin:$PATH + cmake/test/test_sdlconfig.sh + - name: Verify sdl2.pc + run: | + export CC=arm-vita-eabi-gcc + export PKG_CONFIG_PATH=${{ env.SDL2_DIR }}/lib/pkgconfig + cmake/test/test_pkgconfig.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d9dc1a3c..c5dadc045 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1865,11 +1865,11 @@ elseif(WINDOWS) file(GLOB VERSION_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.rc) file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.c) if(MINGW OR CYGWIN) - list(APPEND SDL_LIBS "-lmingw32" "-mwindows") if(NOT SDL2_DISABLE_SDL2MAIN) list(APPEND SDL_CFLAGS "-Dmain=SDL_main") - list(APPEND SDL_LIBS "-lSDL2main") + list(INSERT SDL_LIBS 0 "-lSDL2main") endif(NOT SDL2_DISABLE_SDL2MAIN) + list(INSERT SDL_LIBS 0 "-lmingw32" "-mwindows") endif() elseif(APPLE) @@ -2520,7 +2520,10 @@ elseif(PSP) pspaudio pspvram GL - ) + ) + if(NOT SDL2_DISABLE_SDL2MAIN) + list(INSERT SDL_LIBS 0 "-lSDL2main") + endif(NOT SDL2_DISABLE_SDL2MAIN) elseif(PS2) list(APPEND EXTRA_CFLAGS "-DPS2" "-D__PS2__") @@ -2796,23 +2799,14 @@ Libs.private:") endif() # Clean up the different lists - if (VITA) - listtostrrev(EXTRA_LIBS _EXTRA_LIBS "-l") - set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS}) - list(REMOVE_DUPLICATES SDL_STATIC_LIBS) - listtostrrev(SDL_STATIC_LIBS _SDL_STATIC_LIBS) - set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS}) - listtostrrev(SDL_LIBS _SDL_LIBS) - set(SDL_LIBS ${_SDL_LIBS}) - else() - listtostr(EXTRA_LIBS _EXTRA_LIBS "-l") - set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS}) - list(REMOVE_DUPLICATES SDL_STATIC_LIBS) - listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS) - set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS}) - listtostr(SDL_LIBS _SDL_LIBS) - set(SDL_LIBS ${_SDL_LIBS}) - endif() + listtostr(EXTRA_LIBS _EXTRA_LIBS "-l") + set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS}) + list(REMOVE_DUPLICATES SDL_STATIC_LIBS) + listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS) + set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS}) + message("sdl_libs: ${SDL_LIBS}") + listtostr(SDL_LIBS _SDL_LIBS) + set(SDL_LIBS ${_SDL_LIBS}) listtostr(SDL_CFLAGS _SDL_CFLAGS "") set(SDL_CFLAGS ${_SDL_CFLAGS}) diff --git a/cmake/macros.cmake b/cmake/macros.cmake index af7512257..920785bad 100644 --- a/cmake/macros.cmake +++ b/cmake/macros.cmake @@ -74,7 +74,7 @@ macro(LISTTOSTR _LIST _OUTPUT) # Do not use string(REPLACE ";" " ") here to avoid messing up list # entries foreach(_ITEM ${${_LIST}}) - set(${_OUTPUT} "${_LPREFIX}${_ITEM} ${${_OUTPUT}}") + set(${_OUTPUT} "${${_OUTPUT}} ${_LPREFIX}${_ITEM}") endforeach() endmacro() @@ -88,7 +88,7 @@ macro(LISTTOSTRREV _LIST _OUTPUT) # Do not use string(REPLACE ";" " ") here to avoid messing up list # entries foreach(_ITEM ${${_LIST}}) - set(${_OUTPUT} "${${_OUTPUT}} ${_LPREFIX}${_ITEM}") + set(${_OUTPUT} "${_LPREFIX}${_ITEM} ${${_OUTPUT}}") endforeach() endmacro() diff --git a/cmake/test/jni/Android.mk b/cmake/test/jni/Android.mk new file mode 100644 index 000000000..c4956d685 --- /dev/null +++ b/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/cmake/test/test_pkgconfig.sh b/cmake/test/test_pkgconfig.sh new file mode 100755 index 000000000..2c58a752f --- /dev/null +++ b/cmake/test/test_pkgconfig.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +if test "x$CC" = "x"; then + CC=gcc +fi + +machine="$($CC -dumpmachine)" +case "$machine" in + *mingw* ) + EXEPREFIX="" + EXESUFFIX=".exe" + ;; + *android* ) + EXEPREFIX="lib" + EXESUFFIX=".so" + EXTRA_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)") +CFLAGS="$( pkg-config sdl2 --cflags )" +LDFLAGS="$( pkg-config sdl2 --libs )" + +compile_cmd="$CC -c "$testdir/main_gui.c" -o main_gui_pkgconfig.c.o $CFLAGS $EXTRA_CFLAGS" +link_cmd="$CC main_gui_pkgconfig.c.o -o ${EXEPREFIX}main_gui_pkgconfig${EXESUFFIX} $LDFLAGS $EXTRA_LDFLAGS" + +echo "-- CC: $CC" +echo "-- CFLAGS: $CFLAGS" +echo "-- EXTRA_CFLAGS: $EXTRA_CFLAGS" +echo "-- LDFLASG: $LDFLAGS" +echo "-- EXTRA_LDFLAGS: $EXTRA_LDFLAGS" + +echo "-- COMPILE: $compile_cmd" +echo "-- LINK: $link_cmd" + +set -x + +$compile_cmd +$link_cmd diff --git a/cmake/test/test_sdlconfig.sh b/cmake/test/test_sdlconfig.sh new file mode 100755 index 000000000..ca09bc29b --- /dev/null +++ b/cmake/test/test_sdlconfig.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +if test "x$CC" = "x"; then + CC=gcc +fi + +machine="$($CC -dumpmachine)" +case "$machine" in + *mingw* ) + EXEPREFIX="" + EXESUFFIX=".exe" + ;; + *android* ) + EXEPREFIX="lib" + EXESUFFIX=".so" + EXTRA_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)") +CFLAGS="$( sdl2-config --cflags )" +LDFLAGS="$( sdl2-config --libs )" + +compile_cmd="$CC -c "$testdir/main_gui.c" -o main_gui_sdlconfig.c.o $CFLAGS $EXTRA_CFLAGS" +link_cmd="$CC main_gui_sdlconfig.c.o -o ${EXEPREFIX}main_gui_sdlconfig${EXESUFFIX} $LDFLAGS $EXTRA_LDFLAGS" + +echo "-- CC: $CC" +echo "-- CFLAGS: $CFLAGS" +echo "-- EXTRA_CFLAGS: $EXTRA_CFLAGS" +echo "-- LDFLASG: $LDFLAGS" +echo "-- EXTRA_LDFLAGS: $EXTRA_LDFLAGS" + +echo "-- COMPILE: $compile_cmd" +echo "-- LINK: $link_cmd" + +set -x + +$compile_cmd +$link_cmd diff --git a/sdl2-config.in b/sdl2-config.in index 3a87ab85b..f6eca7668 100644 --- a/sdl2-config.in +++ b/sdl2-config.in @@ -53,7 +53,7 @@ while test $# -gt 0; do @ENABLE_SHARED_TRUE@ ;; @ENABLE_STATIC_TRUE@@ENABLE_SHARED_TRUE@ --static-libs) @ENABLE_STATIC_TRUE@@ENABLE_SHARED_FALSE@ --libs|--static-libs) -@ENABLE_STATIC_TRUE@ sdl_static_libs=$(echo "@SDL_LIBS@ @SDL_STATIC_LIBS@" | sed -E "s#-lSDL2[ $]#-Wl,-Bstatic -lSDL2 -Wl,-Bdynamic #g") +@ENABLE_STATIC_TRUE@ sdl_static_libs=$(echo "@SDL_LIBS@ @SDL_STATIC_LIBS@" | sed -E "s#-lSDL2[ $]#$libdir/libSDL2.a #g") @ENABLE_STATIC_TRUE@ echo -L@libdir@ $sdl_static_libs @ENABLE_STATIC_TRUE@ ;; *)