Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMakeList.txt #1

Merged
merged 9 commits into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 165 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,167 @@
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)

project(usb-1.0 C)
cmake_minimum_required(VERSION 3.10)

# This is because CMake on mingw can incorrectly use response files for includes
# instead of passing them directly via -I<dir>
# Explicitly disable use of response files
set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES OFF)

include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckStructHasMember)
include(CheckCCompilerFlag)
include(CTest)

check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
check_function_exists(pthread_condattr_setclock HAVE_PTHREAD_CONDATTR_SETCLOCK)
check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
check_function_exists(pthread_threadid_np HAVE_PTHREAD_THREADID_NP)
check_function_exists(eventfd HAVE_EVENTFD)
check_function_exists(pipe2 HAVE_PIPE2)
check_function_exists(syslog HAVE_SYSLOG)

check_include_files(asm/types.h HAVE_ASM_TYPES_H)
check_include_files(sys/eventfd.h HAVE_EVENTFD)
check_include_files(dlfcn.h HAVE_DLFCN_H)
check_include_files(inttypes.h HAVE_INTTYPES_H)
check_include_files(stdint.h HAVE_STDINT_H)
check_include_files(stdio.h HAVE_STDIO_H)
check_include_files(stdlib.h HAVE_STDLIB_H)
check_include_files(string.h HAVE_STRING_H)
check_include_files(strings.h HAVE_STRINGS_H)
check_include_files(sys/stat.h HAVE_SYS_STAT_H)
check_include_files(sys/time.h HAVE_SYS_TIME_H)
check_include_files(sys/types.h HAVE_SYS_TYPES_H)
check_include_files(unistd.h HAVE_UNISTD_H)
check_include_files("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)

check_symbol_exists(EFD_CLOEXEC "sys/eventfd.h" HAVE_DECL_EFD_CLOEXEC)
check_symbol_exists(EFD_NONBLOCK "sys/eventfd.h" HAVE_DECL_EFD_NONBLOCK)
check_symbol_exists(TFD_CLOEXEC "sys/eventfd.h" HAVE_DECL_TFD_CLOEXEC)
check_symbol_exists(timerfd_create "sys/timerfd.h" HAVE_TIMERFD)

check_struct_has_member("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC)

if(BUILD_SHARED_LIBS)
set(libusb_BUILD_SHARED_LIBS_DEFAULT ON)
else (BUILD_SHARED_LIBS)
set(libusb_BUILD_SHARED_LIBS_DEFAULT OFF)
endif (BUILD_SHARED_LIBS)

option(libusb_BUILD_SHARED_LIBS "Build Shared Libraries for libusb" ${libusb_BUILD_SHARED_LIBS_DEFAULT})
option(libusb_INSTALL_TARGETS "Install libusb targets" ON)
option(libusb_BUILD_TESTING "Build Tests" ON)
option(ENABLE_LOGGING "Enable Logging" ON)

if(WIN32)
set(PLATFORM_WINDOWS 1 CACHE INTERNAL "")
endif()
if(UNIX)
set(PLATFORM_POSIX 1 CACHE INTERNAL "")
endif()

if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL Clang) OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL GNU))
check_c_compiler_flag("-fvisibility=hidden" HAVE_VISIBILITY)
endif()

if(HAVE_VISIBILITY)
set(DEFAULT_VISIBILITY "__attribute__((visibility(\"default\")))" CACHE INTERNAL "")
else()
set(DEFAULT_VISIBILITY "" CACHE INTERNAL "")
endif()

file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gen_include")
configure_file(config.h.in "${CMAKE_CURRENT_BINARY_DIR}/gen_include/config.h" @ONLY)

set(libusb_ROOT libusb/libusb)

set(common_sources
"${libusb_ROOT}/core.c"
"${libusb_ROOT}/descriptor.c"
"${libusb_ROOT}/hotplug.c"
"${libusb_ROOT}/io.c"
"${libusb_ROOT}/sync.c"
"${libusb_ROOT}/strerror.c"

"${libusb_ROOT}/libusb.h"
"${libusb_ROOT}/libusbi.h"
"${libusb_ROOT}/version_nano.h"
"${libusb_ROOT}/version.h"

"${CMAKE_CURRENT_BINARY_DIR}/gen_include/config.h"
)

if(libusb_BUILD_SHARED_LIBS)
add_library(usb-1.0 SHARED ${common_sources})
else()
add_library(usb-1.0 STATIC ${common_sources})
endif()

target_include_directories(usb-1.0 PUBLIC "${libusb_ROOT}")
target_include_directories(usb-1.0 PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/gen_include")
target_include_directories(usb-1.0 PRIVATE "${libusb_ROOT}/os")

if(WIN32)
target_sources(usb-1.0 PRIVATE
"${libusb_ROOT}/os/windows_common.c"
"${libusb_ROOT}/os/windows_usbdk.c"
"${libusb_ROOT}/os/windows_winusb.c"
"${libusb_ROOT}/os/events_windows.c"
"${libusb_ROOT}/os/threads_windows.c"

"${libusb_ROOT}/os/events_windows.h"
"${libusb_ROOT}/os/threads_windows.h"
"${libusb_ROOT}/os/windows_common.h"
"${libusb_ROOT}/os/windows_usbdk.h"
"${libusb_ROOT}/os/windows_winusb.h"

"${libusb_ROOT}/libusb-1.0.def"
)
if(MSVC)
target_sources(usb-1.0 PRIVATE "${libusb_ROOT}/libusb-1.0.rc")
target_compile_definitions(usb-1.0 PRIVATE _CRT_SECURE_NO_WARNINGS=1)
endif()
target_link_libraries(usb-1.0 PRIVATE windowsapp)
endif()

if(UNIX AND NOT ANDROID)
target_sources(usb-1.0 PRIVATE
"${libusb_ROOT}/os/events_posix.c"
"${libusb_ROOT}/os/threads_posix.c"
"${libusb_ROOT}/os/linux_usbfs.c"
"${libusb_ROOT}/os/linux_udev.c"

"${libusb_ROOT}/os/events_posix.h"
"${libusb_ROOT}/os/threads_posix.h"
"${libusb_ROOT}/os/linux_usbfs.h"
)
target_link_libraries(usb-1.0 PUBLIC udev)
target_compile_definitions(usb-1.0 PRIVATE HAVE_LIBUDEV=1)
endif()

if(ANDROID)
target_sources(usb-1.0 PRIVATE
"${libusb_ROOT}/os/events_posix.c"
"${libusb_ROOT}/os/threads_posix.c"
"${libusb_ROOT}/os/linux_usbfs.c"
"${libusb_ROOT}/os/linux_netlink.c"
"${libusb_ROOT}/os/linux_android_jni.c"

"${libusb_ROOT}/os/events_posix.h"
"${libusb_ROOT}/os/threads_posix.h"
"${libusb_ROOT}/os/linux_usbfs.h"
)
target_include_directories(usb-1.0 PUBLIC android)
endif()

if(libusb_BUILD_TESTING AND BUILD_TESTING)
add_executable(testlibusb ${libusb_ROOT}/../tests/testlib.c ${libusb_ROOT}/../tests/stress.c)
target_link_libraries(testlibusb PRIVATE usb-1.0)
add_test(testlibusb COMMAND testlibusb)
endif()

message(FATAL_ERROR "Finish me!")
if(libusb_INSTALL_TARGETS)
install(TARGETS usb-1.0)
install(FILES ${libusb_ROOT}/libusb.h DESTINATION include/libusb-1.0)
endif()
124 changes: 124 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/* #define to the attribute for default visibility. */
#define DEFAULT_VISIBILITY @DEFAULT_VISIBILITY@

/* #define to 1 to start with debug message logging enabled. */
#cmakedefine ENABLE_DEBUG_LOGGING

/* #define to 1 to enable message logging. */
#cmakedefine ENABLE_LOGGING 1

/* #define to 1 if you have the <asm/types.h> header file. */
#cmakedefine HAVE_ASM_TYPES_H

/* #define to 1 if you have the `clock_gettime' function. */
#cmakedefine HAVE_CLOCK_GETTIME 1

/* #define to 1 if you have the declaration of `EFD_CLOEXEC', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_EFD_CLOEXEC 1

/* #define to 1 if you have the declaration of `EFD_NONBLOCK', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_EFD_NONBLOCK 1

/* #define to 1 if you have the declaration of `TFD_CLOEXEC', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_TFD_CLOEXEC 1

/* #define to 1 if you have the declaration of `TFD_NONBLOCK', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_TFD_NONBLOCK 1

/* #define to 1 if you have the <dlfcn.h> header file. */
#cmakedefine HAVE_DLFCN_H 1

/* #define to 1 if the system has eventfd functionality. */
#cmakedefine HAVE_EVENTFD 1

/* #define to 1 if you have the <inttypes.h> header file. */
#cmakedefine HAVE_INTTYPES_H 1

/* #define to 1 if you have the `udev' library (-ludev). */
#cmakedefine HAVE_LIBUDEV 1

/* #define to 1 if you have the <memory.h> header file. */
#cmakedefine HAVE_MEMORY_H 1

/* #define to 1 if the system has the type `nfds_t'. */
#cmakedefine HAVE_NFDS_T 1

/* #define to 1 if you have the `pipe2' function. */
#cmakedefine HAVE_PIPE2

/* #define to 1 if you have the `pthread_condattr_setclock' function. */
#cmakedefine HAVE_PTHREAD_CONDATTR_SETCLOCK

/* #define to 1 if you have the `pthread_setname_np' function. */
#cmakedefine HAVE_PTHREAD_SETNAME_NP

/* #define to 1 if you have the `pthread_threadid_np' function. */
#cmakedefine HAVE_PTHREAD_THREADID_NP

/* #define to 1 if you have the <stdint.h> header file. */
#cmakedefine HAVE_STDINT_H

/* Define to 1 if you have the <stdio.h> header file. */
#cmakedefine HAVE_STDIO_H

/* #define to 1 if you have the <stdlib.h> header file. */
#cmakedefine HAVE_STDLIB_H

/* #define to 1 if you have the <strings.h> header file. */
#cmakedefine HAVE_STRINGS_H

/* #define to 1 if you have the <string.h> header file. */
#cmakedefine HAVE_STRING_H

/* #define to 1 if the system has the type `struct timespec'. */
#cmakedefine HAVE_STRUCT_TIMESPEC

/* #define to 1 if you have the `syslog' function. */
#cmakedefine HAVE_SYSLOG

/* #define to 1 if you have the <sys/stat.h> header file. */
#cmakedefine HAVE_SYS_STAT_H

/* #define to 1 if you have the <sys/time.h> header file. */
#cmakedefine HAVE_SYS_TIME_H

/* #define to 1 if you have the <sys/types.h> header file. */
#cmakedefine HAVE_SYS_TYPES_H

/* #define to 1 if the system has timerfd functionality. */
#cmakedefine HAVE_TIMERFD

/* #define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H

/* #define to 1 if compiling for a POSIX platform. */
#cmakedefine PLATFORM_POSIX

/* #define to 1 if compiling for a Windows platform. */
#cmakedefine PLATFORM_WINDOWS


#if defined(__GNUC__)
#define PRINTF_FORMAT(a, b) __attribute__ ((format (__printf__, a, b)))
#else
#define PRINTF_FORMAT(a, b)
#endif

/* #define to 1 if you have the ANSI C header files. */
#cmakedefine STDC_HEADERS 1

/* #define to 1 to output logging messages to the systemwide log. */
#cmakedefine USE_SYSTEM_LOGGING_FACILITY

/* Enable GNU extensions. */
#cmakedefine _GNU_SOURCE 1

/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
/* #undef inline */
#endif