Adjust CMake Hamlib finder for latest version

Hamlib now used  libusb-1.0 and since that is available  on Windows we
can now build with it across platforms. This change allows for that if
the custom USB backends are configured in Hamlib.

As it looks  like Hamlib v3.1 will be suitable  for WSJT-X this change
also puts  in place what  is needed to  link to a  Hamlib SO/DLL/DYLIB
when required. This is switched on  by not defining the CMake variable
hamlib_STATIC. This could  be used on Windows and Mac  but Linux still
must have  Hamlib statically linked  due to repository  versions being
too old.

For  now  Hamlib  remains  statically linked  for  consistency  across
platforms.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6581 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2016-04-06 17:10:46 +00:00
parent 3dc2f1b6c8
commit b9df9eff69
3 changed files with 84 additions and 53 deletions

View File

@ -1,14 +1,19 @@
# - 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
@ -17,43 +22,61 @@ if (__hamlib_pc_path)
set (ENV{PKG_CONFIG_PATH} "${__hamlib_pc_path}" "$ENV{PKG_CONFIG_PATH}")
unset (__hamlib_pc_path CACHE)
endif ()
message (STATUS "ENV{PKG_CONFIG_PATH} $ENV{PKG_CONFIG_PATH}")
# 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 (WIN32)
set (PC_HAMLIB_STATIC_LIBRARIES hamlib ws2_32)
else ()
set (PC_HAMLIB_STATIC_LIBRARIES hamlib m dl usb)
endif ()
endif ()
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)
libfind_library (hamlib_STATIC libhamlib.a)
endif ()
if (WIN32)
set (hamlib_EXTRA_LIBRARIES ws2_32)
else ()
set (hamlib_EXTRA_LIBRARIES m dl)
endif ()
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)

View File

@ -786,28 +786,14 @@ find_package (FFTW3 COMPONENTS double single threads REQUIRED)
#
# libhamlib setup
#
set (hamlib_STATIC 1)
find_package (hamlib 3 REQUIRED)
if (hamlib_STATIC_LIBRARY)
# static link hamlib if archive library available
set (hamlib_LIBRARY "${hamlib_STATIC_LIBRARY}")
set (hamlib_LIBRARIES "${hamlib_STATIC_LIBRARIES}")
endif ()
find_program (RIGCTL_EXE rigctl)
find_program (RIGCTLD_EXE rigctld)
message (STATUS "hamlib_INCLUDE_DIRS: ${hamlib_INCLUDE_DIRS}")
message (STATUS "hamlib_LIBRARY: ${hamlib_LIBRARY}")
message (STATUS "hamlib_LIBRARIES: ${hamlib_LIBRARIES}")
message (STATUS "hamlib_STATIC_LIBRARY: ${hamlib_STATIC_LIBRARY}")
message (STATUS "hamlib_STATIC_LIBRARIES: ${hamlib_STATIC_LIBRARIES}")
# if (WIN32)
# find_library (hamlib_RUNTIME NAMES hamlib hamlib-2 PATH_SUFFIXES bin)
# get_filename_component (_hamlib_runtime_path "${hamlib_RUNTIME}" PATH)
# file (GLOB hamlib_BACKENDS ${_hamlib_runtime_path}/hamlib*.dll)
# find_library (usb_RUNTIME NAMES usb0 PATH_SUFFIXES bin)
# endif (WIN32)
message (STATUS "hamlib_LIBRARY_DIRS: ${hamlib_LIBRARY_DIRS}")
#
# Qt5 setup
@ -1355,11 +1341,11 @@ endif ()
set (CPACK_DEBIAN_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}")
set (CPACK_DEBIAN_PACKAGE_HOMEPAGE "${PROJECT_HOMEPAGE}")
set (CPACK_DEBIAN_PACKAGE_DEPENDS "libgfortran3 (>=4.8.2), libqt5serialport5 (>=5.2), libqt5multimedia5-plugins (>=5.2), libqt5widgets5 (>=5.2), libc6 (>=2.19)")
set (CPACK_DEBIAN_PACKAGE_DEPENDS "libgfortran3 (>=4.8.2), libqt5serialport5 (>=5.2), libqt5multimedia5-plugins (>=5.2), libqt5widgets5 (>=5.2), libusb-1.0, libudev, libc6 (>=2.19)")
set (CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set (CPACK_RPM_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
set (CPACK_RPM_PACKAGE_REQUIRES "qt5-qtserialport >= 5.2, qt5-qtmultimedia >= 5.2, glibc >= 2, libgfortran >= 4.8.2")
set (CPACK_RPM_PACKAGE_REQUIRES "qt5-qtserialport >= 5.2, qt5-qtmultimedia >= 5.2, libusb-1.0, libudev, glibc >= 2, libgfortran >= 4.8.2")
set (CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /usr/share/pixmaps /usr/share/applications /usr/share/man /usr/share/man1)
configure_file ("${PROJECT_SOURCE_DIR}/CMakeCPackOptions.cmake.in"

32
INSTALL
View File

@ -43,6 +43,13 @@ the libfftw library development package. Normally installing the
library development package pulls in all the FFTW v3 libraries
including the single precision variant.
The Hamlib library optionally requires the libusb-1.0 library, if the
development version (libusb-1.0-dev) is available Hamlib will
configure its custom USB device back end drivers. Most rigs do not
require this so normally you can choose not to install libusb-1.0-dev
but if you have a SoftRock USB or similar SDR that uses a custom USB
interface then it is required.
The Hamlib library is required. Currently WSJT-X needs to be built
using a forked version of the Hamlib git master. This fork contains
patches not yet accepted by the Hamlib development team which are
@ -62,7 +69,7 @@ $ ../src/autogen.sh --prefix=$HOME/hamlib-prefix \
CFLAGS="-fdata-sections -ffunction-sections" \
LDFLAGS="-Wl,--gc-sections"
$ make
$ make install
$ make install-strip
This will build a binary hamlib package located at ~/hamlib-prefix so
you will need to add that to your CMAKE_PREFIX_PATH variable in your
@ -115,6 +122,13 @@ the JT-SDK the following recipe should help. Reasons for building
Hamlib from source might include picking up the very latest patches or
building a different branch that you wish to contribute to.
Hamlib optionally depends upon libusb-1.0, see "Building from Source"
above for more details. If you wish to include support for the
optional custom USB Hamlib rig drivers then you must install
libusb-1.0 before building Hamlib. The package may be obtained from
http://libusb.info/, install it in a convenient location like
C:\Tools.
On Windows there is a complication in that the compilers used to build
Qt and WSJT-X are the MinGW ones bundled with the Qt package but
Hamlib needs to be build from an MSYS shell with the tools required to
@ -138,8 +152,9 @@ $ cd ../build
--without-cxx-binding --disable-winradio \
CC=<path-to-Qt-MinGW-tools>/gcc \
CXX=<path-to-Qt-MinGW-tools>/g++ \
CFLAGS="-fdata-sections -ffunction-sections" \
LDFLAGS="-Wl,--gc-sections"
CFLAGS="-fdata-sections -ffunction-sections -I<path-to-libusb-1.0>/include" \
LDFLAGS="-Wl,--gc-sections" \
LIBUSB_LIBS="-L<path-to-libusb-1.0>/MinGW32/dll -lusb-1.0"
$ make
$ make install
@ -147,6 +162,10 @@ NOTE: <path-to-Qt-MinGQ-tools> should be substituted with the actual
path to your Qt bundled tools e.g on my system it is
C:\Tools\Qt\Tools\mingw48_32\bin
NOTE: <path-to-libusb-1.0> should be substituted with the actual path
to your libusb-1.0 installation directory e.g. on my system it is
C:\Tools\libusb-1.0.20
This will leave a Hamlib binary package installed at
c:/Users/<user-name>/hamlib-prefix which is what needs to be on your
CMAKE_PREFIX_PATH. On Windows you almost certainly will be using a
@ -188,12 +207,13 @@ texinfo
gcc49
fftw-3-single +gcc49
asciidoc
libusb-devel
These are install by typing:
$ sudo port install autoconf automake \
libtool pkgconfig texinfo gcc49 asciidoc \
fftw-3-single +gcc49
fftw-3-single +gcc49 libusb-devel
Once complete you should have all the tools required to build WSJT-X.
@ -230,7 +250,9 @@ $ cd ~/hamlib-prefix/build
--enable-static \
--disable-shared \
--disable-winradio \
--prefix=$HOME/hamlib-prefix
--prefix=$HOME/hamlib-prefix \
CFLAGS="-I/opt/local/include" \
LIBUSB_LIBS="/opt/local/lib/libusb-1.0.la"
$ make
$ make install-strip