lib: Compile custom glob() implementation for Android
authorPaul Elder <paul.elder@ideasonboard.com>
Tue, 26 Jun 2018 14:22:25 +0000 (23:22 +0900)
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Tue, 31 Jul 2018 12:56:48 +0000 (15:56 +0300)
The Android C library doesn't provide the glob() function which we use
in the configfs code. Add conditional compilation to cmake such that a
local copy of glob is automatically compiled if glob isn't provided.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
CMakeLists.txt
include/config.h.in [new file with mode: 0644]
include/glob.h [new file with mode: 0644]
lib/CMakeLists.txt
lib/compat/CMakeLists.txt [new file with mode: 0644]

index 79b78c4..29ab2c1 100644 (file)
@@ -4,7 +4,14 @@ set(CMAKE_BUILD_TYPE Release)
 
 #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -Werror")
 
+include_directories(${CMAKE_BINARY_DIR}/generated)
+
 add_subdirectory(lib)
+
+# Generate config.h
+configure_file(${CMAKE_SOURCE_DIR}/include/config.h.in
+              ${CMAKE_BINARY_DIR}/generated/config.h)
+
 add_executable(uvc-gadget main.c)
 target_link_libraries(uvc-gadget uvcgadget)
 install(TARGETS uvc-gadget DESTINATION bin)
diff --git a/include/config.h.in b/include/config.h.in
new file mode 100644 (file)
index 0000000..c968271
--- /dev/null
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#ifndef __UVC_GADGET_CONFIG_H__
+#define __UVC_GADGET_CONFIG_H__
+
+#cmakedefine HAVE_DIRENT_H     @HAVE_DIRENT_H@
+#cmakedefine HAVE_GLOB         @HAVE_GLOB@
+
+#endif
diff --git a/include/glob.h b/include/glob.h
new file mode 100644 (file)
index 0000000..d3ddcff
--- /dev/null
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * glob() compatibility
+ *
+ * Copyright (C) 2018 Laurent Pinchart
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ */
+#ifndef __UVC_GADGET_GLOB_H__
+#define __UVC_GADGET_GLOB_H__
+
+#include "config.h"
+
+#ifdef HAVE_GLOB
+#include_next <glob.h>
+#else
+#include "compat/glob.h"
+#endif
+
+#endif /* __UVC_GADGET_GLOB_H__ */
index ca08fd7..eacfb9c 100644 (file)
@@ -1,6 +1,8 @@
 file(GLOB SOURCES "*.c" "*.h")
 file(GLOB HEADERS "../include/uvcgadget/*.h")
 
+add_subdirectory(compat)
+
 add_library(uvcgadget ${SOURCES})
 
 set_target_properties(uvcgadget PROPERTIES PUBLIC_HEADER "${HEADERS}")
diff --git a/lib/compat/CMakeLists.txt b/lib/compat/CMakeLists.txt
new file mode 100644 (file)
index 0000000..5fd6db4
--- /dev/null
@@ -0,0 +1,12 @@
+include(CheckFunctionExists)
+include(CheckIncludeFile)
+
+check_include_file(dirent.h HAVE_DIRENT_H)
+
+check_function_exists(glob HAVE_GLOB)
+if(NOT HAVE_GLOB)
+       set(SOURCES "${SOURCES}"
+           "${CMAKE_CURRENT_SOURCE_DIR}/glob.c"
+           "${CMAKE_SOURCE_DIR}/include/compat/glob.h"
+           PARENT_SCOPE)
+endif()