diff --git a/CMakeLists.txt b/CMakeLists.txt index 84aeb73..20aa28f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -342,6 +342,17 @@ elseif (HAVE_SNDIO) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_SNDIO") endif() +elseif (APPLE) + find_package(Portaudio REQUIRED) + if(PORTAUDIO_FOUND) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_PORTAUDIO") + endif() + + find_package(hidapi REQUIRED) + if(HIDAPI_FOUND) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_CM108") + endif() + elseif (NOT WIN32 AND NOT CYGWIN) find_package(Portaudio REQUIRED) if(PORTAUDIO_FOUND) @@ -367,7 +378,10 @@ add_subdirectory(data) # external libraries add_subdirectory(${CUSTOM_GEOTRANZ_DIR}) add_subdirectory(${CUSTOM_REGEX_DIR}) -add_subdirectory(${CUSTOM_HIDAPI_DIR}) +if(NOT APPLE) + # Mac builds use the hidapi library, not custom local files + add_subdirectory(${CUSTOM_HIDAPI_DIR}) +endif() add_subdirectory(${CUSTOM_MISC_DIR}) # direwolf source code and utilities diff --git a/cmake/modules/Findhidapi.cmake b/cmake/modules/Findhidapi.cmake new file mode 100644 index 0000000..163c8c2 --- /dev/null +++ b/cmake/modules/Findhidapi.cmake @@ -0,0 +1,44 @@ +# - Try to find hidapi +# +# HIDAPI_FOUND - system has hidapi +# HIDAPI_LIBRARIES - location of the library for hidapi +# HIDAPI_INCLUDE_DIRS - location of the include files for hidapi + +set(HIDAPI_ROOT_DIR + "${HIDAPI_ROOT_DIR}" + CACHE + PATH + "Directory to search for hidapi") + +# no need to check pkg-config + +find_path(HIDAPI_INCLUDE_DIRS + NAMES + hidapi.h + PATHS + /usr/local/include + /usr/include + /opt/local/include + HINTS + ${HIDAPI_ROOT_DIR} + PATH_SUFFIXES + hidapi + ) + +find_library(HIDAPI_LIBRARIES + NAMES + hidapi + PATHS + /usr/local/lib + /usr/lib + /usr/lib64 + /opt/local/lib + HINTS + ${HIDAPI_ROOT_DIR} + ) + + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(HIDAPI DEFAULT_MSG HIDAPI_INCLUDE_DIRS HIDAPI_LIBRARIES) + +mark_as_advanced(HIDAPI_INCLUDE_DIRS HIDAPI_LIBRARIES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a2c3963..7a05ecc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,15 +10,21 @@ include_directories( ${PORTAUDIO_INCLUDE_DIRS} ${SNDIO_INCLUDE_DIRS} ${CUSTOM_GEOTRANZ_DIR} - ${CUSTOM_HIDAPI_DIR} ) if(WIN32 OR CYGWIN) include_directories( + ${CUSTOM_HIDAPI_DIR} ${CUSTOM_REGEX_DIR} ) endif() +if(APPLE) + include_directories( + ${HIDAPI_INCLUDE_DIRS} + ) +endif() + # direwolf list(APPEND direwolf_SOURCES @@ -131,6 +137,7 @@ if(LINUX) else() # macOS freebsd list(APPEND direwolf_SOURCES audio_portaudio.c + cm108.c ) if(USE_MACOS_DNSSD) list(APPEND direwolf_SOURCES @@ -469,10 +476,11 @@ endif() # List USB audio adapters than can use GPIO for PTT. # Originally for Linux only (using udev). -# Version 1.7 adds it for Windows. Needs hidapi library. +# Version 1.7 adds it for Windows. Uses local hidapi code. +# Post-1.7 adds it for Mac. Uses hidapi library. # cm108 -if(UDEV_FOUND OR WIN32 OR CYGWIN) +if(UDEV_FOUND OR WIN32 OR CYGWIN OR HIDAPI_FOUND) list(APPEND cm108_SOURCES cm108.c textcolor.c @@ -496,6 +504,12 @@ if(UDEV_FOUND OR WIN32 OR CYGWIN) ) endif() + if (APPLE) + target_link_libraries(cm108 + ${HIDAPI_LIBRARIES} + ) + endif() + if (WIN32 OR CYGWIN) target_link_libraries(cm108 ${HIDAPI_LIBRARIES} @@ -568,6 +582,6 @@ install(TARGETS ttcalc DESTINATION ${INSTALL_BIN_DIR}) install(TARGETS kissutil DESTINATION ${INSTALL_BIN_DIR}) install(TARGETS tnctest DESTINATION ${INSTALL_BIN_DIR}) install(TARGETS appserver DESTINATION ${INSTALL_BIN_DIR}) -if(UDEV_FOUND OR WIN32 OR CYGWIN) +if(UDEV_FOUND OR WIN32 OR CYGWIN OR HIDAPI_FOUND) install(TARGETS cm108 DESTINATION ${INSTALL_BIN_DIR}) endif()