From 56c92c55fbae7c88b8e94c049d4a6c9f77d4d4a6 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Sun, 11 Apr 2021 15:29:15 +0100 Subject: [PATCH] Updated CMake finders and changes to build map65 on Linux --- CMake/Modules/Findlibusb.cmake | 87 ++++++++++++++++++++++++++++ CMake/Modules/Findportaudio.cmake | 90 ++++++++++++++++++++--------- CMake/Modules/Findusb.cmake | 57 ------------------ CMakeLists.txt | 15 +++++ map65/CMakeLists.txt | 11 +++- map65/bandmap.cpp | 3 +- map65/libm65/CMakeLists.txt | 8 +++ map65/libm65/{m65a.F90 => m65a.f90} | 0 map65/libm65/ptt_unix.c | 14 +++++ map65/mainwindow.cpp | 24 +++++++- map65/messages.cpp | 3 +- map65/widegraph.cpp | 8 --- map65/widegraph.h | 2 - wsjtx_config.h.in | 10 ++++ 14 files changed, 232 insertions(+), 100 deletions(-) create mode 100644 CMake/Modules/Findlibusb.cmake delete mode 100644 CMake/Modules/Findusb.cmake rename map65/libm65/{m65a.F90 => m65a.f90} (100%) diff --git a/CMake/Modules/Findlibusb.cmake b/CMake/Modules/Findlibusb.cmake new file mode 100644 index 000000000..239656fc9 --- /dev/null +++ b/CMake/Modules/Findlibusb.cmake @@ -0,0 +1,87 @@ +# Findlibusb +# ======= +# +# Find the usb library +# +# This will define the following variables:: +# +# libusb_FOUND - True if the system has the usb library +# libusb_VERSION - The verion of the usb library which was found +# +# and the following imported targets:: +# +# libusb::libusb - The libusb library +# +# If libusb_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) + +# 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 + NAMES libusb.h + PATHS ${libusb_PC_INCLUDE_DIRS} + ) + +# Library +if (libusb_STATIC) + find_library (libusb_LIBRARY + NAMES usb-1.0 + PATHS ${libusb_PC_STATIC_LIBRARY_DIRS} + ) +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) +#dump_cmake_variables ("[lL][iI][bB][uU][sS]") + +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) + add_library (libusb::libusb UNKNOWN IMPORTED) + set_target_properties (libusb::libusb PROPERTIES + IMPORTED_LOCATION "${libusb_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${libusb_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${libusb_INCLUDE_DIR}" + ) +endif () + +mark_as_advanced ( + libusb_INCLUDE_DIR + libusb_LIBRARY + ) diff --git a/CMake/Modules/Findportaudio.cmake b/CMake/Modules/Findportaudio.cmake index 5828e19df..53de86706 100644 --- a/CMake/Modules/Findportaudio.cmake +++ b/CMake/Modules/Findportaudio.cmake @@ -3,45 +3,83 @@ # Once done, this will define: # # portaudio_FOUND - system has portaudio -# portaudio_INCLUDE_DIRS - the portaudio include directories -# portaudio_LIBRARIES - link these to use portaudio -# portaudio_LIBRARY_DIRS - required shared/dynamic libraries are here +# portaudio_VERSION - The version of the portaudio library which was found +# +# and the following imported targets:: +# +# 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) -set (portaudio_LIBRARY_DIRS) - -# pkg-config? -find_path (__portaudio_pc_path NAMES portaudio-2.0.pc - PATH_SUFFIXES lib/pkgconfig lib64/pkgconfig - ) -if (__portaudio_pc_path) - set (__pc_path $ENV{PKG_CONFIG_PATH}) - list (APPEND __pc_path "${__portaudio_pc_path}") - set (ENV{PKG_CONFIG_PATH} "${__pc_path}") - unset (__pc_path CACHE) -endif () -unset (__portaudio_pc_path CACHE) - # Use pkg-config to get hints about paths, libs and, flags -unset (__pkg_config_checked_hamlib CACHE) -libfind_pkg_check_modules (PORTAUDIO portaudio-2.0) +libfind_pkg_check_modules (portaudio_PC portaudio-2.0) +# Include dir +find_path (portaudio_INCLUDE_DIR + NAMES portaudio.h + PATHS ${portaudio_PC_INCLUDE_DIRS} + ) + +# Library if (portaudio_STATIC) - set (portaudio_PROCESS_INCLUDES PORTAUDIO_STATIC_INCLUDE_DIRS) - set (portaudio_PROCESS_LIBS PORTAUDIO_STATIC_LDFLAGS) - set (portaudio_LIBRARY_DIRS ${PORTAUDIO_STATIC_LIBRARY_DIRS}) + find_library (portaudio_LIBRARY + NAMES portaudio + PATHS ${portaudio_PC_STATIC_LIBRARY_DIRS} + ) else () - set (portaudio_PROCESS_INCLUDES PORTAUDIO_INCLUDE_DIRS) - set (portaudio_PROCESS_LIBS PORTAUDIO_LDFLAGS) - set (portaudio_LIBRARY_DIRS ${PORTAUDIO_LIBRARY_DIRS}) + find_library (portaudio_LIBRARY + NAMES portaudio + PATHS ${portaudio_PC_LIBRARY_DIRS} + ) endif () +set (portaudio_PROCESS_INCLUDES portaudio_INCLUDE_DIR) +set (portaudio_PROCESS_LIBS portaudio_LIBRARY) libfind_process (portaudio) # Handle the QUIETLY and REQUIRED arguments and set PORTAUDIO_FOUND to # TRUE if all listed variables are TRUE include (FindPackageHandleStandardArgs) -find_package_handle_standard_args (portaudio DEFAULT_MSG portaudio_INCLUDE_DIRS portaudio_LIBRARIES portaudio_LIBRARY_DIRS) +find_package_handle_standard_args (portaudio + REQUIRED_VARS + portaudio_LIBRARY + portaudio_INCLUDE_DIR + VERSION_VAR portaudio_VERSION + ) + +if (portaudio_FOUND) + set (portaudio_LIBRARIES ${portaudio_LIBRARY}) + set (portaudio_INCLUDE_DIRS ${portaudio_INCLUDE_DIR}) + set (portaudio_DEFINITIONS ${portaudio_CFLAGS_OTHER}) +endif () + +if (portaudio_FOUND AND NOT TARGET portaudio::portaudio) + add_library (portaudio::portaudio UNKNOWN IMPORTED) + set_target_properties (portaudio::portaudio PROPERTIES + IMPORTED_LOCATION "${portaudio_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${portaudio_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${portaudio_INCLUDE_DIR}" + ) +endif () + +mark_as_advanced ( + portaudio_INCLUDE_DIR + portaudio_LIBRARY + ) diff --git a/CMake/Modules/Findusb.cmake b/CMake/Modules/Findusb.cmake deleted file mode 100644 index 6c519c839..000000000 --- a/CMake/Modules/Findusb.cmake +++ /dev/null @@ -1,57 +0,0 @@ -# Findusb -# ======= -# -# Find the usb library -# -# This will define the following variables:: -# -# usb_FOUND - True if the system has the usb library -# usb_VERSION - The verion of the usb library which was found -# -# and the following imported targets:: -# -# usb::usb - The libusb library - -find_package (PkgConfig) -pkg_check_modules (PC_usb QUIET usb) - -find_path (usb_INCLUDE_DIR - NAMES libusb.h - PATHS ${PC_usb_INCLUDE_DIRS} - PATH_SUFFIXES libusb-1.0 - ) -find_library (usb_LIBRARY - NAMES libusb-1.0 - PATHS $PC_usb_LIBRARY_DIRS} -) - -set (usb_VERSION ${PC_usb_VERSION}) - -include (FindPackageHandleStandardArgs) -find_package_handle_standard_args (usb - FOUND_VAR usb_FOUND - REQUIRED_VARS - usb_LIBRARY - usb_INCLUDE_DIR - VERSION_VAR usb_VERSION - ) - -if (usb_FOUND) - set (usb_LIBRARIES ${usb_LIBRARY}) - set (usb_INCLUDE_DIRS ${usb_INCLUDE_DIR}) - set (usb_DEFINITIONS ${PC_usb_CFLAGS_OTHER}) -endif () - -if (usb_FOUND AND NOT TARGET usb::usb) - add_library (usb::usb UNKNOWN IMPORTED) - set_target_properties (usb::usb PROPERTIES - IMPORTED_LOCATION "${usb_LIBRARY}" - INTERFACE_COMPILE_OPTIONS "${PC_usb_CFLAGS_OTHER}" - INTERFACE_INCLUDE_DIRECTORIES "${usb_INCLUDE_DIR}" - ) -endif () - -mark_as_advanced ( - usb_INCLUDE_DIR - usb_LIBRARY - ) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d3676c73..ea718564c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -813,12 +813,27 @@ endif (APPLE) # include (CheckTypeSize) include (CheckCSourceCompiles) +include (CheckIncludeFiles) include (CheckSymbolExists) include (generate_version_info) find_program(CTAGS ctags) find_program(ETAGS etags) +# +# Platform checks +# +check_include_files ("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS) +check_include_files (stdio.h HAVE_STDIO_H) +check_include_files (stdlib.h HAVE_STDLIB_H) +check_include_files (unistd.h HAVE_UNISTD_H) +check_include_files (sys/ioctl.h HAVE_SYS_IOCTL_H) +check_include_files (sys/types.h HAVE_SYS_TYPES_H) +check_include_files (fcntl.h HAVE_FCNTL_H) +check_include_files (sys/stat.h HAVE_SYS_STAT_H) +check_include_files ("linux/ppdev.h;linux/parport.h" HAVE_LINUX_PPDEV_H) +check_include_files ("dev/ppbus/ppi.h;dev/ppbus/ppbconf.h" HAVE_DEV_PPBUS_PPI_H) + # # Standard C Math Library # diff --git a/map65/CMakeLists.txt b/map65/CMakeLists.txt index 9e1baafeb..29f52f88f 100644 --- a/map65/CMakeLists.txt +++ b/map65/CMakeLists.txt @@ -1,6 +1,6 @@ find_package (portaudio REQUIRED) -find_package (usb REQUIRED) +find_package (libusb REQUIRED) set (map65_CXXSRCS about.cpp @@ -43,6 +43,13 @@ set (map65_UISRCS widegraph.ui ) +set (map65_C_and_CXXSRCS + ${map65_CSRCS} + ${map65_CXXSRCS} + ) +set_property (SOURCE ${map65_C_and_CXXSRCS} APPEND_STRING PROPERTY COMPILE_FLAGS " -include wsjtx_config.h") +set_property (SOURCE ${map65_C_and_CXXSRCS} APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_BINARY_DIR}/wsjtx_config.h) + # build the subdirectories add_subdirectory (libm65) @@ -51,7 +58,7 @@ qt5_wrap_ui (map65_GENUISRCS ${map65_UISRCS}) add_executable (map65 ${map65_CXXSRCS} ${map65_CSRCS} ${map65_GENUISRCS} map65.rc) target_include_directories (map65 PRIVATE ${PORTAUDIO_INCLUDE_DIRS}) -target_link_libraries (map65 m65impl ${FFTW3_LIBRARIES} Qt5::Widgets Qt5::Network ${PORTAUDIO_STATIC_LDFLAGS} usb::usb) +target_link_libraries (map65 m65impl ${FFTW3_LIBRARIES} Qt5::Widgets Qt5::Network portaudio::portaudio libusb::libusb) install ( TARGETS map65 diff --git a/map65/bandmap.cpp b/map65/bandmap.cpp index 182014713..130928d55 100644 --- a/map65/bandmap.cpp +++ b/map65/bandmap.cpp @@ -1,5 +1,6 @@ #include "bandmap.h" #include "ui_bandmap.h" +#include "../qt_helpers.hpp" #include BandMap::BandMap(QWidget *parent) : @@ -38,7 +39,7 @@ void BandMap::setText(QString t) s3=""; ui->bmTextBrowser->clear(); - QStringList lines = t.split( "\n", Qt::SkipEmptyParts ); + QStringList lines = t.split( "\n", SkipEmptyParts ); int nrows=(lines.length()+ncols-1)/ncols; for(int i=0; i #endif +#if HAVE_SYS_STAT_H +# include +#endif #if HAVE_SYS_IOCTL_H # include #endif @@ -171,6 +174,7 @@ ptt_serial(int fd, int *ntx, int *iptt) { int control = TIOCM_RTS | TIOCM_DTR; +#if defined (TIOCMBIS) && defined (TIOCMBIS) if(*ntx) { ioctl(fd, TIOCMBIS, &control); /* Set DTR and RTS */ *iptt = 1; @@ -178,6 +182,16 @@ ptt_serial(int fd, int *ntx, int *iptt) ioctl(fd, TIOCMBIC, &control); *iptt = 0; } +#else + unsigned y; + ioctl(fd, TIOCMGET, &y); + if (*ntx) { + y |= control; + } else { + y &= ~control; + } + ioctl(fd, TIOCMSET, &y); +#endif return(0); } diff --git a/map65/mainwindow.cpp b/map65/mainwindow.cpp index 89be6b771..94984e601 100644 --- a/map65/mainwindow.cpp +++ b/map65/mainwindow.cpp @@ -1520,7 +1520,13 @@ void MainWindow::guiUpdate() f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append); QTextStream out(&f); out << QDateTime::currentDateTimeUtc().toString("yyyy-MMM-dd hh:mm") - << " Tx message: " << QString::fromLatin1(msgsent) << Qt::endl; + << " Tx message: " << QString::fromLatin1(msgsent) +#if QT_VERSION >= QT_VERSION_CHECK (5, 15, 0) + << Qt::endl +#else + << endl +#endif + ; f.close(); } @@ -1543,7 +1549,13 @@ void MainWindow::guiUpdate() f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append); QTextStream out(&f); out << QDateTime::currentDateTimeUtc().toString("yyyy-MMM-dd hh:mm") - << " Tx message: " << QString::fromLatin1(msgsent) << Qt::endl; + << " Tx message: " << QString::fromLatin1(msgsent) +#if QT_VERSION >= QT_VERSION_CHECK (5, 15, 0) + << Qt::endl +#else + << endl +#endif + ; f.close(); } @@ -1885,7 +1897,13 @@ void MainWindow::on_addButton_clicked() //Add button if(f1.size()==0) { QTextStream out(&f1); - out << "ZZZZZZ" << Qt::endl; + out << "ZZZZZZ" +#if QT_VERSION >= QT_VERSION_CHECK (5, 15, 0) + << Qt::endl +#else + << endl +#endif + ; f1.close(); f1.open(QIODevice::ReadOnly | QIODevice::Text); } diff --git a/map65/messages.cpp b/map65/messages.cpp index cac60447a..f63b6473c 100644 --- a/map65/messages.cpp +++ b/map65/messages.cpp @@ -1,6 +1,7 @@ #include "messages.h" #include "ui_messages.h" #include "mainwindow.h" +#include "../qt_helpers.hpp" Messages::Messages(QWidget *parent) : QDialog(parent), @@ -31,7 +32,7 @@ void Messages::setText(QString t, QString t2) ui->messagesTextBrowser->setStyleSheet(s); ui->messagesTextBrowser->clear(); - QStringList lines = t.split( "\n", Qt::SkipEmptyParts ); + QStringList lines = t.split( "\n", SkipEmptyParts ); foreach( QString line, lines ) { QString t1=line.mid(0,50); int ncq=t1.indexOf(" CQ "); diff --git a/map65/widegraph.cpp b/map65/widegraph.cpp index ee60e6925..d918ffb51 100644 --- a/map65/widegraph.cpp +++ b/map65/widegraph.cpp @@ -298,7 +298,6 @@ void WideGraph::on_fCenterLineEdit_editingFinished() void WideGraph::on_pbSetRxHardware_clicked() { -#ifdef WIN32 int iret=set570(m_mult570*(1.0+0.000001*m_cal570)*m_dForceCenterFreq); if(iret != 0) { QMessageBox mb; @@ -306,12 +305,10 @@ void WideGraph::on_pbSetRxHardware_clicked() if(iret==-2) mb.setText("Frequency out of permitted range."); mb.exec(); } -#endif } void WideGraph::initIQplus() { -#ifdef WIN32 int iret=set570(288.0); if(iret != 0) { QMessageBox mb; @@ -321,7 +318,6 @@ void WideGraph::initIQplus() } else { on_pbSetRxHardware_clicked(); } -#endif } void WideGraph::on_cbSpec2d_toggled(bool b) @@ -348,7 +344,6 @@ void WideGraph::on_cbLockTxRx_stateChanged(int n) void WideGraph::rx570() { double f=m_mult570*(1.0+0.000001*m_cal570)*m_dForceCenterFreq; -#ifdef WIN32 int iret=set570(f); if(iret != 0) { QMessageBox mb; @@ -356,7 +351,6 @@ void WideGraph::rx570() if(iret==-2) mb.setText("Frequency out of permitted range."); mb.exec(); } -#endif } void WideGraph::tx570() @@ -367,7 +361,6 @@ void WideGraph::tx570() // double f1=m_mult570Tx*(1.0+0.000001*m_cal570) * f; double f1=m_mult570Tx*(1.0+0.000001*m_cal570) * (f - m_TxOffset); -#ifdef WIN32 int iret=set570(f1); if(iret != 0) { QMessageBox mb; @@ -375,7 +368,6 @@ void WideGraph::tx570() if(iret==-2) mb.setText("Frequency out of permitted range."); mb.exec(); } -#endif } void WideGraph::updateFreqLabel() diff --git a/map65/widegraph.h b/map65/widegraph.h index 3fdcc6448..c4e201ab0 100644 --- a/map65/widegraph.h +++ b/map65/widegraph.h @@ -84,8 +84,6 @@ private: Ui::WideGraph *ui; }; -#ifdef WIN32 extern int set570(double freq_MHz); -#endif #endif // WIDEGRAPH_H diff --git a/wsjtx_config.h.in b/wsjtx_config.h.in index c54819ea4..592d9b6b7 100644 --- a/wsjtx_config.h.in +++ b/wsjtx_config.h.in @@ -32,6 +32,16 @@ extern "C" { #cmakedefine01 HAVE_HAMLIB_OLD_CACHING #cmakedefine01 HAVE_HAMLIB_CACHING +#cmakedefine HAVE_STDIO_H 1 +#cmakedefine STDC_HEADERS 1 +#cmakedefine HAVE_STDLIB_H 1 +#cmakedefine HAVE_UNISTD_H 1 +#cmakedefine HAVE_SYS_IOCTL_H 1 +#cmakedefine HAVE_FCNTL_H 1 +#cmakedefine HAVE_SYS_STAT_H 1 +#cmakedefine HAVE_LINUX_PPDEV_H 1 +#cmakedefine HAVE_DEV_PPBUS_PPI_H 1 + #cmakedefine01 WSJT_SHARED_RUNTIME #cmakedefine01 WSJT_SOFT_KEYING #cmakedefine01 WSJT_ENABLE_EXPERIMENTAL_FEATURES