Skip to content

Commit

Permalink
Android build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-André Moreau committed Apr 27, 2022
1 parent c9f78b2 commit f49b254
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
35 changes: 32 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ option(BUILD_MANPAGES "Build man pages" ON)
option(BUILD_SHARED_LIBS "Build a shared library" ON)
option(BUILD_STATIC_LIBS "Build a static library" ON)
option(BUILD_TOOLS "Build tool programs" ON)
option(BUILD_TESTS "Build test programs" ON)
option(FUZZ "Enable fuzzing instrumentation" OFF)
option(LIBFUZZER "Build libfuzzer harnesses" OFF)
option(USE_HIDAPI "Use hidapi as the HID backend" OFF)
Expand Down Expand Up @@ -70,6 +71,9 @@ if(NOT MSVC)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_GNU_SOURCE")
set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_DEFAULT_SOURCE")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_GNU_SOURCE")
set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_DEFAULT_SOURCE")
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
CMAKE_SYSTEM_NAME STREQUAL "MidnightBSD")
set(FIDO_CFLAGS "${FIDO_CFLAGS} -D__BSD_VISIBLE=1")
Expand Down Expand Up @@ -110,6 +114,11 @@ check_symbol_exists(sysconf unistd.h HAVE_SYSCONF)
check_symbol_exists(timespecsub sys/time.h HAVE_TIMESPECSUB)
check_symbol_exists(timingsafe_bcmp string.h HAVE_TIMINGSAFE_BCMP)

if(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(HAVE_EXPLICIT_BZERO OFF)
add_definitions(-DCRYPTO_EXPLICIT_BZERO)
endif()

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
try_compile(HAVE_POSIX_IOCTL
"${CMAKE_CURRENT_BINARY_DIR}/posix_ioctl_check.o"
Expand Down Expand Up @@ -229,6 +238,23 @@ else()
set(BASE_LIBRARIES ${BASE_LIBRARIES} rt)
endif()
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
if(UDEV_ROOT_DIR)
list(PREPEND CMAKE_FIND_ROOT_PATH ${UDEV_ROOT_DIR})
endif()

find_path(UDEV_INCLUDE_DIR
NAMES "libudev.h")

find_library(UDEV_LIBRARY
NAMES libudev-zero.a libudev)

add_library(udev STATIC IMPORTED GLOBAL)
set_target_properties(udev PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${UDEV_INCLUDE_DIR}")
set_target_properties(udev PROPERTIES IMPORTED_LOCATION "${UDEV_LIBRARY}")

set(UDEV_INCLUDE_DIRS "${UDEV_INCLUDE_DIR}")
set(UDEV_LIBRARIES "udev")
else()
set(NFC_LINUX OFF)
endif()
Expand Down Expand Up @@ -436,10 +462,13 @@ else()
message(FATAL_ERROR "Nothing to build (BUILD_*_LIBS=OFF)")
endif()

enable_testing()

subdirs(src)
subdirs(regress)

if(BUILD_TESTS)
enable_testing()
subdirs(regress)
endif()

if(BUILD_EXAMPLES)
subdirs(examples)
endif()
Expand Down
2 changes: 1 addition & 1 deletion openbsd-compat/explicit_bzero.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "openbsd-compat.h"

#if !defined(HAVE_EXPLICIT_BZERO) && !defined(_WIN32)
#if !defined(HAVE_EXPLICIT_BZERO) && !defined(_WIN32) && !defined(CRYPTO_EXPLICIT_BZERO)

#include <string.h>

Expand Down
2 changes: 1 addition & 1 deletion openbsd-compat/openbsd-compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ char *strsep(char **, const char *);
void *recallocarray(void *, size_t, size_t, size_t);
#endif

#if !defined(HAVE_EXPLICIT_BZERO)
#if !defined(HAVE_EXPLICIT_BZERO) || defined(CRYPTO_EXPLICIT_BZERO)
void explicit_bzero(void *, size_t);
#endif

Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ elseif(APPLE)
list(APPEND FIDO_SOURCES hid_osx.c)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND FIDO_SOURCES hid_linux.c hid_unix.c)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
list(APPEND FIDO_SOURCES hid_linux.c hid_unix.c)
elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
list(APPEND FIDO_SOURCES hid_netbsd.c hid_unix.c)
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
Expand Down

0 comments on commit f49b254

Please sign in to comment.