summaryrefslogtreecommitdiff
path: root/CMake/Modules/Findhamlib.cmake
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2018-02-16 15:17:14 +0000
committerhibby <d@vehibberd.com>2018-02-16 15:17:14 +0000
commit37f727ac0746fd85504aa46c1f023c09b3eff33a (patch)
treec8a7ce04545040a8f161ba279528730bd9a3e6ab /CMake/Modules/Findhamlib.cmake
parentd63dd8d081a6fcd0715cd13f26df59fb831769d2 (diff)
New upstream version 1.8.0+repackupstream/1.8.0+repack
Diffstat (limited to 'CMake/Modules/Findhamlib.cmake')
-rw-r--r--CMake/Modules/Findhamlib.cmake80
1 files changed, 51 insertions, 29 deletions
diff --git a/CMake/Modules/Findhamlib.cmake b/CMake/Modules/Findhamlib.cmake
index abed74b2..1590f051 100644
--- a/CMake/Modules/Findhamlib.cmake
+++ b/CMake/Modules/Findhamlib.cmake
@@ -1,18 +1,23 @@
# - Try to find hamlib
+#
# Once done, this will define:
#
-# hamlib_FOUND - system has Hamlib-2
-# hamlib_INCLUDE_DIRS - the Hamlib-2 include directories
-# hamlib_LIBRARIES - link these to use Hamlib-2
-# hamlib_STATIC_FOUND - system has Hamlib-2 static archive
-# hamlib_STATIC_LIBRARIES - link these to use Hamlib-2 static archive
+# hamlib_FOUND - system has Hamlib
+# hamlib_INCLUDE_DIRS - the Hamlib include directories
+# hamlib_LIBRARIES - link these to use Hamlib
+# hamlib_LIBRARY_DIRS - required shared/dynamic libraries are here
+#
+# If hamlib_STATIC is TRUE then static linking will be assumed
+#
include (LibFindMacros)
+set (hamlib_LIBRARY_DIRS)
+
# pkg-config?
find_path (__hamlib_pc_path NAMES hamlib.pc
PATH_SUFFIXES lib/pkgconfig
-)
+ )
if (__hamlib_pc_path)
set (ENV{PKG_CONFIG_PATH} "${__hamlib_pc_path}" "$ENV{PKG_CONFIG_PATH}")
unset (__hamlib_pc_path CACHE)
@@ -20,40 +25,57 @@ endif ()
# Use pkg-config to get hints about paths, libs and, flags
unset (__pkg_config_checked_hamlib CACHE)
+# pkg_config will fail on Windows if the Hamlib USB backends are
+# configured since libusb-1.0 does not ship with a pkg_config file on
+# Windows, that's OK because we fix it up below
libfind_pkg_check_modules (PC_HAMLIB hamlib)
-if (NOT PC_HAMLIB_STATIC_LIBRARIES)
+if (NOT PC_HAMLIB_FOUND)
+ # The headers
+ find_path (hamlib_INCLUDEDIR hamlib/rig.h)
+ # The libraries
+ if (hamlib_STATIC)
+ libfind_library (hamlib libhamlib.a)
+ else ()
+ libfind_library (hamlib hamlib)
+ endif ()
if (WIN32)
- set (PC_HAMLIB_STATIC_LIBRARIES hamlib ws2_32)
+ set (hamlib_EXTRA_LIBRARIES ws2_32)
else ()
- set (PC_HAMLIB_STATIC_LIBRARIES hamlib m dl usb)
+ set (hamlib_EXTRA_LIBRARIES m dl)
endif ()
-endif ()
-# The libraries
-libfind_library (hamlib hamlib)
-libfind_library (hamlib_STATIC libhamlib.a)
-
-find_path (hamlib_INCLUDE_DIR hamlib/rig.h)
-
-# Set the include dir variables and the libraries and let libfind_process do the rest
-set (hamlib_PROCESS_INCLUDES hamlib_INCLUDE_DIR)
-set (hamlib_PROCESS_LIBS hamlib_LIBRARY)
+ # libusb-1.0 has no pkg-config file on Windows so we have to find it
+ # ourselves
+ find_library (LIBUSB NAMES usb-1.0 PATH_SUFFIXES MinGW32/dll)
+ if (LIBUSB)
+ set (hamlib_EXTRA_LIBRARIES ${LIBUSB} ${hamlib_EXTRA_LIBRARIES})
+ get_filename_component (hamlib_libusb_path ${LIBUSB} PATH)
+ set (hamlib_LIBRARY_DIRS ${hamlib_LIBRARY_DIRS} ${hamlib_libusb_path})
+ endif (LIBUSB)
+ set (hamlib_PROCESS_INCLUDES hamlib_INCLUDEDIR)
+ set (hamlib_PROCESS_LIBS hamlib_LIBRARY hamlib_EXTRA_LIBRARIES)
+else ()
+ if (hamlib_STATIC)
+ set (hamlib_PROCESS_INCLUDES PC_HAMLIB_STATIC_INCLUDE_DIRS)
+ set (hamlib_PROCESS_LIBS PC_HAMLIB_STATIC_LDFLAGS)
+ set (hamlib_LIBRARY_DIRS ${PC_HAMLIB_STATIC_LIBRARY_DIRS})
+ else ()
+ set (hamlib_PROCESS_INCLUDES PC_HAMLIB_INCLUDE_DIRS)
+ set (hamlib_PROCESS_LIBS PC_HAMLIB_LDFLAGS)
+ set (hamlib_LIBRARY_DIRS ${PC_HAMLIB_LIBRARY_DIRS})
+ endif ()
+endif ()
libfind_process (hamlib)
-set (hamlib_STATIC_PROCESS_INCLUDES hamlib_STATIC_INCLUDE_DIR)
-set (hamlib_STATIC_PROCESS_LIBS hamlib_STATIC_LIBRARY PC_HAMLIB_STATIC_LIBRARIES)
-libfind_process (hamlib_STATIC)
-
-# make sure we return a full path for the library we return
-if (hamlib_FOUND)
- list (REMOVE_ITEM hamlib_LIBRARIES hamlib)
- if (hamlib_STATIC_LIBRARIES)
- list (REMOVE_ITEM hamlib_STATIC_LIBRARIES hamlib)
+if (WIN32)
+ find_path (hamlib_dll_path libhamlib-2.dll)
+ if (hamlib_dll_path)
+ set (hamlib_LIBRARY_DIRS ${hamlib_LIBRARY_DIRS} ${hamlib_dll_path})
endif ()
endif ()
# Handle the QUIETLY and REQUIRED arguments and set HAMLIB_FOUND to
# TRUE if all listed variables are TRUE
include (FindPackageHandleStandardArgs)
-find_package_handle_standard_args (hamlib DEFAULT_MSG hamlib_INCLUDE_DIRS hamlib_LIBRARY hamlib_LIBRARIES)
+find_package_handle_standard_args (hamlib DEFAULT_MSG hamlib_INCLUDE_DIRS hamlib_LIBRARIES hamlib_LIBRARY_DIRS)