Skip to content

Commit b8fdf01

Browse files
committed
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.
1 parent b03a797 commit b8fdf01

File tree

3 files changed

+77
-5
lines changed

3 files changed

+77
-5
lines changed

Diff for: CMakeLists.txt

+15-1
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,17 @@ elseif (HAVE_SNDIO)
342342
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_SNDIO")
343343
endif()
344344

345+
elseif (APPLE)
346+
find_package(Portaudio REQUIRED)
347+
if(PORTAUDIO_FOUND)
348+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_PORTAUDIO")
349+
endif()
350+
351+
find_package(hidapi REQUIRED)
352+
if(HIDAPI_FOUND)
353+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_CM108")
354+
endif()
355+
345356
elseif (NOT WIN32 AND NOT CYGWIN)
346357
find_package(Portaudio REQUIRED)
347358
if(PORTAUDIO_FOUND)
@@ -367,7 +378,10 @@ add_subdirectory(data)
367378
# external libraries
368379
add_subdirectory(${CUSTOM_GEOTRANZ_DIR})
369380
add_subdirectory(${CUSTOM_REGEX_DIR})
370-
add_subdirectory(${CUSTOM_HIDAPI_DIR})
381+
if(NOT APPLE)
382+
# Mac builds use the hidapi library, not custom local files
383+
add_subdirectory(${CUSTOM_HIDAPI_DIR})
384+
endif()
371385
add_subdirectory(${CUSTOM_MISC_DIR})
372386

373387
# direwolf source code and utilities

Diff for: cmake/modules/Findhidapi.cmake

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# - Try to find hidapi
2+
#
3+
# HIDAPI_FOUND - system has hidapi
4+
# HIDAPI_LIBRARIES - location of the library for hidapi
5+
# HIDAPI_INCLUDE_DIRS - location of the include files for hidapi
6+
7+
set(HIDAPI_ROOT_DIR
8+
"${HIDAPI_ROOT_DIR}"
9+
CACHE
10+
PATH
11+
"Directory to search for hidapi")
12+
13+
# no need to check pkg-config
14+
15+
find_path(HIDAPI_INCLUDE_DIRS
16+
NAMES
17+
hidapi.h
18+
PATHS
19+
/usr/local/include
20+
/usr/include
21+
/opt/local/include
22+
HINTS
23+
${HIDAPI_ROOT_DIR}
24+
PATH_SUFFIXES
25+
hidapi
26+
)
27+
28+
find_library(HIDAPI_LIBRARIES
29+
NAMES
30+
hidapi
31+
PATHS
32+
/usr/local/lib
33+
/usr/lib
34+
/usr/lib64
35+
/opt/local/lib
36+
HINTS
37+
${HIDAPI_ROOT_DIR}
38+
)
39+
40+
41+
include(FindPackageHandleStandardArgs)
42+
find_package_handle_standard_args(HIDAPI DEFAULT_MSG HIDAPI_INCLUDE_DIRS HIDAPI_LIBRARIES)
43+
44+
mark_as_advanced(HIDAPI_INCLUDE_DIRS HIDAPI_LIBRARIES)

Diff for: src/CMakeLists.txt

+18-4
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ include_directories(
1010
${PORTAUDIO_INCLUDE_DIRS}
1111
${SNDIO_INCLUDE_DIRS}
1212
${CUSTOM_GEOTRANZ_DIR}
13-
${CUSTOM_HIDAPI_DIR}
1413
)
1514

1615
if(WIN32 OR CYGWIN)
1716
include_directories(
17+
${CUSTOM_HIDAPI_DIR}
1818
${CUSTOM_REGEX_DIR}
1919
)
2020
endif()
2121

22+
if(APPLE)
23+
include_directories(
24+
${HIDAPI_INCLUDE_DIRS}
25+
)
26+
endif()
27+
2228

2329
# direwolf
2430
list(APPEND direwolf_SOURCES
@@ -131,6 +137,7 @@ if(LINUX)
131137
else() # macOS freebsd
132138
list(APPEND direwolf_SOURCES
133139
audio_portaudio.c
140+
cm108.c
134141
)
135142
if(USE_MACOS_DNSSD)
136143
list(APPEND direwolf_SOURCES
@@ -469,10 +476,11 @@ endif()
469476

470477
# List USB audio adapters than can use GPIO for PTT.
471478
# Originally for Linux only (using udev).
472-
# Version 1.7 adds it for Windows. Needs hidapi library.
479+
# Version 1.7 adds it for Windows. Uses local hidapi code.
480+
# Post-1.7 adds it for Mac. Uses hidapi library.
473481

474482
# cm108
475-
if(UDEV_FOUND OR WIN32 OR CYGWIN)
483+
if(UDEV_FOUND OR WIN32 OR CYGWIN OR HIDAPI_FOUND)
476484
list(APPEND cm108_SOURCES
477485
cm108.c
478486
textcolor.c
@@ -496,6 +504,12 @@ if(UDEV_FOUND OR WIN32 OR CYGWIN)
496504
)
497505
endif()
498506

507+
if (APPLE)
508+
target_link_libraries(cm108
509+
${HIDAPI_LIBRARIES}
510+
)
511+
endif()
512+
499513
if (WIN32 OR CYGWIN)
500514
target_link_libraries(cm108
501515
${HIDAPI_LIBRARIES}
@@ -568,6 +582,6 @@ install(TARGETS ttcalc DESTINATION ${INSTALL_BIN_DIR})
568582
install(TARGETS kissutil DESTINATION ${INSTALL_BIN_DIR})
569583
install(TARGETS tnctest DESTINATION ${INSTALL_BIN_DIR})
570584
install(TARGETS appserver DESTINATION ${INSTALL_BIN_DIR})
571-
if(UDEV_FOUND OR WIN32 OR CYGWIN)
585+
if(UDEV_FOUND OR WIN32 OR CYGWIN OR HIDAPI_FOUND)
572586
install(TARGETS cm108 DESTINATION ${INSTALL_BIN_DIR})
573587
endif()

0 commit comments

Comments
 (0)