Skip to content

Commit 219f610

Browse files
author
Marc-André Moreau
committed
Android build fixes
1 parent c9f78b2 commit 219f610

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

CMakeLists.txt

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ option(BUILD_MANPAGES "Build man pages" ON)
3737
option(BUILD_SHARED_LIBS "Build a shared library" ON)
3838
option(BUILD_STATIC_LIBS "Build a static library" ON)
3939
option(BUILD_TOOLS "Build tool programs" ON)
40+
option(BUILD_TESTS "Build test programs" OFF)
4041
option(FUZZ "Enable fuzzing instrumentation" OFF)
4142
option(LIBFUZZER "Build libfuzzer harnesses" OFF)
4243
option(USE_HIDAPI "Use hidapi as the HID backend" OFF)
@@ -70,6 +71,9 @@ if(NOT MSVC)
7071
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
7172
set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_GNU_SOURCE")
7273
set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_DEFAULT_SOURCE")
74+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
75+
set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_GNU_SOURCE")
76+
set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_DEFAULT_SOURCE")
7377
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
7478
CMAKE_SYSTEM_NAME STREQUAL "MidnightBSD")
7579
set(FIDO_CFLAGS "${FIDO_CFLAGS} -D__BSD_VISIBLE=1")
@@ -110,6 +114,11 @@ check_symbol_exists(sysconf unistd.h HAVE_SYSCONF)
110114
check_symbol_exists(timespecsub sys/time.h HAVE_TIMESPECSUB)
111115
check_symbol_exists(timingsafe_bcmp string.h HAVE_TIMINGSAFE_BCMP)
112116

117+
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
118+
set(HAVE_EXPLICIT_BZERO OFF)
119+
add_definitions(-DCRYPTO_EXPLICIT_BZERO)
120+
endif()
121+
113122
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
114123
try_compile(HAVE_POSIX_IOCTL
115124
"${CMAKE_CURRENT_BINARY_DIR}/posix_ioctl_check.o"
@@ -212,6 +221,7 @@ else()
212221
message(FATAL_ERROR "could not find zlib")
213222
endif()
214223

224+
set(ZLIB_LIBRARIES "zlib")
215225
set(CBOR_LIBRARIES "cbor")
216226
set(CRYPTO_LIBRARIES "crypto")
217227

@@ -229,6 +239,23 @@ else()
229239
set(BASE_LIBRARIES ${BASE_LIBRARIES} rt)
230240
endif()
231241
endif()
242+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
243+
if(UDEV_ROOT_DIR)
244+
list(PREPEND CMAKE_FIND_ROOT_PATH ${UDEV_ROOT_DIR})
245+
endif()
246+
247+
find_path(UDEV_INCLUDE_DIR
248+
NAMES "libudev.h")
249+
250+
find_library(UDEV_LIBRARY
251+
NAMES libudev-zero.a libudev)
252+
253+
add_library(udev STATIC IMPORTED GLOBAL)
254+
set_target_properties(udev PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${UDEV_INCLUDE_DIR}")
255+
set_target_properties(udev PROPERTIES IMPORTED_LOCATION "${UDEV_LIBRARY}")
256+
257+
set(UDEV_INCLUDE_DIRS "${UDEV_INCLUDE_DIR}")
258+
set(UDEV_LIBRARIES "udev")
232259
else()
233260
set(NFC_LINUX OFF)
234261
endif()
@@ -436,10 +463,13 @@ else()
436463
message(FATAL_ERROR "Nothing to build (BUILD_*_LIBS=OFF)")
437464
endif()
438465

439-
enable_testing()
440-
441466
subdirs(src)
442-
subdirs(regress)
467+
468+
if(BUILD_TESTS)
469+
enable_testing()
470+
subdirs(regress)
471+
endif()
472+
443473
if(BUILD_EXAMPLES)
444474
subdirs(examples)
445475
endif()

openbsd-compat/explicit_bzero.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "openbsd-compat.h"
99

10-
#if !defined(HAVE_EXPLICIT_BZERO) && !defined(_WIN32)
10+
#if !defined(HAVE_EXPLICIT_BZERO) && !defined(_WIN32) && !defined(CRYPTO_EXPLICIT_BZERO)
1111

1212
#include <string.h>
1313

openbsd-compat/openbsd-compat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ char *strsep(char **, const char *);
6262
void *recallocarray(void *, size_t, size_t, size_t);
6363
#endif
6464

65-
#if !defined(HAVE_EXPLICIT_BZERO)
65+
#if !defined(HAVE_EXPLICIT_BZERO) || defined(CRYPTO_EXPLICIT_BZERO)
6666
void explicit_bzero(void *, size_t);
6767
#endif
6868

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ elseif(APPLE)
7171
list(APPEND FIDO_SOURCES hid_osx.c)
7272
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
7373
list(APPEND FIDO_SOURCES hid_linux.c hid_unix.c)
74+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
75+
list(APPEND FIDO_SOURCES hid_linux.c hid_unix.c)
7476
elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
7577
list(APPEND FIDO_SOURCES hid_netbsd.c hid_unix.c)
7678
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")

0 commit comments

Comments
 (0)