Fixed bug 4639 - CMake build does not generate libhidapi.so for Android
authorSam Lantinga <slouken@libsdl.org>
Tue, 21 May 2019 17:33:31 -0700
changeset 12747cdf53e16feb7
parent 12746 132a2af7edac
child 12750 455b89ce7384
Fixed bug 4639 - CMake build does not generate libhidapi.so for Android

Manuel Sabogal

I noticed that the current Android.mk builds a libhidapi.so library for Android but the CMake build hasn't been updated to do so. I'll attach a patch that fixes this issue.
CMakeLists.txt
     1.1 --- a/CMakeLists.txt	Sun Apr 28 17:37:49 2019 -0700
     1.2 +++ b/CMakeLists.txt	Tue May 21 17:33:31 2019 -0700
     1.3 @@ -3,7 +3,7 @@
     1.4  endif()
     1.5  
     1.6  cmake_minimum_required(VERSION 2.8.11)
     1.7 -project(SDL2 C)
     1.8 +project(SDL2 C CXX)
     1.9  
    1.10  # !!! FIXME: this should probably do "MACOSX_RPATH ON" as a target property
    1.11  # !!! FIXME:  for the SDL2 shared library (so you get an
    1.12 @@ -914,6 +914,8 @@
    1.13      endif()
    1.14    endif()
    1.15  
    1.16 +  file(GLOB ANDROID_HIDAPI_SOURCES ${SDL2_SOURCE_DIR}/src/hidapi/android/*.cpp)
    1.17 +
    1.18    CheckPTHREAD()
    1.19  
    1.20  endif()
    1.21 @@ -1776,6 +1778,17 @@
    1.22    endif()
    1.23  endif()
    1.24  
    1.25 +if(ANDROID)
    1.26 +  add_library(hidapi SHARED ${ANDROID_HIDAPI_SOURCES})
    1.27 +  if(MSVC AND NOT LIBC)
    1.28 +    # Don't try to link with the default set of libraries.
    1.29 +    set_target_properties(hidapi PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
    1.30 +    set_target_properties(hidapi PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
    1.31 +    set_target_properties(hidapi PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
    1.32 +  endif()
    1.33 +  target_link_libraries(hidapi log)
    1.34 +endif()
    1.35 +
    1.36  if(SDL_STATIC)
    1.37    set (BUILD_SHARED_LIBS FALSE)
    1.38    add_library(SDL2-static STATIC ${SOURCE_FILES})