libsdl-org / SDL_mixer

An audio mixer that supports various file formats for Simple Directmedia Layer.
zlib License
405 stars 138 forks source link

Android build with SDL2MIXER_FLAC=ON can't find libFLAC.so #457

Closed genpfault closed 1 year ago

genpfault commented 1 year ago

The build can't find libFLAC.so with SDL2MIXER_FLAC=ON on an Android build, causing the build to fail:

$ ./gradlew build

...

> Task :buildCMakeDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':buildCMakeDebug'.
> Expected output file at /project-name/android/build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/libFLAC.so for target FLAC but there was none

...

CMakeLists.txt:

cmake_minimum_required( VERSION 3.18.0 )
cmake_policy( SET CMP0091 NEW )
project( appname )

set( SDL_LIBC ON CACHE BOOL "" FORCE )
set( SDL_TEST OFF CACHE BOOL "" FORCE )
# https://github.com/libsdl-org/SDL.git
# release-2.24.1
add_subdirectory( external/sdl )

set( BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE )
set( SDL2MIXER_FLAC ON CACHE BOOL "" FORCE )
set( SDL2MIXER_OPUS OFF CACHE BOOL "" FORCE )
set( SDL2MIXER_SAMPLES OFF CACHE BOOL "" FORCE )
set( SDL2MIXER_VENDORED ON CACHE BOOL "" FORCE )
# https://github.com/libsdl-org/SDL_mixer.git
# HEAD of 'main' branch as of today: db9da3d416077195a2f84403b2fb40955518b4ab
add_subdirectory( external/sdl-mixer )

set( SRCS "src/main.cpp" )

set( LIBS
    SDL2::SDL2main
    SDL2::SDL2-static
    SDL2_mixer::SDL2_mixer-static
    )

if( ${CMAKE_SYSTEM_NAME} MATCHES "Android")
    add_library( main SHARED ${SRCS} )
    target_link_libraries( main ${LIBS} )
else()
    add_executable( ${CMAKE_PROJECT_NAME} ${SRCS} )
    target_link_libraries( ${CMAKE_PROJECT_NAME} ${LIBS} )
endif()

src/main.cpp:

#include <SDL.h>
#include <SDL_mixer.h>

int main( int argc, char** argv )
{
    SDL_Init( SDL_INIT_EVERYTHING );
    SDL_Quit();
    return 0;
}

The same CMakeLists.txt builds successfully with SDL2MIXER_FLAC=OFF, as well as on the host Debian 11 system with:

cmake -B build -G "Ninja Multi-Config" .
cmake --build build --config Release --parallel $(nproc)
slouken commented 1 year ago

Is this with the last release or the latest from GitHub?

madebr commented 1 year ago

I see the following error when building FLAC for x86 targeting Android:

[1/5] Building ASM_NASM object external/flac/src/libFLAC/ia32/CMakeFiles/FLAC-asm.dir/cpu_asm.nasm.o
FAILED: external/flac/src/libFLAC/ia32/CMakeFiles/FLAC-asm.dir/cpu_asm.nasm.o 
/opt/android/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/yasm -DFLAC__HAS_NASM -DHAVE_CONFIG_H -D_DARWIN_C_SOURCE -D_POSIX_PTHREAD_SEMANTICS -D_TANDEM_SOURCE -D__STDC_WANT_IEC_60559_BFP_EXT__ -D__STDC_WANT_IEC_60559_DFP_EXT__ -D__STDC_WANT_IEC_60559_FUNCS_EXT__ -D__STDC_WANT_IEC_60559_TYPES_EXT__ -D__STDC_WANT_LIB_EXT2__ -D__STDC_WANT_MATH_SPEC_FUNCS__ -I/sdl_mixer/external/flac/include -I/sdl_mixer/build-android-prefab/build_x86/shared_ON/external/flac -I/sdl_mixer/external/flac/src/libFLAC/ia32 -mstackrealign -I/sdl_mixer/external/flac/src/libFLAC/ia32/ -dOBJ_FORMAT_elf -f elf -o external/flac/src/libFLAC/ia32/CMakeFiles/FLAC-asm.dir/cpu_asm.nasm.o /sdl_mixer/external/flac/src/libFLAC/ia32/cpu_asm.nasm
yasm: FATAL: `stackrealign' is not a valid machine for architecture `x86'
[2/5] Building ASM_NASM object external/flac/src/libFLAC/ia32/CMakeFiles/FLAC-asm.dir/fixed_asm.nasm.o
FAILED: external/flac/src/libFLAC/ia32/CMakeFiles/FLAC-asm.dir/fixed_asm.nasm.o 
/opt/android/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/yasm -DFLAC__HAS_NASM -DHAVE_CONFIG_H -D_DARWIN_C_SOURCE -D_POSIX_PTHREAD_SEMANTICS -D_TANDEM_SOURCE -D__STDC_WANT_IEC_60559_BFP_EXT__ -D__STDC_WANT_IEC_60559_DFP_EXT__ -D__STDC_WANT_IEC_60559_FUNCS_EXT__ -D__STDC_WANT_IEC_60559_TYPES_EXT__ -D__STDC_WANT_LIB_EXT2__ -D__STDC_WANT_MATH_SPEC_FUNCS__ -I/sdl_mixer/external/flac/include -I/sdl_mixer/build-android-prefab/build_x86/shared_ON/external/flac -I/sdl_mixer/external/flac/src/libFLAC/ia32 -mstackrealign -I/sdl_mixer/external/flac/src/libFLAC/ia32/ -dOBJ_FORMAT_elf -f elf -o external/flac/src/libFLAC/ia32/CMakeFiles/FLAC-asm.dir/fixed_asm.nasm.o /sdl_mixer/external/flac/src/libFLAC/ia32/fixed_asm.nasm
yasm: FATAL: `stackrealign' is not a valid machine for architecture `x86'
[3/5] Building ASM_NASM object external/flac/src/libFLAC/ia32/CMakeFiles/FLAC-asm.dir/lpc_asm.nasm.o
FAILED: external/flac/src/libFLAC/ia32/CMakeFiles/FLAC-asm.dir/lpc_asm.nasm.o 
/opt/android/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/yasm -DFLAC__HAS_NASM -DHAVE_CONFIG_H -D_DARWIN_C_SOURCE -D_POSIX_PTHREAD_SEMANTICS -D_TANDEM_SOURCE -D__STDC_WANT_IEC_60559_BFP_EXT__ -D__STDC_WANT_IEC_60559_DFP_EXT__ -D__STDC_WANT_IEC_60559_FUNCS_EXT__ -D__STDC_WANT_IEC_60559_TYPES_EXT__ -D__STDC_WANT_LIB_EXT2__ -D__STDC_WANT_MATH_SPEC_FUNCS__ -I/sdl_mixer/external/flac/include -I/sdl_mixer/build-android-prefab/build_x86/shared_ON/external/flac -I/sdl_mixer/external/flac/src/libFLAC/ia32 -mstackrealign -I/sdl_mixer/external/flac/src/libFLAC/ia32/ -dOBJ_FORMAT_elf -f elf -o external/flac/src/libFLAC/ia32/CMakeFiles/FLAC-asm.dir/lpc_asm.nasm.o /sdl_mixer/external/flac/src/libFLAC/ia32/lpc_asm.nasm
yasm: FATAL: `stackrealign' is not a valid machine for architecture `x86'
ninja: build stopped: subcommand failed.
madebr commented 1 year ago

Getting rid of -mstackrealign gives the following errors:

[1/153] Building ASM_NASM object external/flac/src/libFLAC/ia32/CMakeFiles/FLAC-asm.dir/cpu_asm.nasm.o
FAILED: external/flac/src/libFLAC/ia32/CMakeFiles/FLAC-asm.dir/cpu_asm.nasm.o 
/opt/android/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/yasm -DFLAC__HAS_NASM -DHAVE_CONFIG_H -D_DARWIN_C_SOURCE -D_POSIX_PTHREAD_SEMANTICS -D_TANDEM_SOURCE -D__STDC_WANT_IEC_60559_BFP_EXT__ -D__STDC_WANT_IEC_60559_DFP_EXT__ -D__STDC_WANT_IEC_60559_FUNCS_EXT__ -D__STDC_WANT_IEC_60559_TYPES_EXT__ -D__STDC_WANT_LIB_EXT2__ -D__STDC_WANT_MATH_SPEC_FUNCS__ -I/sdl_mixer/external/flac/include -I/sdl_mixer/build-android-prefab/build_x86/shared_ON/external/flac -I/sdl_mixer/external/flac/src/libFLAC/ia32 -I/sdl_mixer/external/flac/src/libFLAC/ia32/ -dOBJ_FORMAT_elf -f elf -o external/flac/src/libFLAC/ia32/CMakeFiles/FLAC-asm.dir/cpu_asm.nasm.o /sdl_mixer/external/flac/src/libFLAC/ia32/cpu_asm.nasm
/sdl_mixer/external/flac/src/libFLAC/ia32/cpu_asm.nasm:38: error: (cglobal:4) undefined symbol `__NASM_MAJOR__' in preprocessor
/sdl_mixer/external/flac/src/libFLAC/ia32/cpu_asm.nasm:39: error: (cglobal:4) undefined symbol `__NASM_MAJOR__' in preprocessor

Weird.

When configuring the project with -DWITH_ASM=OFF, I was able to build SDL_mixer successfully for all 4 Android platforms.

@genpfault Can you try building the project with flac enabled, and with -DWITH_ASM=OFF? I tested this by building sdl_mixer from console, not using gradle. But that shouldn't matter. :crossed_fingers:

If it doesn't work, can you please post a complete cmake build log?

sezero commented 1 year ago

Why is it using yasm instead of nasm itself?

madebr commented 1 year ago

android.toolchain.cmake contains:

if(ANDROID_ABI STREQUAL "x86" OR ANDROID_ABI STREQUAL "x86_64")
  set(CMAKE_ASM_NASM_COMPILER
    "${ANDROID_TOOLCHAIN_ROOT}/bin/yasm${ANDROID_TOOLCHAIN_SUFFIX}")
  set(CMAKE_ASM_NASM_COMPILER_ARG1 "-DELF")
endif()
sezero commented 1 year ago

android.toolchain.cmake contains:

Huh.. And that thing comes with the toolchain? Then, for flac, we should add a check for nasm being nasm.

Or, we can report this to flac mainstream, although they intend to remove asm code, not sure how soon.

madebr commented 1 year ago

android.toolchain.cmake contains:

Huh.. And that thing comes with the toolchain? Then, for flac, we should add a check for nasm being nasm.

Yes, I'm using an (older) 21.4.7075529 though, for compatibility with later ndk releases.

Or, we can report this to flac mainstream, although they intend to remove asm code, not sure how soon.

Reporting upstream would not hurt. If they already intend to remove asm code, then this might accelerate that decision.

sezero commented 1 year ago

Reported asm build issue to mainstream at https://github.com/xiph/flac/issues/475

sezero commented 1 year ago

Getting rid of -mstackrealign

Is that -mstackrealign issue there if we upgrade our embedded flac to v1.4.1?

madebr commented 1 year ago

Just bumped to 1.4.1, and they got rid of -mstackrealign in a similar way as I did. The __NASM_MAJOR__ preprocessor error remains.

sezero commented 1 year ago

Just bumped to 1.4.1, and they got rid of -mstackrealign in a similar way as I did. The __NASM_MAJOR__ preprocessor error remains.

Then let's upgrade officially in SDL_mixer main branch if there are no complications.

genpfault commented 1 year ago

Is this with the last release or the latest from GitHub?

It was with the (then-)latest from Github, db9da3d416077195a2f84403b2fb40955518b4ab

genpfault commented 1 year ago

@madebr:

Can you try building the project with flac enabled, and with -DWITH_ASM=OFF?

With a set( WITH_ASM OFF CACHE BOOL "" FORCE ) before the add_subdirectory( external/sdl-mixer ) and today's main (58497bdb6ae7dee132bc538072ea3ce12a6e7c50) it still can't find libFLAC.so.

Not sure how to convince Gradle to cough up CMake configure output; grepping around in .cxx/Debug/<...>/arm64-v8a/ didn't turn up anything useful.

Best I'm seeing is the confiugreCMakeDebug task output:

> Task :configureCMakeDebug
C/C++: debug|arm64-v8a :CMake Warning (dev) at external/sdl-mixer/external/ogg/CMakeLists.txt:2 (project):
C/C++: debug|arm64-v8a :  Policy CMP0048 is not set: project() command manages VERSION variables.
C/C++: debug|arm64-v8a :  Run "cmake --help-policy CMP0048" for policy details.  Use the cmake_policy
C/C++: debug|arm64-v8a :  command to set the policy and suppress this warning.
C/C++: debug|arm64-v8a :  The following variable(s) would be set to empty:
C/C++: debug|arm64-v8a :    PROJECT_VERSION
C/C++: debug|arm64-v8a :    PROJECT_VERSION_MAJOR
C/C++: debug|arm64-v8a :    PROJECT_VERSION_MINOR
C/C++: debug|arm64-v8a :    PROJECT_VERSION_PATCH
C/C++: debug|arm64-v8a :This warning is for project developers.  Use -Wno-dev to suppress it.
C/C++: debug|arm64-v8a :-- Check for working linker: /android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld
C/C++: debug|arm64-v8a :CMake Warning (dev) at external/sdl-mixer/external/libxmp/CMakeLists.txt:25 (option):
C/C++: debug|arm64-v8a :  Policy CMP0077 is not set: option() honors normal variables.  Run "cmake
C/C++: debug|arm64-v8a :  --help-policy CMP0077" for policy details.  Use the cmake_policy command to
C/C++: debug|arm64-v8a :  set the policy and suppress this warning.
C/C++: debug|arm64-v8a :  For compatibility with older versions of CMake, option is clearing the
C/C++: debug|arm64-v8a :  normal variable 'BUILD_STATIC'.
C/C++: debug|arm64-v8a :This warning is for project developers.  Use -Wno-dev to suppress it.
C/C++: debug|arm64-v8a :CMake Warning (dev) at external/sdl-mixer/external/libxmp/CMakeLists.txt:26 (option):
C/C++: debug|arm64-v8a :  Policy CMP0077 is not set: option() honors normal variables.  Run "cmake
C/C++: debug|arm64-v8a :  --help-policy CMP0077" for policy details.  Use the cmake_policy command to
C/C++: debug|arm64-v8a :  set the policy and suppress this warning.
C/C++: debug|arm64-v8a :  For compatibility with older versions of CMake, option is clearing the
C/C++: debug|arm64-v8a :  normal variable 'BUILD_SHARED'.
C/C++: debug|arm64-v8a :This warning is for project developers.  Use -Wno-dev to suppress it.
C/C++: debug|arm64-v8a :CMake Warning:
C/C++: debug|arm64-v8a :  Manually-specified variables were not used by the project:
C/C++: debug|arm64-v8a :    ANDROID_APP_PLATFORM
genpfault commented 1 year ago

Setting SDL2MIXER_DEPS_SHARED=OFF lets the build complete though, even without WITH_ASM=OFF.

madebr commented 1 year ago

I can't reproduce this with (latest?) Android Studio 2021.3.1. I pushed some commits to reduce the number of unneeded libraries/executables being built, and also avoid libFLAC++.so being added to the .apk.

I tested this with re-using the android project of SDL, changing the c++ stl to c++_shared and making sure a cmake project is being built.

Setting SDL2MIXER_DEPS_SHARED=OFF lets the build complete though, even without WITH_ASM=OFF.

I also didn't see any issues with WITH_ASM when building with android studio. I noticed my Android Studio uses the legacy cmake toolchain. Not sure why that is.

The main difference between SDL2MIXER_DEPS_SHARED enabled or disabled is that the dependencies are dynamically loaded (at run time) instead of dynamically linked (at build time). In the CMake script, there is only a build dependency when it is enabled. I can only theorize your toolchain does not pick these up.

About the logs, these are written as .txt files in a build and .cxx folder. As reference, here are my logs. The zip is the result of running the following command inside the app directory:

find . -iname "*.txt" -exec zip logs.zip {} +

While trying out things, I also occasionally removed the .cxx and build directories to make sure nothing was cached. Android Studio will then rebuild everything.

genpfault commented 1 year ago

bug-457.zip contains the Git repo I've been testing on, with submodules for SDL & SDL_mixer and an adaptation of the SDL Android build guide in android/.

Repro steps:

unzip bug-457.zip
cd bug-457
git reset --hard HEAD
git submodule update --init --recursive
cd android
./gradlew build

Trimmed output:

$ ./gradlew build
Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>

> Task :configureCMakeDebug
C/C++: debug|arm64-v8a :CMake Warning (dev) at external/sdl-mixer/external/ogg/CMakeLists.txt:2 (project):
C/C++: debug|arm64-v8a :  Policy CMP0048 is not set: project() command manages VERSION variables.
C/C++: debug|arm64-v8a :  Run "cmake --help-policy CMP0048" for policy details.  Use the cmake_policy
C/C++: debug|arm64-v8a :  command to set the policy and suppress this warning.
C/C++: debug|arm64-v8a :  The following variable(s) would be set to empty:
C/C++: debug|arm64-v8a :    PROJECT_VERSION
C/C++: debug|arm64-v8a :    PROJECT_VERSION_MAJOR
C/C++: debug|arm64-v8a :    PROJECT_VERSION_MINOR
C/C++: debug|arm64-v8a :    PROJECT_VERSION_PATCH
C/C++: debug|arm64-v8a :This warning is for project developers.  Use -Wno-dev to suppress it.
C/C++: debug|arm64-v8a :-- Check for working linker: /home/genpfault/Workspace/android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld
C/C++: debug|arm64-v8a :CMake Warning (dev) at external/sdl-mixer/external/libxmp/CMakeLists.txt:25 (option):
C/C++: debug|arm64-v8a :  Policy CMP0077 is not set: option() honors normal variables.  Run "cmake
C/C++: debug|arm64-v8a :  --help-policy CMP0077" for policy details.  Use the cmake_policy command to
C/C++: debug|arm64-v8a :  set the policy and suppress this warning.
C/C++: debug|arm64-v8a :  For compatibility with older versions of CMake, option is clearing the
C/C++: debug|arm64-v8a :  normal variable 'BUILD_STATIC'.
C/C++: debug|arm64-v8a :This warning is for project developers.  Use -Wno-dev to suppress it.
C/C++: debug|arm64-v8a :CMake Warning (dev) at external/sdl-mixer/external/libxmp/CMakeLists.txt:26 (option):
C/C++: debug|arm64-v8a :  Policy CMP0077 is not set: option() honors normal variables.  Run "cmake
C/C++: debug|arm64-v8a :  --help-policy CMP0077" for policy details.  Use the cmake_policy command to
C/C++: debug|arm64-v8a :  set the policy and suppress this warning.
C/C++: debug|arm64-v8a :  For compatibility with older versions of CMake, option is clearing the
C/C++: debug|arm64-v8a :  normal variable 'BUILD_SHARED'.
C/C++: debug|arm64-v8a :This warning is for project developers.  Use -Wno-dev to suppress it.
C/C++: debug|arm64-v8a :CMake Warning:
C/C++: debug|arm64-v8a :  Manually-specified variables were not used by the project:
C/C++: debug|arm64-v8a :    ANDROID_APP_PLATFORM

> Task :buildCMakeDebug
C/C++: ninja: Entering directory `/tmp/bug-457/android/.cxx/Debug/3l3k51t6/arm64-v8a'
C/C++: clang: warning: argument unused during compilation: '-marm' [-Wunused-command-line-argument]
C/C++: clang: warning: argument unused during compilation: '-marm' [-Wunused-command-line-argument]
C/C++: ../../../../../external/sdl-mixer/external/libxmp/src/depackers/depacker.c:144:12: warning: unused function 'execute_command' [-Wunused-function]

> Task :buildCMakeDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':buildCMakeDebug'.
> Expected output file at /tmp/bug-457/android/build/intermediates/cxx/Debug/3l3k51t6/obj/arm64-v8a/libFLAC.so for target FLAC but there was none
...

logs.zip: Output from find . -iname "*.txt" -exec zip logs.zip {} + from inside android/ after the above repro steps fail on my end.

No Android Studio on my end, installed the command-line tools + whatever other Android SDK/NDK parts Gradle automagically installed via sdkmanager.

madebr commented 1 year ago

Thanks. I can reproduce in a docker container. It's really weird. Running gradle build --info shows the build command that is used.

$ ./gradlew build --info
...
Starting process 'command '/opt/android/cmake/3.18.1/bin/ninja''. Working directory: /src/android Command: /opt/android/cmake/3.18.1/bin/ninja -C /src/android/.cxx/Debug/2my5f214/arm64-v8a FLAC SDL2 benchmark_residual main xmp_shared
...
Execution failed for task ':buildCMakeDebug'.
...
$ find . -iname "*.so"
./build/intermediates/cxx/Debug/2my5f214/obj/arm64-v8a/libmain.so
./build/intermediates/cxx/Debug/2my5f214/obj/arm64-v8a/libSDL2.so
./build/intermediates/cxx/Debug/2my5f214/obj/arm64-v8a/libxmp.so

Let's try running the build command manually:

$ /opt/android/cmake/3.18.1/bin/ninja -C /src/android/.cxx/Debug/2my5f214/arm64-v8a FLAC SDL2 benchmark_residual main xmp_shared
$ find . -iname "*.so"
./build/intermediates/cxx/Debug/2my5f214/obj/arm64-v8a/libFLAC.so
./build/intermediates/cxx/Debug/2my5f214/obj/arm64-v8a/libmain.so
./build/intermediates/cxx/Debug/2my5f214/obj/arm64-v8a/libSDL2.so
./build/intermediates/cxx/Debug/2my5f214/obj/arm64-v8a/libxmp.so

Now libFLAC.so is there. But running ./gradlew build will remove it again.

So it looks like something is removing libFLAC.so, and I have no idea who/why. The logs don't show this.

I've created these build logs, but they don't contain anything useful (or so I think): https://scans.gradle.com/s/wtlvlp6fu2wjy https://scans.gradle.com/s/ttmmdd5waiiwy

genpfault commented 1 year ago

Dropping back to CMake 3.10.2 at the project level and in SDL_mixer seems to fix it.

Unfortunately external/flac needs modification:

/tmp/bug-457/external/sdl-mixer/external/flac$ git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5cac6be1..9bcb1076 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -93,7 +93,7 @@ add_compile_options(
     $<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_DECL_AFTER_STMT_FLAG}>>:-Wdeclaration-after-statement>)

 if(HAVE_STACK_PROTECTOR_FLAG)
-    add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-fstack-protector-strong>)
+    add_compile_options(-fstack-protector-strong)
 endif()

 if(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND HAVE_STACKREALIGN_FLAG)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index bde3647b..1abab494 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.11)
+cmake_minimum_required(VERSION 3.10.2)

 option(ENABLE_64_BIT_WORDS "Set FLAC__BYTES_PER_WORD to 8 (4 is the default)" OFF)
 option(WITH_XMMS "Build XMMS plugin" OFF)
diff --git a/src/share/utf8/CMakeLists.txt b/src/share/utf8/CMakeLists.txt
index 389b09e2..12a082a6 100644
--- a/src/share/utf8/CMakeLists.txt
+++ b/src/share/utf8/CMakeLists.txt
@@ -1,8 +1,12 @@
-cmake_minimum_required(VERSION 3.12)
+cmake_minimum_required(VERSION 3.10.2)

 add_library(utf8 STATIC
     charset.c
     iconvert.c
     utf8.c)

-target_link_libraries(utf8 PUBLIC grabbag $<TARGET_NAME_IF_EXISTS:Iconv::Iconv>)
+if(TARGET Iconv::Iconv)
+    target_link_libraries(utf8 PUBLIC grabbag Iconv::Iconv)
+else()
+    target_link_libraries(utf8 PUBLIC grabbag)
+endif()
madebr commented 1 year ago

I bumped the CMake version to 3.22.1 and could make the build succeed without any issue. Peeking into the .apk, it does contain libFLAC.so, libmain.so, libSDL2.so and libxmp.so. So I think you need to add the following to your cmake script.

set(SDL_SHARED OFF CACHE BOOL "" FORCE)
genpfault commented 1 year ago

Sadly CMake 3.22.1 doesn't seem to exist in the Gradle/Android magic binaries list, just 3.10.2 and 3.18.1:

/tmp/bug-457/android$ ./gradlew build

> Configure project :
[CXX1300] CMake '3.22.1' was not found in SDK, PATH, or by cmake.dir property.
[CXX1301] - CMake '3.18.4' found in PATH did not satisfy requested version.
[CXX1301] - CMake '3.10.2' found in SDK did not satisfy requested version.
[CXX1301] - CMake '3.18.1' found in SDK did not satisfy requested version.
[CXX1300] CMake '3.22.1' was not found in SDK, PATH, or by cmake.dir property.
[CXX1301] - CMake '3.18.4' found in PATH did not satisfy requested version.
[CXX1301] - CMake '3.10.2' found in SDK did not satisfy requested version.
[CXX1301] - CMake '3.18.1' found in SDK did not satisfy requested version.

...

Though I can confirm that manually downloading the CMake 3.22.1 binaries & putting them in the PATH does fix it on my end. SDL_SHARED=OFF doesn't seem to be needed.

madebr commented 1 year ago

I installed it through the sdk manager: sdkmanager --install "cmake;3.22.1"

No, SDL_SHARED=OFF is not needed indeed. I mentioned it because you link to a static SDL, so libSDL2.so is not needed. Perhaps this happened because you do:

add_subdirectory(external/sdl)

instead of

add_subdirectory(external/sdl EXCLUDE_FROM_ALL)

But I haven't tested this.

genpfault commented 1 year ago

I'll go with sdkmanager --install "cmake;3.22.1" then, thank you for all your patience and help!