Commit 78a37516593dbcedb2b0d1a5177f37c348dbb528

Anonymous Maarten 2022-06-16T16:38:58

cmake+ci: fix+test sdl2-config + sdl2.pc for all supported platforms

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml
index 65820ee..6c417da 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 f49f54a..7cfc3f2 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 da777cd..a8f9ce2 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 1ca74f6..9a92677 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 4e2a026..9b27370 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 9d9dc1a..c5dadc0 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 af75122..920785b 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 0000000..c4956d6
--- /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 0000000..2c58a75
--- /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 0000000..ca09bc2
--- /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 3a87ab8..f6eca76 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@      ;;
     *)