Updated CMake finders, working on Windows & supporting dynamic hamlib

This commit is contained in:
Bill Somerville 2021-04-12 22:33:46 +01:00
parent 3f98270681
commit 63e485e819
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F
4 changed files with 57 additions and 130 deletions

View File

@ -1,45 +1,25 @@
# - Try to find hamlib
# #
# Once done, this will define: # Find the hamlib library
# #
# hamlib_FOUND - system has Hamlib # This will define the following variables::
# 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 # hamlib_FOUND - True if the system has the usb library
# hamlib_VERSION - The verion of the usb library which was found
#
# and the following imported targets::
#
# hamlib::hamlib - The hamlib library
# #
# function(dump_cmake_variables)
# get_cmake_property(_variableNames VARIABLES)
# list (SORT _variableNames)
# foreach (_variableName ${_variableNames})
# if (ARGV0)
# unset(MATCHED)
# string(REGEX MATCH ${ARGV0} MATCHED ${_variableName})
# if (NOT MATCHED)
# continue()
# endif()
# endif()
# message(STATUS "${_variableName}=${${_variableName}}")
# endforeach()
# endfunction()
include (LibFindMacros) include (LibFindMacros)
libfind_pkg_detect (hamlib hamlib FIND_PATH hamlib/rig.h PATH_SUFFIXES hamlib FIND_LIBRARY hamlib) libfind_pkg_detect (hamlib hamlib
FIND_PATH hamlib/rig.h PATH_SUFFIXES hamlib
FIND_LIBRARY hamlib
)
libfind_package (hamlib libusb) libfind_package (hamlib libusb)
if (hamlib_STATIC)
if (hamlib_PKGCONF_FOUND)
set (hamlib_PROCESS_LIBS hamlib_PKGCONF_STATIC_LIBRARY)
else ()
endif ()
else ()
if (hamlib_PKGCONF_FOUND)
set (hamlib_PROCESS_LIBS hamlib_PKGCONF_LIBRARY)
else ()
endif ()
endif ()
libfind_process (hamlib) libfind_process (hamlib)
if (NOT hamlib_PKGCONF_FOUND) if (NOT hamlib_PKGCONF_FOUND)
@ -49,3 +29,19 @@ if (NOT hamlib_PKGCONF_FOUND)
set (hamlib_LIBRARIES ${hamlib_LIBRARIES};m;dl) set (hamlib_LIBRARIES ${hamlib_LIBRARIES};m;dl)
endif () endif ()
endif () endif ()
if (hamlib_FOUND AND NOT TARGET hamlib::hamlib)
add_library (hamlib::hamlib UNKNOWN IMPORTED)
set_target_properties (hamlib::hamlib PROPERTIES
IMPORTED_LOCATION "${hamlib_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${hamlib_PKGCONF_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${hamlib_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${hamlib_LIBRARIES}"
)
endif ()
mark_as_advanced (
hamlib_INCLUDE_DIR
hamlib_LIBRARY
hamlib_LIBRARIES
)

View File

@ -1,86 +1,42 @@
# Findlibusb # Findlibusb
# ======= # ==========
# #
# Find the usb library # Find the usb library
# #
# This will define the following variables:: # This will define the following variables::
# #
# libusb_FOUND - True if the system has the usb library # libusb_FOUND - True if the system has the usb library
# libusb_VERSION - The verion of the usb library which was found # libusb_VERSION - The verion of the usb library which was found
# #
# and the following imported targets:: # and the following imported targets::
# #
# libusb::libusb - The libusb library # libusb::libusb - The libusb library
# #
# If libusb_STATIC is TRUE then static linking will be assumed
#
function(dump_cmake_variables) if (WIN32)
get_cmake_property(_variableNames VARIABLES) # Use path suffixes on MS Windows as we probably shouldn't
list (SORT _variableNames) # trust the PATH envvar. PATH will still be searched to find the
foreach (_variableName ${_variableNames}) # library as last resort.
if (ARGV0) if (CMAKE_SIZEOF_VOID_P MATCHES "8")
unset(MATCHED) set (_library_options PATH_SUFFIXES MinGW64/dll MinGW64/static)
string(REGEX MATCH ${ARGV0} MATCHED ${_variableName}) else ()
if (NOT MATCHED) set (_library_options PATH_SUFFIXES MinGW32/dll MinGW32/static)
continue() endif ()
endif() endif ()
endif() libfind_pkg_detect (libusb libusb-1.0
message(STATUS "${_variableName}=${${_variableName}}") FIND_PATH libusb.h PATH_SUFFIXES libusb-1.0
endforeach() FIND_LIBRARY libusb-1.0 ${_library_options}
endfunction() )
include (LibFindMacros)
libfind_pkg_detect (libusb libusb-1.0 FIND_PATH libusb.h PATH_SUFFIXES libusb-1.0 FIND_LIBRARY libusb-1.0)
set (libusb_LIBRARY C:/Tools/libusb-1.0.24/MinGW64/dll/libusb-1.0.dll.a)
# # Use pkg-config to get hints about paths, libs and, flags
# libfind_pkg_check_modules (libusb_PC libusb-1.0)
# # Include dir
# find_path (libusb_INCLUDE_DIR
# libusb.h
# PATHS ${libusb_PC_INCLUDE_DIRS}
# PATH_SUFFIXES libusb-1.0
# )
# # Library
# if (libusb_STATIC)
# find_library (libusb_LIBRARY
# NAMES usb-1.0
# PATHS ${libusb_PC_STATIC_LIBRARY_DIRS}
# PATH_SUFFIXES static
# )
# else ()
# find_library (libusb_LIBRARY
# NAMES usb-1.0
# PATHS ${libusb_PC_LIBRARY_DIRS}
# )
# endif ()
# set (libusb_PROCESS_INCLUDES libusb_INCLUDE_DIR)
# set (libusb_PROCESS_LIBS libusb_LIBRARY)
libfind_process (libusb) libfind_process (libusb)
# include (FindPackageHandleStandardArgs)
# find_package_handle_standard_args (libusb
# REQUIRED_VARS
# libusb_LIBRARY
# libusb_INCLUDE_DIR
# VERSION_VAR libusb_VERSION
# )
# if (libusb_FOUND)
# set (libusb_LIBRARIES ${libusb_LIBRARY})
# set (libusb_INCLUDE_DIRS ${libusb_INCLUDE_DIR})
# set (libusb_DEFINITIONS ${libusb_CFLAGS_OTHER})
# endif ()
if (libusb_FOUND AND NOT TARGET libusb::libusb) if (libusb_FOUND AND NOT TARGET libusb::libusb)
add_library (libusb::libusb UNKNOWN IMPORTED) add_library (libusb::libusb UNKNOWN IMPORTED)
set_target_properties (libusb::libusb PROPERTIES set_target_properties (libusb::libusb PROPERTIES
IMPORTED_LOCATION "${libusb_LIBRARY}" IMPORTED_LOCATION "${libusb_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${libusb_CFLAGS_OTHER}" INTERFACE_COMPILE_OPTIONS "${libusb_PKGCONF_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${libusb_INCLUDE_DIRS}" INTERFACE_INCLUDE_DIRECTORIES "${libusb_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARAIES "${libusb_LIBRARIES}" INTERFACE_LINK_LIBRARIES "${libusb_LIBRARIES}"
) )
endif () endif ()

View File

@ -9,39 +9,23 @@
# #
# portaudio::portaudio - The portaudio library # portaudio::portaudio - The portaudio library
# #
# If portaudio_STATIC is TRUE then static linking will be assumed
#
# function(dump_cmake_variables)
# get_cmake_property(_variableNames VARIABLES)
# list (SORT _variableNames)
# foreach (_variableName ${_variableNames})
# if (ARGV0)
# unset(MATCHED)
# string(REGEX MATCH ${ARGV0} MATCHED ${_variableName})
# if (NOT MATCHED)
# continue()
# endif()
# endif()
# message(STATUS "${_variableName}=${${_variableName}}")
# endforeach()
# endfunction()
include (LibFindMacros) include (LibFindMacros)
libfind_pkg_detect (portaudio portaudio-2.0 FIND_PATH portaudio.h FIND_LIBRARY portaudio) libfind_pkg_detect (portaudio portaudio-2.0
set (portaudio_PROCESS_LIBS portaudio_PKGCONF_LDFLAGS) FIND_PATH portaudio.h
libfind_process (portaudio) FIND_LIBRARY portaudio
)
#dump_cmake_variables ("^portaudio_") libfind_process (portaudio)
if (portaudio_FOUND AND NOT TARGET portaudio::portaudio) if (portaudio_FOUND AND NOT TARGET portaudio::portaudio)
add_library (portaudio::portaudio UNKNOWN IMPORTED) add_library (portaudio::portaudio UNKNOWN IMPORTED)
set_target_properties (portaudio::portaudio PROPERTIES set_target_properties (portaudio::portaudio PROPERTIES
IMPORTED_LOCATION "${portaudio_LIBRARY}" IMPORTED_LOCATION "${portaudio_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${portaudio_CFLAGS_OTHERS}" INTERFACE_COMPILE_OPTIONS "${portaudio_PKGCONF_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${portaudio_INCLUDE_DIRS}" INTERFACE_INCLUDE_DIRECTORIES "${portaudio_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${portaudio_LIBRARIES}" INTERFACE_LINK_LIBRARIES "${portaudio_PKGCONF_LDFLAGS}"
) )
endif () endif ()

View File

@ -872,19 +872,11 @@ find_package (FFTW3 COMPONENTS single threads REQUIRED)
# #
# libhamlib setup # libhamlib setup
# #
set (hamlib_STATIC 1)
find_package (hamlib REQUIRED) find_package (hamlib REQUIRED)
find_program (RIGCTL_EXE rigctl) find_program (RIGCTL_EXE rigctl)
find_program (RIGCTLD_EXE rigctld) find_program (RIGCTLD_EXE rigctld)
find_program (RIGCTLCOM_EXE rigctlcom) find_program (RIGCTLCOM_EXE rigctlcom)
message (STATUS "hamlib_INCLUDE_DIRS: ${hamlib_INCLUDE_DIRS}")
message (STATUS "hamlib_LIBRARIES: ${hamlib_LIBRARIES}")
message (STATUS "hamlib_LIBRARY_DIRS: ${hamlib_LIBRARY_DIRS}")
set (CMAKE_REQUIRED_INCLUDES "${hamlib_INCLUDE_DIRS}")
set (CMAKE_REQUIRED_LIBRARIES "${hamlib_LIBRARIES}")
set (CMAKE_EXTRA_INCLUDE_FILES "hamlib/rig.h")
check_type_size (CACHE_ALL HAMLIB_OLD_CACHING) check_type_size (CACHE_ALL HAMLIB_OLD_CACHING)
check_symbol_exists (rig_set_cache_timeout_ms "hamlib/rig.h" HAVE_HAMLIB_CACHING) check_symbol_exists (rig_set_cache_timeout_ms "hamlib/rig.h" HAVE_HAMLIB_CACHING)
@ -1332,8 +1324,7 @@ target_link_libraries (qcp Qt5::Widgets Qt5::PrintSupport)
add_library (wsjt_qt STATIC ${wsjt_qt_CXXSRCS} ${wsjt_qt_GENUISRCS} ${GENAXSRCS}) add_library (wsjt_qt STATIC ${wsjt_qt_CXXSRCS} ${wsjt_qt_GENUISRCS} ${GENAXSRCS})
# set wsjtx_udp exports to static variants # set wsjtx_udp exports to static variants
target_compile_definitions (wsjt_qt PUBLIC UDP_STATIC_DEFINE) target_compile_definitions (wsjt_qt PUBLIC UDP_STATIC_DEFINE)
target_link_libraries (wsjt_qt Boost::log qcp Qt5::Widgets Qt5::Network Qt5::Sql) target_link_libraries (wsjt_qt hamlib::hamlib Boost::log qcp Qt5::Widgets Qt5::Network Qt5::Sql)
target_include_directories (wsjt_qt BEFORE PRIVATE ${hamlib_INCLUDE_DIRS})
if (WIN32) if (WIN32)
target_link_libraries (wsjt_qt Qt5::AxContainer Qt5::AxBase) target_link_libraries (wsjt_qt Qt5::AxContainer Qt5::AxBase)
endif (WIN32) endif (WIN32)
@ -1450,7 +1441,7 @@ else ()
) )
endif () endif ()
endif () endif ()
target_link_libraries (wsjtx Qt5::SerialPort wsjt_cxx wsjt_qt wsjt_qtmm ${hamlib_LIBRARIES} ${FFTW3_LIBRARIES} ${LIBM_LIBRARIES}) target_link_libraries (wsjtx Qt5::SerialPort wsjt_cxx wsjt_qt wsjt_qtmm ${FFTW3_LIBRARIES} ${LIBM_LIBRARIES})
# make a library for WSJT-X UDP servers # make a library for WSJT-X UDP servers
# add_library (wsjtx_udp SHARED ${UDP_library_CXXSRCS}) # add_library (wsjtx_udp SHARED ${UDP_library_CXXSRCS})