[PATCH] cmake: Go back CMake min ver. 3.8 by removing need for CMP0079

Piotr Krysik ptrkrysik at gmail.com
Mon Feb 17 08:11:25 UTC 2020


CMake 3.13 is not present in older (~2 years old)
Linux distributions and GNU Radio requires min CMake
version 3.8.

All that is needed in order to avoid bumping CMake version
is to not use 'target_link_libraries' in subdirectories.
Here this is done by creating a list of needed
libraries and adding them for linking at the end (like
it was done in gr-osmosdr before porting to GNU Radio 3.8).

One thing that is lost here is 'PRIVATE' statement in case
of FCD libraries linking.
---
 CMakeLists.txt               | 3 +--
 lib/CMakeLists.txt           | 7 ++++---
 lib/airspy/CMakeLists.txt    | 2 +-
 lib/airspyhf/CMakeLists.txt  | 2 +-
 lib/bladerf/CMakeLists.txt   | 2 +-
 lib/fcd/CMakeLists.txt       | 5 +++--
 lib/file/CMakeLists.txt      | 2 +-
 lib/freesrp/CMakeLists.txt   | 2 +-
 lib/hackrf/CMakeLists.txt    | 2 +-
 lib/miri/CMakeLists.txt      | 2 +-
 lib/osmosdr/CMakeLists.txt   | 2 +-
 lib/redpitaya/CMakeLists.txt | 2 +-
 lib/rtl/CMakeLists.txt       | 2 +-
 lib/rtl_tcp/CMakeLists.txt   | 2 +-
 lib/sdrplay/CMakeLists.txt   | 2 +-
 lib/soapy/CMakeLists.txt     | 2 +-
 lib/uhd/CMakeLists.txt       | 2 +-
 17 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7a2cf9d..cf24991 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,14 +20,13 @@
 ########################################################################
 # Project setup
 ########################################################################
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.8)
 include(GNUInstallDirs)
 project(gr-osmosdr CXX C)
 enable_testing()
 
 #policy setup
 cmake_policy(SET CMP0011 NEW)
-cmake_policy(SET CMP0079 NEW)
 
 #select the release build type by default to get optimization flags
 if(NOT CMAKE_BUILD_TYPE)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index d04cb1d..f8c9db7 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -41,7 +41,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
 endif()
 
 add_library(gnuradio-osmosdr SHARED)
-target_link_libraries(gnuradio-osmosdr ${Boost_LIBRARIES} gnuradio::gnuradio-runtime)
+list(APPEND gr_osmosdr_libs ${Boost_LIBRARIES} gnuradio::gnuradio-runtime)
 target_include_directories(gnuradio-osmosdr
     PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
     PUBLIC ${Boost_INCLUDE_DIRS}
@@ -100,7 +100,7 @@ CHECK_CXX_SOURCE_COMPILES("
 if(HAVE_CLOCK_GETTIME)
     message(STATUS "  High resolution timing supported through clock_gettime.")
     set(TIME_SPEC_DEFS HAVE_CLOCK_GETTIME)
-    target_link_libraries(gnuradio-osmosdr "-lrt")
+    list(APPEND gr_osmosdr_libs "-lrt")
 elseif(HAVE_MACH_ABSOLUTE_TIME)
     message(STATUS "  High resolution timing supported through mach_absolute_time.")
     set(TIME_SPEC_DEFS HAVE_MACH_ABSOLUTE_TIME)
@@ -124,7 +124,7 @@ GR_REGISTER_COMPONENT("Osmocom IQ Imbalance Correction" ENABLE_IQBALANCE gnuradi
 if(ENABLE_IQBALANCE)
     add_definitions(-DHAVE_IQBALANCE=1)
     target_include_directories(gnuradio-osmosdr PRIVATE ${gnuradio-iqbalance_INCLUDE_DIRS})
-    target_link_libraries(gnuradio-osmosdr gnuradio::gnuradio-iqbalance)
+    list(APPEND gr_osmosdr_libs gnuradio::gnuradio-iqbalance)
 endif(ENABLE_IQBALANCE)
 
 ########################################################################
@@ -263,6 +263,7 @@ configure_file(
 # Finalize target
 ########################################################################
 set_target_properties(gnuradio-osmosdr PROPERTIES SOURCES "${gr_osmosdr_srcs}")
+target_link_libraries(gnuradio-osmosdr ${gr_osmosdr_libs})
 
 ########################################################################
 # Install built library files
diff --git a/lib/airspy/CMakeLists.txt b/lib/airspy/CMakeLists.txt
index 4a60138..848a91a 100644
--- a/lib/airspy/CMakeLists.txt
+++ b/lib/airspy/CMakeLists.txt
@@ -26,7 +26,7 @@ target_include_directories(gnuradio-osmosdr PRIVATE
     ${LIBAIRSPY_INCLUDE_DIRS}
 )
 
-target_link_libraries(gnuradio-osmosdr
+list(APPEND gr_osmosdr_libs
     gnuradio::gnuradio-filter
     ${Gnuradio-blocks_LIBRARIES}
     ${LIBAIRSPY_LIBRARIES}
diff --git a/lib/airspyhf/CMakeLists.txt b/lib/airspyhf/CMakeLists.txt
index 122a67c..e2c63d7 100644
--- a/lib/airspyhf/CMakeLists.txt
+++ b/lib/airspyhf/CMakeLists.txt
@@ -26,7 +26,7 @@ target_include_directories(gnuradio-osmosdr PRIVATE
     ${LIBAIRSPYHF_INCLUDE_DIRS}
 )
 
-target_link_libraries(gnuradio-osmosdr
+list(APPEND gr_osmosdr_libs
     ${Gnuradio-blocks_LIBRARIES}
     ${LIBAIRSPYHF_LIBRARIES}
 )
diff --git a/lib/bladerf/CMakeLists.txt b/lib/bladerf/CMakeLists.txt
index e09a4d7..6cf2f7d 100644
--- a/lib/bladerf/CMakeLists.txt
+++ b/lib/bladerf/CMakeLists.txt
@@ -27,7 +27,7 @@ target_include_directories(gnuradio-osmosdr PRIVATE
     ${Volk_INCLUDE_DIRS}
 )
 
-target_link_libraries(gnuradio-osmosdr
+list(APPEND gr_osmosdr_libs
     ${LIBBLADERF_LIBRARIES}
     ${Volk_LIBRARIES}
 )
diff --git a/lib/fcd/CMakeLists.txt b/lib/fcd/CMakeLists.txt
index 146191f..80f88d3 100644
--- a/lib/fcd/CMakeLists.txt
+++ b/lib/fcd/CMakeLists.txt
@@ -29,7 +29,8 @@ if(ENABLE_FCD)
     target_include_directories(gnuradio-osmosdr PRIVATE
         ${Gnuradio-fcd_INCLUDE_DIRS}
     )
-    target_link_libraries(gnuradio-osmosdr PRIVATE
+
+    list(APPEND gr_osmosdr_libs
         ${Gnuradio-fcd_LIBRARIES}
     )
 endif(ENABLE_FCD)
@@ -38,7 +39,7 @@ if(ENABLE_FCDPP)
     target_include_directories(gnuradio-osmosdr PRIVATE
         ${Gnuradio-fcdpp_INCLUDE_DIRS}
     )
-    target_link_libraries(gnuradio-osmosdr PRIVATE
+    list(APPEND gr_osmosdr_libs
         ${Gnuradio-fcdpp_LIBRARIES}
     )
 endif(ENABLE_FCDPP)
diff --git a/lib/file/CMakeLists.txt b/lib/file/CMakeLists.txt
index 2897589..98e60f7 100644
--- a/lib/file/CMakeLists.txt
+++ b/lib/file/CMakeLists.txt
@@ -25,7 +25,7 @@ target_include_directories(gnuradio-osmosdr PRIVATE
     ${CMAKE_CURRENT_SOURCE_DIR}
 )
 
-target_link_libraries(gnuradio-osmosdr
+list(APPEND gr_osmosdr_libs
     gnuradio::gnuradio-blocks
 )
 message(STATUS ${gnuradio-blocks_LIBRARIES})
diff --git a/lib/freesrp/CMakeLists.txt b/lib/freesrp/CMakeLists.txt
index 85eb64d..ec1ed85 100644
--- a/lib/freesrp/CMakeLists.txt
+++ b/lib/freesrp/CMakeLists.txt
@@ -26,7 +26,7 @@ target_include_directories(gnuradio-osmosdr PRIVATE
     ${LIBFREESRP_INCLUDE_DIRS}
 )
 
-target_link_libraries(gnuradio-osmosdr
+list(APPEND gr_osmosdr_libs
     ${LIBFREESRP_LIBRARIES}
 )
 
diff --git a/lib/hackrf/CMakeLists.txt b/lib/hackrf/CMakeLists.txt
index d099b41..32dd0ea 100644
--- a/lib/hackrf/CMakeLists.txt
+++ b/lib/hackrf/CMakeLists.txt
@@ -26,7 +26,7 @@ target_include_directories(gnuradio-osmosdr PRIVATE
     ${LIBHACKRF_INCLUDE_DIRS}
 )
 
-target_link_libraries(gnuradio-osmosdr
+list(APPEND gr_osmosdr_libs
     ${LIBHACKRF_LIBRARIES}
 )
 
diff --git a/lib/miri/CMakeLists.txt b/lib/miri/CMakeLists.txt
index 5415a9d..e999927 100644
--- a/lib/miri/CMakeLists.txt
+++ b/lib/miri/CMakeLists.txt
@@ -26,7 +26,7 @@ target_include_directories(gnuradio-osmosdr PRIVATE
     ${LIBMIRISDR_INCLUDE_DIRS}
 )
 
-target_link_libraries(gnuradio-osmosdr
+list(APPEND gr_osmosdr_libs
     ${LIBMIRISDR_LIBRARIES}
 )
 
diff --git a/lib/osmosdr/CMakeLists.txt b/lib/osmosdr/CMakeLists.txt
index 83d6dbc..c9dabdd 100644
--- a/lib/osmosdr/CMakeLists.txt
+++ b/lib/osmosdr/CMakeLists.txt
@@ -26,7 +26,7 @@ target_include_directories(gnuradio-osmosdr PRIVATE
     ${LIBOSMOSDR_INCLUDE_DIRS}
 )
 
-target_link_libraries(gnuradio-osmosdr
+list(APPEND gr_osmosdr_libs
     ${LIBOSMOSDR_LIBRARIES}
 )
 
diff --git a/lib/redpitaya/CMakeLists.txt b/lib/redpitaya/CMakeLists.txt
index 0d13c48..695ef5b 100644
--- a/lib/redpitaya/CMakeLists.txt
+++ b/lib/redpitaya/CMakeLists.txt
@@ -25,7 +25,7 @@ target_include_directories(gnuradio-osmosdr PRIVATE
     ${CMAKE_CURRENT_SOURCE_DIR}
 )
 
-target_link_libraries(gnuradio-osmosdr
+list(APPEND gr_osmosdr_libs
     ${Gnuradio-blocks_LIBRARIES}
 )
 
diff --git a/lib/rtl/CMakeLists.txt b/lib/rtl/CMakeLists.txt
index ad3a7dc..d70338e 100644
--- a/lib/rtl/CMakeLists.txt
+++ b/lib/rtl/CMakeLists.txt
@@ -26,7 +26,7 @@ target_include_directories(gnuradio-osmosdr PRIVATE
     ${LIBRTLSDR_INCLUDE_DIRS}
 )
 
-target_link_libraries(gnuradio-osmosdr
+list(APPEND gr_osmosdr_libs
     ${LIBRTLSDR_LIBRARIES}
 )
 
diff --git a/lib/rtl_tcp/CMakeLists.txt b/lib/rtl_tcp/CMakeLists.txt
index 7acb614..f723668 100644
--- a/lib/rtl_tcp/CMakeLists.txt
+++ b/lib/rtl_tcp/CMakeLists.txt
@@ -25,7 +25,7 @@ target_include_directories(gnuradio-osmosdr PRIVATE
     ${CMAKE_CURRENT_SOURCE_DIR}
 )
 
-target_link_libraries(gnuradio-osmosdr
+list(APPEND gr_osmosdr_libs
     ${Gnuradio-blocks_LIBRARIES}
 )
 
diff --git a/lib/sdrplay/CMakeLists.txt b/lib/sdrplay/CMakeLists.txt
index c310f5d..6b73cbf 100644
--- a/lib/sdrplay/CMakeLists.txt
+++ b/lib/sdrplay/CMakeLists.txt
@@ -26,7 +26,7 @@ target_include_directories(gnuradio-osmosdr PRIVATE
     ${LIBSDRPLAY_INCLUDE_DIRS}
 )
 
-target_link_libraries(gnuradio-osmosdr
+list(APPEND gr_osmosdr_libs
     ${LIBSDRPLAY_LIBRARIES}
 )
 
diff --git a/lib/soapy/CMakeLists.txt b/lib/soapy/CMakeLists.txt
index d2a725b..5277483 100644
--- a/lib/soapy/CMakeLists.txt
+++ b/lib/soapy/CMakeLists.txt
@@ -26,7 +26,7 @@ target_include_directories(gnuradio-osmosdr PRIVATE
     ${SoapySDR_INCLUDE_DIRS}
 )
 
-target_link_libraries(gnuradio-osmosdr
+list(APPEND gr_osmosdr_libs
     ${SoapySDR_LIBRARIES}
 )
 
diff --git a/lib/uhd/CMakeLists.txt b/lib/uhd/CMakeLists.txt
index f9fb196..db089f5 100644
--- a/lib/uhd/CMakeLists.txt
+++ b/lib/uhd/CMakeLists.txt
@@ -27,7 +27,7 @@ target_include_directories(gnuradio-osmosdr PRIVATE
     ${UHD_INCLUDE_DIRS}
 )
 
-target_link_libraries(gnuradio-osmosdr
+list(APPEND gr_osmosdr_libs
     gnuradio::gnuradio-uhd
     ${UHD_LIBRARIES}
 )
-- 
2.7.4



More information about the osmocom-sdr mailing list