aboutsummaryrefslogtreecommitdiffstats
diff options
authorUrs Fleisch <ufleisch@users.sourceforge.net>2025-05-01 19:55:46 +0200
committerGitHub <noreply@github.com>2025-05-01 19:55:46 +0200
commitfbbead3efd98b4f0fa71a194ecbffb99bca3fe6f (patch)
treeef4f41aab545d6f92765668b84b4642112465bdb
parentee1931b81116cd0091c906896f6f4fb74850be51 (diff)
Support custom temp and tests directories (#1268) (#1270)HEADupstream/master
The following user-settable values for CMake are supported: - TESTS_DIR: Tests directory, is path to unit test data when 'data' is appended. Can be used to run the unit tests on a target. - TESTS_TMPDIR: Directory for temporary files created during unit tests, system tmpdir is used if undefined. Has to be defined on systems without global temporary directory.
-rw-r--r--CMakeLists.txt5
-rw-r--r--INSTALL.md54
-rw-r--r--config.h.cmake1
-rw-r--r--tests/utils.h6
4 files changed, 63 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 81317304..00487bfb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,7 +48,10 @@ set(TAGLIB_INSTALL_SUFFIX "" CACHE STRING
"Suffix added to installed files (include directory, libraries, .pc)")
add_definitions(-DHAVE_CONFIG_H)
-set(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/")
+set(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/" CACHE STRING
+ "Tests directory, is path to unit test data when 'data' is appended")
+set(TESTS_TMPDIR "" CACHE STRING
+ "Directory for temporary files created during unit tests, system tmpdir is used if undefined")
if(CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
diff --git a/INSTALL.md b/INSTALL.md
index 77c9d7a9..beb4bf43 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -42,6 +42,9 @@ CMakeLists.txt file.
| `TAGLIB_INSTALL_SUFFIX` | Suffix added to installed libraries, includes, ... |
| `ENABLE_STATIC_RUNTIME` | Link with MSVC runtime statically |
| `BUILD_FRAMEWORK` | Build a macOS framework |
+| `TESTS_DIR` | Where to find unit test data (with data appended) |
+| `TESTS_TMPDIR` | Where to create temporary files in unit tests |
+
If you want to install TagLib 2 alongside TagLib 1, you can use
`-DTAGLIB_INSTALL_SUFFIX=-2` and make sure that `BUILD_EXAMPLES` is not `ON`
@@ -462,3 +465,54 @@ cmake --build build_mingw --config Release
PATH=$PATH:$TAGLIB_PREFIX/bin
build_mingw/tagreader /path/to/audio-file
```
+
+## Android
+
+### Using vcpkg
+
+The bash script below can be used to build TagLib for Android using vcpkg.
+It must be started in the parent folder of the taglib source folder and will
+build in a folder _android_build_ and install into _android_pkg_.
+The package and the unit tests are then transferred to an Android device
+and the unit tests are run on the device.
+
+Note that `TESTS_TMPDIR` is set because there is no system-wide temporary folder
+on Android. `TESTS_DIR` is set to run the tests on the target.
+
+```
+# You may have to adapt the NDK and vcpkg paths and the ABI/triplet.
+
+export ANDROID_NDK_HOME=$HOME/Development/android-sdk/ndk/23.1.7779620
+export VCPKG_ROOT=$HOME/Development/vcpkg
+PATH=$PATH:$VCPKG_ROOT
+
+# armeabi-v7a/arm-android or arm64-v8a/arm64-android or x86/x86-android or x86_64/x64-android
+android_abi=armeabi-v7a
+vcpkg_target_triplet=arm-android
+
+vcpkg_toolchain_file=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
+android_toolchain_file=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake
+
+vcpkg install --triplet $vcpkg_target_triplet utfcpp zlib cppunit
+
+cmake -B android_build -S taglib \
+ -DCMAKE_TOOLCHAIN_FILE=$vcpkg_toolchain_file \
+ -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=$android_toolchain_file \
+ -DVCPKG_TARGET_TRIPLET=$vcpkg_target_triplet \
+ -DANDROID_ABI=$android_abi \
+ -GNinja -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release \
+ -DVISIBILITY_HIDDEN=ON -DENABLE_CCACHE=ON -DBUILD_EXAMPLES=ON -DBUILD_TESTING=ON \
+ -DTESTS_DIR=/data/local/tmp/tests/ -DTESTS_TMPDIR=/data/local/tmp
+cmake --build android_build --config Release
+cmake --install android_build --config Release --prefix android_pkg --strip
+cp -a android_build/tests/test_runner android_pkg/bin/
+
+if hash adb 2>/dev/null; then
+ adb push android_pkg /data/local/tmp/
+ adb push android_build/tests/test_runner /data/local/tmp/tests/test_runner
+ adb push taglib/tests/data /data/local/tmp/tests/
+ adb shell "env LD_LIBRARY_PATH=/data/local/tmp/android_pkg/lib /data/local/tmp/tests/test_runner"
+ # You could also try an example binary:
+ # adb shell "env LD_LIBRARY_PATH=/data/local/tmp/android_pkg/lib /data/local/tmp/android_pkg/bin/tagreader '/sdcard/Music/Some Album/A Track.mp3'"
+fi
+```
diff --git a/config.h.cmake b/config.h.cmake
index 67334d79..9860b38e 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -20,5 +20,6 @@
#cmakedefine TRACE_IN_RELEASE 1
#cmakedefine TESTS_DIR "@TESTS_DIR@"
+#cmakedefine TESTS_TMPDIR "@TESTS_TMPDIR@"
#endif
diff --git a/tests/utils.h b/tests/utils.h
index ee2ec03a..ba4c721e 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -54,12 +54,14 @@ inline string copyFile(const string &filename, const string &ext)
{
char testFileName[1024];
-#ifdef _WIN32
+#ifdef TESTS_TMPDIR
+ snprintf(testFileName, sizeof(testFileName), "%s/taglib-test%s", TESTS_TMPDIR, ext.c_str());
+#elif defined _WIN32
char tempDir[MAX_PATH + 1];
GetTempPathA(sizeof(tempDir), tempDir);
wsprintfA(testFileName, "%s\\taglib-test%s", tempDir, ext.c_str());
#else
- snprintf(testFileName, sizeof(testFileName), "/%s/taglib-test%s", P_tmpdir, ext.c_str());
+ snprintf(testFileName, sizeof(testFileName), "%s/taglib-test%s", P_tmpdir, ext.c_str());
#endif
string sourceFileName = testFilePath(filename) + ext;