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 support for the use of CM108 for PTT on Mac #500

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
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
Prev Previous commit
Next Next commit
Build changes for the use of CM108 for PTT on Mac
The CMake changes are slightly complicated by the Windows build using
a local copy of some hidapi files, for some reason, instead of using
the hidapi library itself. The Mac version uses hidapi in the same way
as other libraries.

In the CMake files, it is unclear to me whether "elseif (NOT WIN32 AND
NOT CYGWIN)" means the same thing as "elseif (APPLE)", so they are
treated separately in order to avoid breaking other build types.
  • Loading branch information
mfncooper committed Nov 16, 2023
commit b8fdf013c53b2597776079d71e06d0664b583ddd
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
44 changes: 44 additions & 0 deletions cmake/modules/Findhidapi.cmake
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 18 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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()