Android Studio, CMake issues

I’m trying to build SDL2 project with using of CMake. But I’ve got errors:

CMake Error: install(EXPORT “SDL2Targets” …) includes target “SDL2-static” which requires target “cpufeatures” that is not in the export set.
CMake Error: install(EXPORT “SDL2Targets” …) includes target “SDL2” which requires target “cpufeatures” that is not in the export set.

My root CMakeLists.txt looks like:

========================================
include(AndroidNdkModules)
android_ndk_import_module_cpufeatures()

list(APPEND EXTRA_LIBS cpufeatures)

add_subdirectory(SDL)
add_subdirectory(main)

========================================

if I remove “list(APPEND EXTRA_LIBS cpufeatures)” everything is find but I will get linker errors:

SDL_cpuinfo.c:471: error: undefined reference to ‘android_getCpuFamily’
SDL_cpuinfo.c:473: error: undefined reference to ‘android_getCpuFeatures’

Is anybody knows how to fix it?

And if I make simple test project with the same structure and add “cpufeatures” as a dependency every thing builds find.

1 Like

Hi! Do you have any solution to cpufeatures link errors?

No I made build under armv8 only

I have the same error, I tried both NDK 21.1.6352462 and 21.3.6528147 when using cmake. I don’t see AndroidNdkModules.cmake in my build/cmake directory, which should add:

    macro(android_ndk_import_module_cpufeatures)
        if(ANDROID)
            include_directories(${ANDROID_NDK}/sources/android/cpufeatures)
            add_library(cpufeatures ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
            target_link_libraries(cpufeatures dl)
        endif()
    endmacro()

Instead I solved by adding

    add_library(cpufeatures STATIC ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
    target_include_directories(cpufeatures PUBLIC ${ANDROID_NDK}/sources/android/cpufeatures)
    target_link_libraries(cpufeatures dl)
    install(TARGETS cpufeatures EXPORT SDL2Targets)
    install(FILES ${ANDROID_NDK}/sources/android/cpufeatures/cpufeatures.h DESTINATION include)
    list(APPEND EXTRA_LIBS cpufeatures)

after line 1004 add_definitions(-DGL_GLEXT_PROTOTYPES) in the ANDROID stuff of the SDL2 CMakeLists.txt