From 2459c7c4bac1c8636b611551d7b81b0496816d4b Mon Sep 17 00:00:00 2001 From: Egor Chesakov <33474695+echesakov@users.noreply.github.com> Date: Thu, 7 May 2020 11:56:16 -0700 Subject: [PATCH] [rtlsdr] Add new port (#10901) * Add rtlsdr port * Update ci.baseline.txt * Update to use github mirror in portfile.cmake Co-authored-by: Egor Chesakov --- ports/rtlsdr/CONTROL | 6 ++ ports/rtlsdr/Compile-with-msvc.patch | 88 ++++++++++++++++++++++++++++ ports/rtlsdr/Findlibusb.cmake | 17 ++++++ ports/rtlsdr/portfile.cmake | 48 +++++++++++++++ scripts/ci.baseline.txt | 5 ++ 5 files changed, 164 insertions(+) create mode 100644 ports/rtlsdr/CONTROL create mode 100644 ports/rtlsdr/Compile-with-msvc.patch create mode 100644 ports/rtlsdr/Findlibusb.cmake create mode 100644 ports/rtlsdr/portfile.cmake diff --git a/ports/rtlsdr/CONTROL b/ports/rtlsdr/CONTROL new file mode 100644 index 0000000000..c276dc3170 --- /dev/null +++ b/ports/rtlsdr/CONTROL @@ -0,0 +1,6 @@ +Source: rtlsdr +Version: 2020-04-16 +Homepage: https://osmocom.org/projects/rtl-sdr +Description: rtl-sdr is a library that turns your Realtek RTL2832 based DVB dongle into a SDR receiver +Build-Depends: libusb, pthreads (windows) +Supports: windows&(x86|x64) diff --git a/ports/rtlsdr/Compile-with-msvc.patch b/ports/rtlsdr/Compile-with-msvc.patch new file mode 100644 index 0000000000..5374ed4126 --- /dev/null +++ b/ports/rtlsdr/Compile-with-msvc.patch @@ -0,0 +1,88 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 2def354..674ff2d 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -66,6 +66,12 @@ endif() + ######################################################################## + # Find build dependencies + ######################################################################## ++if(MSVC) ++find_package(pthreads) ++find_package(libusb) ++include_directories(${PThreads4W_INCLUDE_DIR}) ++include_directories(${LIBUSB_INCLUDE_DIRS}) ++else() + if(WIN32 AND NOT MINGW) + set(THREADS_USE_PTHREADS_WIN32 true) + endif() +@@ -79,6 +85,7 @@ endif() + if(NOT THREADS_FOUND) + message(FATAL_ERROR "pthreads(-win32) required to compile rtl-sdr") + endif() ++endif() + + ######################################################################## + # Create uninstall target +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 33faee7..fda4612 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -20,7 +20,11 @@ + ######################################################################## + add_library(rtlsdr SHARED librtlsdr.c + tuner_e4k.c tuner_fc0012.c tuner_fc0013.c tuner_fc2580.c tuner_r82xx.c) ++if(MSVC) ++target_link_libraries(rtlsdr ${LIBUSB_LIBRARIES}) ++else() + target_link_libraries(rtlsdr PkgConfig::LIBUSB) ++endif() + target_include_directories(rtlsdr PUBLIC + $ + $ # /include +@@ -36,7 +40,11 @@ generate_export_header(rtlsdr) + ######################################################################## + add_library(rtlsdr_static STATIC librtlsdr.c + tuner_e4k.c tuner_fc0012.c tuner_fc0013.c tuner_fc2580.c tuner_r82xx.c) ++if(MSVC) ++target_link_libraries(rtlsdr_static ${LIBUSB_LIBRARIES}) ++else() + target_link_libraries(rtlsdr_static PkgConfig::LIBUSB) ++endif() + target_include_directories(rtlsdr_static PUBLIC + $ + $ # /include +@@ -58,8 +66,8 @@ IF(MSVC) + ${CMAKE_CURRENT_SOURCE_DIR}/rtlsdr.rc.in + ${CMAKE_CURRENT_BINARY_DIR}/rtlsdr.rc + @ONLY) +- target_sources(rtlsdr ${CMAKE_CURRENT_BINARY_DIR}/rtlsdr.rc) +- target_sources(rtlsdr_static ${CMAKE_CURRENT_BINARY_DIR}/rtlsdr.rc) ++ target_sources(rtlsdr PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/rtlsdr.rc) ++ target_sources(rtlsdr_static PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/rtlsdr.rc) + ENDIF(MSVC) + + ######################################################################## +@@ -77,6 +85,11 @@ add_library(libgetopt_static STATIC + target_link_libraries(convenience_static + rtlsdr + ) ++if(MSVC) ++target_link_libraries(convenience_static ++ ${PThreads4W_LIBRARY} ++) ++endif() + endif() + + ######################################################################## +diff --git a/src/rtl_tcp.c b/src/rtl_tcp.c +index 562198f..b4bfa51 100644 +--- a/src/rtl_tcp.c ++++ b/src/rtl_tcp.c +@@ -35,6 +35,7 @@ + #include + #else + #include ++#include + #include "getopt/getopt.h" + #endif + diff --git a/ports/rtlsdr/Findlibusb.cmake b/ports/rtlsdr/Findlibusb.cmake new file mode 100644 index 0000000000..052ae21dfc --- /dev/null +++ b/ports/rtlsdr/Findlibusb.cmake @@ -0,0 +1,17 @@ +find_path( + LIBUSB_INCLUDE_DIRS + NAMES libusb.h + PATH_SUFFIXES libusb-1.0 +) + +find_library( + LIBUSB_LIBRARIES + NAMES libusb-1.0 +) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args( + LIBUSB + REQUIRED_VARS LIBUSB_LIBRARIES LIBUSB_INCLUDE_DIRS +) diff --git a/ports/rtlsdr/portfile.cmake b/ports/rtlsdr/portfile.cmake new file mode 100644 index 0000000000..925a076f8e --- /dev/null +++ b/ports/rtlsdr/portfile.cmake @@ -0,0 +1,48 @@ +vcpkg_fail_port_install( + ON_TARGET "uwp" "linux" "osx" "android" "freebsd" + ON_ARCH "arm" "arm64" +) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO osmocom/rtl-sdr + REF d794155ba65796a76cd0a436f9709f4601509320 + SHA512 21fe10f1dbecca651650f03d1008560930fac439d220c33b4a23acce98d78d8476ff200765eed8cfa6cddde761d45f7ba36c8b5bc3662aa85819172830ea4938 + HEAD_REF master + PATCHES Compile-with-msvc.patch +) + +file( + COPY ${CMAKE_CURRENT_LIST_DIR}/Findlibusb.cmake + DESTINATION ${SOURCE_PATH}/cmake/Modules +) + +vcpkg_configure_cmake( + SOURCE_PATH ${SOURCE_PATH} + PREFER_NINJA +) + +vcpkg_install_cmake() +vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake/rtlsdr) +vcpkg_copy_pdbs() + +file( + INSTALL ${SOURCE_PATH}/COPYING + DESTINATION ${CURRENT_PACKAGES_DIR}/share/rtlsdr + RENAME copyright +) + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") + +if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin) +else() + file(GLOB DEBUG_TOOLS "${CURRENT_PACKAGES_DIR}/debug/bin/*.exe") + file(GLOB RELEASE_TOOLS "${CURRENT_PACKAGES_DIR}/bin/*.exe") + file( + INSTALL ${RELEASE_TOOLS} + DESTINATION ${CURRENT_PACKAGES_DIR}/tools/${PORT} + ) + vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT}) + file(REMOVE ${DEBUG_TOOLS} ${RELEASE_TOOLS}) +endif() diff --git a/scripts/ci.baseline.txt b/scripts/ci.baseline.txt index 82c721aa68..435dc8f49a 100644 --- a/scripts/ci.baseline.txt +++ b/scripts/ci.baseline.txt @@ -1584,6 +1584,11 @@ rpclib:x64-uwp=fail rpclib:x64-windows=ignore rpclib:x86-windows=ignore rpclib:x64-windows-static=ignore +rtlsdr:x64-uwp=fail +rtlsdr:arm64-windows=fail +rtlsdr:arm-uwp=fail +rtlsdr:x64-linux=fail +rtlsdr:x64-osx=fail rttr:arm-uwp=fail rttr:x64-uwp=fail rxspencer:x64-uwp=fail