Skip to content

Commit

Permalink
Merge pull request #2146 from godsic/bugfix/soapy-cmake
Browse files Browse the repository at this point in the history
Fix and refactor FindSoapySDR.cmake
  • Loading branch information
f4exb authored Jun 2, 2024
2 parents f6425af + 4252592 commit 209e3a9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
35 changes: 18 additions & 17 deletions cmake/Modules/FindSoapySDR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,45 @@ if(NOT SOAPYSDR_FOUND)
set(${VERSION} "${CMAKE_MATCH_1}" PARENT_SCOPE)
endfunction(_SOAPY_SDR_GET_ABI_VERSION)

pkg_search_module (LIBSOAPYSDR_PKG soapysdr>=0.4.0 SoapySDR>=0.4.0)
pkg_search_module (SOAPYSDR SoapySDR>=0.4.0)

if(NOT LIBSOAPYSDR_PKG_FOUND OR (DEFINED SOAPYSDR_DIR))
if(NOT SOAPYSDR_FOUND OR (DEFINED SOAPYSDR_DIR))

find_path (SOAPYSDR_INCLUDE_DIR
find_path (SOAPYSDR_INCLUDE_DIRS
NAMES SoapySDR/Version.h
HINTS ${SOAPYSDR_DIR}/include
${LIBSOAPYSDR_PKG_INCLUDE_DIRS}
PATHS /usr/include
/usr/local/include
)
)

find_library (SOAPYSDR_LIBRARY
find_library (SOAPYSDR_LINK_LIBRARIES
NAMES SoapySDR
HINTS ${SOAPYSDR_DIR}/lib
${SOAPYSDR_DIR}/lib64
${CMAKE_INSTALL_PREFIX}/lib
${CMAKE_INSTALL_PREFIX}/lib64
${LIBSOAPYSDR_PKG_LIBRARY_DIRS}
PATHS /usr/local/lib
/usr/local/lib64
/usr/lib
/usr/lib64
)
)

if (SOAPYSDR_INCLUDE_DIR AND SOAPYSDR_LIBRARY)
if (SOAPYSDR_INCLUDE_DIRS AND SOAPYSDR_LINK_LIBRARIES)
set(SOAPYSDR_FOUND TRUE)
# get the root of SoapySDR; used on cpack
string(REGEX REPLACE "/lib/.*${CMAKE_SHARED_LIBRARY_SUFFIX}" "" SOAPYSDR_ROOT ${SOAPYSDR_LIBRARY})
# get the soapy version; to using FindPkgConfig because we can use SOAPYSDR_DIR
_SOAPY_SDR_GET_ABI_VERSION(SOAPYSDR_ABI_VERSION ${SOAPYSDR_INCLUDE_DIR})
message (STATUS "Found SoapySDR: ${SOAPYSDR_INCLUDE_DIR}, ${SOAPYSDR_LIBRARY}")
else()
message (STATUS "SoapySDR not found")
string(REGEX REPLACE "/lib/.*${CMAKE_SHARED_LIBRARY_SUFFIX}" "" SOAPYSDR_LIBDIR ${SOAPYSDR_LINK_LIBRARIES})
# get the soapy version
_SOAPY_SDR_GET_ABI_VERSION(SOAPYSDR_VERSION ${SOAPYSDR_INCLUDE_DIRS})
endif()

mark_as_advanced(SOAPYSDR_INCLUDE_DIR SOAPYSDR_LIBRARY SOAPYSDR_ROOT SOAPYSDR_ABI_VERSION)
endif(NOT SOAPYSDR_FOUND OR (DEFINED SOAPYSDR_DIR))

endif(NOT LIBSOAPYSDR_PKG_FOUND OR (DEFINED SOAPYSDR_DIR))
if (SOAPYSDR_FOUND)
message (STATUS "Found SoapySDR: version ${SOAPYSDR_VERSION}, ${SOAPYSDR_LIBDIR}, ${SOAPYSDR_INCLUDE_DIRS}, ${SOAPYSDR_LINK_LIBRARIES}")
else()
message (STATUS "SoapySDR not found")
endif()

mark_as_advanced(SOAPYSDR_INCLUDE_DIRS SOAPYSDR_LINK_LIBRARIES SOAPYSDR_LIBDIR SOAPYSDR_VERSION)

endif(NOT SOAPYSDR_FOUND)
4 changes: 2 additions & 2 deletions cmake/cpack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ if(APPLE AND BUNDLE AND BUILD_GUI)
# probably libmirsdrapi-rsp.dylib can't be re-distribuited
# we remove the file at the end of fixup_bundle
if(ENABLE_SOAPYSDR AND SOAPYSDR_FOUND)
set(SOAPY_SDR_MOD_PATH "${SOAPYSDR_ROOT}/lib/SoapySDR/modules${SOAPYSDR_ABI_VERSION}")
set(SOAPY_SDR_MOD_PATH "${SOAPYSDR_LIBDIR}/lib/SoapySDR/modules${SOAPYSDR_VERSION}")
file(GLOB SOAPY_MODS ${SOAPY_SDR_MOD_PATH}/*.so)
foreach(SOAPY_MOD_FILE ${SOAPY_MODS})
install( FILES "${SOAPY_MOD_FILE}"
DESTINATION "../Frameworks/SoapySDR/modules${SOAPYSDR_ABI_VERSION}"
DESTINATION "../Frameworks/SoapySDR/modules${SOAPYSDR_VERSION}"
COMPONENT Runtime
)
endforeach()
Expand Down
4 changes: 2 additions & 2 deletions devices/soapysdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(soapysdrdevice_HEADERS
)

include_directories(
${SOAPYSDR_INCLUDE_DIR}
${SOAPYSDR_INCLUDE_DIRS}
)

add_library(soapysdrdevice SHARED
Expand All @@ -26,7 +26,7 @@ set_target_properties(soapysdrdevice
PROPERTIES DEFINE_SYMBOL "devices_EXPORTS")

target_link_libraries(soapysdrdevice
${SOAPYSDR_LIBRARY}
${SOAPYSDR_LINK_LIBRARIES}
sdrbase
)

Expand Down
8 changes: 4 additions & 4 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ if (WIN32 OR APPLE)

if (ENABLE_SOAPYSDR)
if (WIN32)
set(SOAPYSDR_LIBRARY "${SDRANGEL_BINARY_LIB_DIR}/SoapySDR.lib" CACHE INTERNAL "")
set(SOAPYSDR_LINK_LIBRARIES "${SDRANGEL_BINARY_LIB_DIR}/SoapySDR.lib" CACHE INTERNAL "")
endif ()
ExternalProject_Add(soapysdr
GIT_REPOSITORY https://github.com/pothosware/SoapySDR.git
Expand All @@ -1235,20 +1235,20 @@ if (WIN32 OR APPLE)
-DENABLE_PYTHON=OFF
-DENABLE_PYTHON3=OFF
-DENABLE_TESTS=OFF
BUILD_BYPRODUCTS "${SOAPYSDR_LIBRARY}"
BUILD_BYPRODUCTS "${SOAPYSDR_LINK_LIBRARIES}"
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config $<CONFIG> -- SoapySDR
INSTALL_COMMAND ""
TEST_COMMAND ""
)
ExternalProject_Get_Property(soapysdr source_dir binary_dir)
set_global_cache(SOAPYSDR_FOUND ON)
set(SOAPYSDR_EXTERNAL ON CACHE INTERNAL "")
set(SOAPYSDR_INCLUDE_DIR "${source_dir}/include" CACHE INTERNAL "")
set(SOAPYSDR_INCLUDE_DIRS "${source_dir}/include" CACHE INTERNAL "")
if (WIN32)
install(FILES "${SDRANGEL_BINARY_BIN_DIR}/SoapySDR${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION "${INSTALL_LIB_DIR}")
install(DIRECTORY "${SDRANGEL_BINARY_LIB_DIR}/SoapySDR" DESTINATION "${INSTALL_LIB_DIR}/lib")
elseif (APPLE)
set(SOAPYSDR_LIBRARY "${binary_dir}/lib/libSoapySDR${CMAKE_SHARED_LIBRARY_SUFFIX}" CACHE INTERNAL "")
set(SOAPYSDR_LINK_LIBRARIES "${binary_dir}/lib/libSoapySDR${CMAKE_SHARED_LIBRARY_SUFFIX}" CACHE INTERNAL "")
install(DIRECTORY "${binary_dir}/lib/" DESTINATION "${INSTALL_LIB_DIR}"
FILES_MATCHING PATTERN "libSoapySDR*${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(MACOS_EXTERNAL_LIBS_FIXUP "${MACOS_EXTERNAL_LIBS_FIXUP};${binary_dir}/lib/")
Expand Down
4 changes: 2 additions & 2 deletions plugins/samplesink/soapysdroutput/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(soapysdroutput_HEADERS
include_directories(
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
${CMAKE_SOURCE_DIR}/devices
${SOAPYSDR_INCLUDE_DIR}
${SOAPYSDR_INCLUDE_DIRS}
)

if(NOT SERVER_MODE)
Expand Down Expand Up @@ -55,7 +55,7 @@ target_link_libraries(${TARGET_NAME}
sdrbase
${TARGET_LIB_GUI}
swagger
${SOAPYSDR_LIBRARY}
${SOAPYSDR_LINK_LIBRARIES}
soapysdrdevice
)

Expand Down
4 changes: 2 additions & 2 deletions plugins/samplesource/soapysdrinput/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(soapysdrinput_HEADERS
include_directories(
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
${CMAKE_SOURCE_DIR}/devices
${SOAPYSDR_INCLUDE_DIR}
${SOAPYSDR_INCLUDE_DIRS}
)

if(NOT SERVER_MODE)
Expand Down Expand Up @@ -55,7 +55,7 @@ target_link_libraries(${TARGET_NAME}
sdrbase
${TARGET_LIB_GUI}
swagger
${SOAPYSDR_LIBRARY}
${SOAPYSDR_LINK_LIBRARIES}
soapysdrdevice
)

Expand Down

0 comments on commit 209e3a9

Please sign in to comment.