Skip to content

Conversation

@jackluo923
Copy link

@jackluo923 jackluo923 commented Jul 22, 2025

Description

When building Zstd v1.5.7 for the Android platform using CMake, the following error occurs during configuration:

CMake Error at CMakeLists.txt:95 (if):
  if given arguments:

    "(" "NOT" ")" "OR" "VERSION_LESS" "24"

  Unknown arguments specified

This regression was introduced in 49fe2ec (refactor: modularize CMakeLists.txt for better maintainability). The problematic conditional logic is:

if((NOT ANDROID_PLATFORM_LEVEL) OR (ANDROID_PLATFORM_LEVEL VERSION_LESS 24))
    message(STATUS "Configuring for old Android API - disabling fseeko/ftello")
    add_compile_definitions(LIBC_NO_FSEEKO)
endif()

CMake is picky about parentheses for logical grouping inside if() statements. This leads to a parsing failure on valid Android configurations.

Fix

The parentheses surrounding the version check is removed to comply with CMake syntax rules.

if(NOT ANDROID_PLATFORM_LEVEL OR ANDROID_PLATFORM_LEVEL VERSION_LESS 24)
    message(STATUS "Configuring for old Android API - disabling fseeko/ftello")
    add_compile_definitions(LIBC_NO_FSEEKO)
endif()

Validation

Manually triggered a successful cross-compiled build with Android NDK26.

set(ZSTD_MULTITHREAD_SUPPORT_DEFAULT OFF)
# Handle old Android API levels
if((NOT ANDROID_PLATFORM_LEVEL) OR (ANDROID_PLATFORM_LEVEL VERSION_LESS 24))
if((NOT ANDROID_PLATFORM_LEVEL) OR ANDROID_PLATFORM_LEVEL VERSION_LESS 24)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the patch removes one parenthesis level,
and now it works better for cmake ?

Copy link
Author

@jackluo923 jackluo923 Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Removing the pair of parenthesis makes cmake happy.

Here's an explanation provided by ChatGPT: https://poe.com/s/6bcOKmapQY5A2mpfW5sc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting ...

@Cyan4973
Copy link
Contributor

Probably a parallel concern to this PR,
I wonder if we could have some kind of cross-compilation job to Android in our CI.
This might help catch such issues as they creep up, rather than waiting for user feedback.

@jackluo923
Copy link
Author

Probably a parallel concern to this PR, I wonder if we could have some kind of cross-compilation job to Android in our CI. This might help catch such issues as they creep up, rather than waiting for user feedback.

This repo already appears to support Android cross-compilation through this workflow, albeit by directly invoking the make command rather than using cmake. Extending the current workflow to cover more build paths should be sufficient.

Cyan4973 added a commit that referenced this pull request Jul 23, 2025
is expecte to fail, due to #4444
@Cyan4973
Copy link
Contributor

I just tried to add a cmake build test to the Android workflow,
it doesn't use this patch (yet) so it's supposed to fail.
Yet, it succeeded :
https://github.com/facebook/zstd/actions/runs/16482663518/job/46600650990?pr=4447#step:7:208

Is there anything different in this test, compared to yours ?
cmake version maybe ?

Cyan4973 added a commit that referenced this pull request Jul 23, 2025
is expecte to fail, due to #4444
@jackluo923
Copy link
Author

I just tried to add a cmake build test to the Android workflow, it doesn't use this patch (yet) so it's supposed to fail. Yet, it succeeded : https://github.com/facebook/zstd/actions/runs/16482663518/job/46600650990?pr=4447#step:7:208

Is there anything different in this test, compared to yours ? cmake version maybe ?

We’re using the default CMake version (v3.22.1) provided by Ubuntu Jammy (22.04 LTS) package manager. Your CI run uses version v3.31.6. I’ll try upgrading and do some experiment.

@jackluo923
Copy link
Author

Here's the output using cmake version 3.31.6 on the v1.5.7 release.

root@d179c4babba7:/tmp/zstd# git branch -a
* (HEAD detached at v1.5.7)

root@d179c4babba7:/tmp/build# cmake --version
cmake version 3.31.6

CMake suite maintained and supported by Kitware (kitware.com/cmake).

root@d179c4babba7:/tmp/build# cmake \
  -DCMAKE_TOOLCHAIN_FILE=$install_prefix/android.toolchain.cmake \
  -DCMAKE_ANDROID_NDK=$install_prefix/android-ndk-r26 \
  -DCMAKE_ANDROID_ARCH_ABI=${ABI} \
  -DCMAKE_ANDROID_API=33 \
  -DCMAKE_ANDROID_STL_TYPE=c++_static \
  -DCMAKE_INSTALL_PREFIX=${install_prefix}/${ABI} \
  -DCMAKE_FIND_ROOT_PATH=${install_prefix}/${ABI} \
  -S /tmp/zstd/build/cmake
-- Android: Targeting API '33' with architecture 'arm64', ABI 'arm64-v8a', and processor 'aarch64'
-- Android: Selected unified Clang toolchain
-- The C compiler identification is Clang 17.0.2
-- The ASM compiler identification is Clang with GNU-like command-line
-- Found assembler: /android/android-ndk-r26/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- The CXX compiler identification is Clang 17.0.2
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /android/android-ndk-r26/toolchains/llvm/prebuilt/linux-x86_64/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /android/android-ndk-r26/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- ZSTD VERSION: 1.5.7
-- Performing Test C_FLAG_WALL
-- Performing Test C_FLAG_WALL - Success
-- Performing Test CXX_FLAG_WALL
-- Performing Test CXX_FLAG_WALL - Success
-- Performing Test C_FLAG_WEXTRA
-- Performing Test C_FLAG_WEXTRA - Success
-- Performing Test CXX_FLAG_WEXTRA
-- Performing Test CXX_FLAG_WEXTRA - Success
-- Performing Test C_FLAG_WUNDEF
-- Performing Test C_FLAG_WUNDEF - Success
-- Performing Test CXX_FLAG_WUNDEF
-- Performing Test CXX_FLAG_WUNDEF - Success
-- Performing Test C_FLAG_WSHADOW
-- Performing Test C_FLAG_WSHADOW - Success
-- Performing Test CXX_FLAG_WSHADOW
-- Performing Test CXX_FLAG_WSHADOW - Success
-- Performing Test C_FLAG_WCAST_ALIGN
-- Performing Test C_FLAG_WCAST_ALIGN - Success
-- Performing Test CXX_FLAG_WCAST_ALIGN
-- Performing Test CXX_FLAG_WCAST_ALIGN - Success
-- Performing Test C_FLAG_WCAST_QUAL
-- Performing Test C_FLAG_WCAST_QUAL - Success
-- Performing Test CXX_FLAG_WCAST_QUAL
-- Performing Test CXX_FLAG_WCAST_QUAL - Success
-- Performing Test C_FLAG_WSTRICT_PROTOTYPES
-- Performing Test C_FLAG_WSTRICT_PROTOTYPES - Success
-- Performing Test LD_FLAG_WL_Z_NOEXECSTACK
-- Performing Test LD_FLAG_WL_Z_NOEXECSTACK - Success
-- Performing Test C_FLAG_QUNUSED_ARGUMENTS
-- Performing Test C_FLAG_QUNUSED_ARGUMENTS - Success
-- Performing Test CXX_FLAG_QUNUSED_ARGUMENTS
-- Performing Test CXX_FLAG_QUNUSED_ARGUMENTS - Success
-- Performing Test C_FLAG_WA_NOEXECSTACK
-- Performing Test C_FLAG_WA_NOEXECSTACK - Success
-- Performing Test CXX_FLAG_WA_NOEXECSTACK
-- Performing Test CXX_FLAG_WA_NOEXECSTACK - Success
-- CMAKE_INSTALL_PREFIX: /android/arm64-v8a
-- CMAKE_INSTALL_LIBDIR: lib
-- ZSTD_LEGACY_SUPPORT defined!
CMake Error at CMakeLists.txt:95 (if):
  if given arguments:

    "(" "NOT" ")" "OR" "VERSION_LESS" "24"

  Unknown arguments specified


-- Configuring incomplete, errors occurred!

Here's the output using cmake version 3.31.6 on the latest dev branch commit.

root@d179c4babba7:/tmp/zstd# git log -1
commit 34f3a0ab1181611903172b50985b3111a30694b6 (HEAD -> dev, origin/dev, orig
in/HEAD)
Merge: 6f1cb87a bd38fc2c
Author: Yann Collet <Cyan4973@users.noreply.github.com>
Date:   Wed Jul 23 15:03:37 2025 -0800

    Merge pull request #4413 from arpadpanyik-arm/huf_decode2x

    AArch64: Enhance struct access in Huffman decode 2X
 
root@d179c4babba7:/tmp/build# cmake --version
cmake version 3.31.6

CMake suite maintained and supported by Kitware (kitware.com/cmake).

root@d179c4babba7:/tmp/build# cmake \
  -DCMAKE_TOOLCHAIN_FILE=$install_prefix/android.toolchain.cmake \
  -DCMAKE_ANDROID_NDK=$install_prefix/android-ndk-r26 \
  -DCMAKE_ANDROID_ARCH_ABI=${ABI} \
  -DCMAKE_ANDROID_API=33 \
  -DCMAKE_ANDROID_STL_TYPE=c++_static \
  -DCMAKE_INSTALL_PREFIX=${install_prefix}/${ABI} \
  -DCMAKE_FIND_ROOT_PATH=${install_prefix}/${ABI} \
  -S /tmp/zstd/build/cmake
-- ZSTD VERSION: 1.5.8
-- Android: Targeting API '33' with architecture 'arm64', ABI 'arm64-v8a', and processor 'aarch64'
-- Android: Selected unified Clang toolchain
-- The C compiler identification is Clang 17.0.2
-- The ASM compiler identification is Clang with GNU-like command-line
-- Found assembler: /android/android-ndk-r26/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /android/android-ndk-r26/toolchains/llvm/prebuilt/linux-x86_64/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- CMAKE_INSTALL_PREFIX: /android/arm64-v8a
-- CMAKE_INSTALL_LIBDIR: lib
-- ZSTD_LEGACY_SUPPORT enabled
-- Configuring for old Android API - disabling fseeko/ftello
-- Multi-threading support disabled
-- Configuring done (0.5s)
-- Generating done (0.0s)
-- Build files have been written to: /tmp/build

This means some how between v1.5.7 and the latest dev branch, the build problem disappeared. I am not sure what the root cause for this yet.

@Cyan4973
Copy link
Contributor

That's weird.
The targeted line in the cmake script hasn't changed between v1.5.7 and dev.

@Cyan4973
Copy link
Contributor

Wait, it did change,

the line used to be :
if ((NOT ${ANDROID_PLATFORM_LEVEL}) OR ${ANDROID_PLATFORM_LEVEL} VERSION_LESS 24)

and now it's this:
if((NOT ANDROID_PLATFORM_LEVEL) OR (ANDROID_PLATFORM_LEVEL VERSION_LESS 24))

That's a small difference, but it was enough to create the problem you observed.

${} forces immediate expansion: If ANDROID_PLATFORM_LEVEL is undefined/empty, ${ANDROID_PLATFORM_LEVEL} becomes an empty string.
And now the lines becomes:
if ((NOT ) OR VERSION_LESS 24)
which matches the error message you shared at the top of this issue.

@jackluo923
Copy link
Author

Wait, it did change,

the line used to be : if ((NOT ${ANDROID_PLATFORM_LEVEL}) OR ${ANDROID_PLATFORM_LEVEL} VERSION_LESS 24)

and now it's this: if((NOT ANDROID_PLATFORM_LEVEL) OR (ANDROID_PLATFORM_LEVEL VERSION_LESS 24))

That's a small difference, but it was enough to create the problem you observed.

${} forces immediate expansion: If ANDROID_PLATFORM_LEVEL is undefined/empty, ${ANDROID_PLATFORM_LEVEL} becomes an empty string. And now the lines becomes: if ((NOT ) OR VERSION_LESS 24) which matches the error message you shared at the top of this issue.

I guess this PR is no longer needed. Do we want to leave the current code as-is or improve it some how?

@Cyan4973
Copy link
Contributor

I think indeed that the current code is fine, and the proposed change doesn't improve it.

@jackluo923 jackluo923 closed this Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants