Enhanced CMake finder for hamlib to use pkg-config to determine static

linking requirements.

Changed build to use static hamlib if available.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3975 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2014-04-02 12:46:15 +00:00
parent 544666b5f8
commit 118e994b64
2 changed files with 64 additions and 27 deletions

View File

@ -4,25 +4,56 @@
# hamlib_FOUND - system has Hamlib-2 # hamlib_FOUND - system has Hamlib-2
# hamlib_INCLUDE_DIRS - the Hamlib-2 include directories # hamlib_INCLUDE_DIRS - the Hamlib-2 include directories
# hamlib_LIBRARIES - link these to use Hamlib-2 # 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
include (LibFindMacros) include (LibFindMacros)
# Use pkg-config to get hints about paths # pkg-config?
libfind_pkg_check_modules (hamlib_PKGCONF hamlib) find_path (__hamlib_pc_path NAMES hamlib.pc
PATH_SUFFIXES lib/pkgconfig
# Include dirs
find_path (hamlib_INCLUDE_DIR
NAMES hamlib/rig.h
PATHS ${hamlib_PKGCONF_INCLUDE_DIRS}
) )
if (__hamlib_pc_path)
set (ENV{PKG_CONFIG_PATH} "${__hamlib_pc_path}" "$ENV{PKG_CONFIG_PATH}")
unset (__hamlib_pc_path CACHE)
endif ()
# The library # Use pkg-config to get hints about paths, libs and, flags
find_library (hamlib_LIBRARY unset (__pkg_config_checked_hamlib CACHE)
NAMES hamlib hamlib-2 libfind_pkg_check_modules (PC_HAMLIB hamlib)
PATHS ${hamlib_PKGCONF_LIBRARY_DIRS}
) 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 ()
# 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 the include dir variables and the libraries and let libfind_process do the rest
set (hamlib_PROCESS_INCLUDES hamlib_INCLUDE_DIR) set (hamlib_PROCESS_INCLUDES hamlib_INCLUDE_DIR)
set (hamlib_PROCESS_LIBS hamlib_LIBRARY) set (hamlib_PROCESS_LIBS hamlib_LIBRARY)
libfind_process (hamlib) 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)
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)

View File

@ -429,7 +429,7 @@ set (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${WSJT_LIB_DESTINATION}") set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${WSJT_LIB_DESTINATION}")
# add teh automaticaly determined parts of the RPATH which point to # add the automaticaly determined parts of the RPATH which point to
# directories outside of the build tree to the install RPATH # directories outside of the build tree to the install RPATH
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
@ -445,19 +445,24 @@ endif ("${isSystemDir}" STREQUAL "-1")
# fftw3 single precsion library # fftw3 single precsion library
# #
find_package (FFTW3 COMPONENTS single REQUIRED) find_package (FFTW3 COMPONENTS single REQUIRED)
if (NOT FFTW3_FOUND)
message (FATAL_ERROR "fftw3 single precsion library not found")
endif (NOT FFTW3_FOUND)
include_directories (${FFTW3_INCLUDE_DIRS}) include_directories (${FFTW3_INCLUDE_DIRS})
# #
# libhamlib setup # libhamlib setup
# #
find_package (hamlib REQUIRED) find_package (hamlib 3 REQUIRED)
if (NOT hamlib_FOUND)
message (FATAL_ERROR "hamlib library not found")
endif (NOT hamlib_FOUND)
include_directories (${hamlib_INCLUDE_DIRS}) include_directories (${hamlib_INCLUDE_DIRS})
if (hamlib_STATIC_LIBRARY)
# static link hamlib if archive library available
set (hamlib_LIBRARY "${hamlib_STATIC_LIBRARY}")
set (hamlib_LIBRARIES "${hamlib_STATIC_LIBRARIES}")
endif ()
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) # if (WIN32)
# find_library (hamlib_RUNTIME NAMES hamlib hamlib-2 PATH_SUFFIXES bin) # find_library (hamlib_RUNTIME NAMES hamlib hamlib-2 PATH_SUFFIXES bin)
@ -472,8 +477,8 @@ include_directories (${hamlib_INCLUDE_DIRS})
# #
# Widgets finds its own dependencies. # Widgets finds its own dependencies.
find_package (Qt5Widgets REQUIRED) find_package (Qt5Widgets 5 REQUIRED)
find_package (Qt5Multimedia REQUIRED) find_package (Qt5Multimedia 5 REQUIRED)
if (WIN32) if (WIN32)
add_definitions (-DQT_NEEDS_QTMAIN) add_definitions (-DQT_NEEDS_QTMAIN)
@ -574,7 +579,7 @@ add_executable (jt9code lib/jt9code.f90 wsjtx.rc)
target_link_libraries (jt9code wsjt) target_link_libraries (jt9code wsjt)
add_executable (jt9 lib/jt9.f90 lib/jt9a.f90 lib/jt9b.f90 lib/jt9c.f90 ${jt9_CXXSRCS} wsjtx.rc) add_executable (jt9 lib/jt9.f90 lib/jt9a.f90 lib/jt9b.f90 lib/jt9c.f90 ${jt9_CXXSRCS} wsjtx.rc)
target_link_libraries (jt9 wsjt ${FFTW3F_LIBRARY}) target_link_libraries (jt9 wsjt ${FFTW3_LIBRARIES})
qt5_use_modules (jt9 Core) qt5_use_modules (jt9 Core)
# build configuration dialog and transceiver interface test application # build configuration dialog and transceiver interface test application
@ -596,7 +601,7 @@ set_target_properties (wsjtx PROPERTIES
MACOSX_BUNDLE_COPYRIGHT "${WSJTX_COPYRIGHT}" MACOSX_BUNDLE_COPYRIGHT "${WSJTX_COPYRIGHT}"
) )
target_link_libraries (wsjtx wsjt wsjt_qt ${hamlib_LIBRARIES} ${FFTW3F_LIBRARY}) target_link_libraries (wsjtx wsjt wsjt_qt ${hamlib_LIBRARIES} ${FFTW3_LIBRARIES})
add_dependencies (wsjtx kvasd) add_dependencies (wsjtx kvasd)
if (WIN32) if (WIN32)
@ -707,7 +712,7 @@ if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
# if a system Qt is used (e.g. installed in /usr/lib/), it will not be included in the installation # if a system Qt is used (e.g. installed in /usr/lib/), it will not be included in the installation
set (fixup_exe "\${CMAKE_INSTALL_PREFIX}/${WSJT_BIN_DESTINATION}/${CMAKE_PROJECT_NAME}${CMAKE_EXECUTABLE_SUFFIX}") set (fixup_exe "\${CMAKE_INSTALL_PREFIX}/${WSJT_BIN_DESTINATION}/${CMAKE_PROJECT_NAME}${CMAKE_EXECUTABLE_SUFFIX}")
get_filename_component (hamlib_lib_dir ${hamlib_LIBRARIES} PATH) #get_filename_component (hamlib_lib_dir ${hamlib_LIBRARIES} PATH)
if (APPLE) if (APPLE)
# install required Qt plugins # install required Qt plugins
@ -746,7 +751,7 @@ file (APPEND \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${WSJT_QT_CONF_DESTINATION
if (WIN32) if (WIN32)
# DLL directory # DLL directory
set (hamlib_lib_dir ${hamlib_lib_dir}/../bin) #set (hamlib_lib_dir ${hamlib_lib_dir}/../bin)
get_filename_component (fftw_lib_dir ${FFTW3F_LIBRARY} PATH) get_filename_component (fftw_lib_dir ${FFTW3F_LIBRARY} PATH)
list (APPEND fixup_library_dirs ${fftw_lib_dir}) list (APPEND fixup_library_dirs ${fftw_lib_dir})
@ -786,7 +791,8 @@ file (APPEND \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${WSJT_QT_CONF_DESTINATION
# set (gp_tool "objdump") # we want MinGW tool - not MSVC (See GetPrerequisites.cmake) # set (gp_tool "objdump") # we want MinGW tool - not MSVC (See GetPrerequisites.cmake)
endif (WIN32) endif (WIN32)
list (APPEND fixup_library_dirs ${hamlib_lib_dir}) #list (APPEND fixup_library_dirs ${hamlib_lib_dir})
list (APPEND fixup_library_dirs ${hamlib_LIBRARY_DIRS})
install (CODE " install (CODE "
file (GLOB_RECURSE QTPLUGINS file (GLOB_RECURSE QTPLUGINS