File: convert-to-modern-cmake-gnuradio-3.8-patterns

package info (click to toggle)
gr-iqbal 0.38-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,220 kB
  • sloc: python: 9,276; ansic: 801; cpp: 213; makefile: 72; sh: 56
file content (289 lines) | stat: -rw-r--r-- 11,517 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
From bef18bfa16a2b86ba8052401a5cad77619d97f67 Mon Sep 17 00:00:00 2001
From: "A. Maitland Bottoms" <bottoms@debian.org>
Date: Sun, 25 Aug 2019 19:59:26 -0400
Subject: [PATCH 2/4] convert to modern cmake gnuradio 3.8 patterns

---
 CMakeLists.txt                      | 65 ++++++++++++++++++++++-------
 cmake/Modules/targetConfig.cmake.in | 26 ++++++++++++
 lib/CMakeLists.txt                  | 46 ++++++++++++--------
 swig/CMakeLists.txt                 | 22 ++++++----
 4 files changed, 119 insertions(+), 40 deletions(-)
 create mode 100644 cmake/Modules/targetConfig.cmake.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1306830..90f464d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,7 +21,8 @@
 ########################################################################
 # Project setup
 ########################################################################
-cmake_minimum_required(VERSION 2.6)
+cmake_minimum_required(VERSION 3.8)
+include(GNUInstallDirs)
 project(gr-iqbalance CXX C)
 enable_testing()
 
@@ -32,7 +33,18 @@ if(NOT CMAKE_BUILD_TYPE)
 endif(NOT CMAKE_BUILD_TYPE)
 set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "")
 
-list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
+########################################################################
+# set search path for cmake modules to OOT, Gnuradio
+########################################################################
+set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
+find_package(Gnuradio "3.8" REQUIRED)
+
+# Set the version information here
+set(VERSION_INFO_MAJOR_VERSION 3)
+set(VERSION_INFO_API_COMPAT    8)
+set(VERSION_INFO_MINOR_VERSION 0)
+set(VERSION_INFO_MAINT_VERSION "")
+include(GrVersion) #setup version info
 
 ########################################################################
 # Compiler specific setup
@@ -57,11 +69,7 @@ set(Boost_ADDITIONAL_VERSIONS
     "1.60.0" "1.60" "1.61.0" "1.61" "1.62.0" "1.62" "1.63.0" "1.63" "1.64.0" "1.64"
     "1.65.0" "1.65" "1.66.0" "1.66" "1.67.0" "1.67" "1.68.0" "1.68" "1.69.0" "1.69"
 )
-find_package(Boost "1.35" COMPONENTS system)
-
-if(NOT Boost_FOUND)
-    message(FATAL_ERROR "Boost required to compile iqbalance")
-endif()
+find_package(Boost "1.35" COMPONENTS filesystem program_options regex system thread)
 
 ########################################################################
 # Find FFTW3
@@ -84,7 +92,7 @@ endif()
 if(NOT LIBOSMODSP_FOUND)
     message(STATUS "libosmodsp not found, using local checkout")
     set(LIBOSMODSP_INCLUDE_DIRS "libosmo-dsp/include/")
-    set(LIBOSMODSP_LIBRARIES ${FFTW3F_LIBRARIES})
+    set(LIBOSMODSP_LIBRARIES fftw3f::fftw3f)
     set(LIBOSMODSP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/libosmo-dsp/src/cxvec.c ${CMAKE_CURRENT_SOURCE_DIR}/libosmo-dsp/src/iqbal.c)
 endif()
 
@@ -92,9 +100,15 @@ endif()
 # Install directories
 ########################################################################
 include(GrPlatform) #define LIB_SUFFIX
+
+if(NOT CMAKE_MODULES_DIR)
+  set(CMAKE_MODULES_DIR lib${LIB_SUFFIX}/cmake)
+endif(NOT CMAKE_MODULES_DIR)
+
 set(GR_RUNTIME_DIR      bin)
 set(GR_LIBRARY_DIR      lib${LIB_SUFFIX})
-set(GR_INCLUDE_DIR      include)
+set(GR_INCLUDE_DIR      include/gnuradio/iqbalance)
+SET(GR_CMAKE_DIR        ${CMAKE_MODULES_DIR}/gr-iqbal)
 set(GR_DATA_DIR         share)
 set(GR_PKG_DATA_DIR     ${GR_DATA_DIR}/${CMAKE_PROJECT_NAME})
 set(GR_DOC_DIR          ${GR_DATA_DIR}/doc)
@@ -106,14 +120,28 @@ set(GR_PKG_LIBEXEC_DIR  ${GR_LIBEXEC_DIR}/${CMAKE_PROJECT_NAME})
 set(GRC_BLOCKS_DIR      ${GR_PKG_DATA_DIR}/grc/blocks)
 
 ########################################################################
-# Find gnuradio build dependencies
+# On Apple only, set install name and use rpath correctly, if not already set
 ########################################################################
-set(GR_REQUIRED_COMPONENTS RUNTIME)
-find_package(Gnuradio "3.7.0")
-if(NOT GNURADIO_RUNTIME_FOUND)
-    message(FATAL_ERROR "GnuRadio Runtime required to compile iqbalance")
-endif()
+if(APPLE)
+    if(NOT CMAKE_INSTALL_NAME_DIR)
+        set(CMAKE_INSTALL_NAME_DIR
+            ${CMAKE_INSTALL_PREFIX}/${GR_LIBRARY_DIR} CACHE
+            PATH "Library Install Name Destination Directory" FORCE)
+    endif(NOT CMAKE_INSTALL_NAME_DIR)
+    if(NOT CMAKE_INSTALL_RPATH)
+        set(CMAKE_INSTALL_RPATH
+            ${CMAKE_INSTALL_PREFIX}/${GR_LIBRARY_DIR} CACHE
+            PATH "Library Install RPath" FORCE)
+    endif(NOT CMAKE_INSTALL_RPATH)
+    if(NOT CMAKE_BUILD_WITH_INSTALL_RPATH)
+        set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE
+            BOOL "Do Build Using Library Install RPath" FORCE)
+    endif(NOT CMAKE_BUILD_WITH_INSTALL_RPATH)
+endif(APPLE)
 
+########################################################################
+# Find gnuradio build dependencies
+########################################################################
 find_package(Doxygen)
 
 ########################################################################
@@ -178,3 +206,10 @@ install(
     FILES ${CMAKE_CURRENT_BINARY_DIR}/gnuradio-iqbalance.pc
     DESTINATION ${GR_LIBRARY_DIR}/pkgconfig
 )
+
+########################################################################
+# Install cmake search helper for this library
+########################################################################
+#install(FILES cmake/Modules/gnuradio-iqbalanceConfig.cmake
+#    DESTINATION ${CMAKE_MODULES_DIR}/gnuradio-iqbalance
+#)
diff --git a/cmake/Modules/targetConfig.cmake.in b/cmake/Modules/targetConfig.cmake.in
new file mode 100644
index 0000000..79e4a28
--- /dev/null
+++ b/cmake/Modules/targetConfig.cmake.in
@@ -0,0 +1,26 @@
+# Copyright 2018 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+
+include(CMakeFindDependencyMacro)
+
+set(target_deps "@TARGET_DEPENDENCIES@")
+foreach(dep IN LISTS target_deps)
+    find_dependency(${dep})
+endforeach()
+include("${CMAKE_CURRENT_LIST_DIR}/@TARGET@Targets.cmake")
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 6e5df60..c79c7e9 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -1,4 +1,7 @@
-# Copyright 2011 Free Software Foundation, Inc.
+# Copyright 2011,2012,2016,2018,2019 Free Software Foundation, Inc.
+#
+# This file was generated by gr_modtool, a tool from the GNU Radio framework
+# This file is a part of gr-iqbal
 #
 # GNU Radio is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -20,26 +23,34 @@
 ########################################################################
 include(GrPlatform) #define LIB_SUFFIX
 
-include_directories(${Boost_INCLUDE_DIR})
-link_directories(${Boost_LIBRARY_DIRS})
-
-list(APPEND iqbalance_sources
-     fix_cc.cc
-     optimize_c.cc
-)
-
-add_library(gnuradio-iqbalance SHARED ${iqbalance_sources} ${LIBOSMODSP_SOURCES})
-target_link_libraries(gnuradio-iqbalance ${Boost_LIBRARIES} ${GNURADIO_ALL_LIBRARIES} ${LIBOSMODSP_LIBRARIES})
+add_library(gnuradio-iqbalance SHARED fix_cc.cc optimize_c.cc ${LIBOSMODSP_SOURCES})
+target_link_libraries(gnuradio-iqbalance gnuradio::gnuradio-runtime ${LIBOSMODSP_LIBRARIES})
+target_include_directories(gnuradio-iqbalance
+    PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
+    PUBLIC $<INSTALL_INTERFACE:include>
+  )
+set_target_properties(gnuradio-iqbalance PROPERTIES OUTPUT_NAME gnuradio-iqbalance)
 set_target_properties(gnuradio-iqbalance PROPERTIES DEFINE_SYMBOL "gnuradio_iqbalance_EXPORTS")
 
+if(APPLE)
+    set_target_properties(gnuradio-iqbalance PROPERTIES
+        INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
+    )
+endif(APPLE)
+
 ########################################################################
 # Install built library files
 ########################################################################
-install(TARGETS gnuradio-iqbalance
-    LIBRARY DESTINATION lib${LIB_SUFFIX} # .so/.dylib file
-    ARCHIVE DESTINATION lib${LIB_SUFFIX} # .lib file
-    RUNTIME DESTINATION bin              # .dll file
-)
+include(GrMiscUtils)
+set(VERSION "3.8.0")
+set(LIBVER "3.8.0")
+GR_LIBRARY_FOO(gnuradio-iqbalance)
+
+########################################################################
+# Print summary
+########################################################################
+message(STATUS "Using install prefix: ${CMAKE_INSTALL_PREFIX}")
+message(STATUS "Building for version: ${VERSION} / ${LIBVER}")
 
 ########################################################################
 # Build and register unit test
@@ -47,7 +58,6 @@ install(TARGETS gnuradio-iqbalance
 find_package(Boost COMPONENTS unit_test_framework)
 
 include(GrTest)
-set(GR_TEST_TARGET_DEPS gnuradio-iqbalance)
+list(APPEND GR_TEST_TARGET_DEPS gnuradio-iqbalance)
 #turn each test cpp file into an executable with an int main() function
 add_definitions(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN)
-
diff --git a/swig/CMakeLists.txt b/swig/CMakeLists.txt
index bac10ad..ff21c3a 100644
--- a/swig/CMakeLists.txt
+++ b/swig/CMakeLists.txt
@@ -18,30 +18,38 @@
 # Boston, MA 02110-1301, USA.
 
 ########################################################################
-# Setup swig generation
+# Include swig generation macros
 ########################################################################
 find_package(SWIG)
-find_package(PythonLibs 2)
+find_package(PythonLibs)
 if(NOT SWIG_FOUND OR NOT PYTHONLIBS_FOUND)
     return()
 endif()
 include(GrSwig)
 include(GrPython)
 
-foreach(incdir ${GNURADIO_RUNTIME_INCLUDE_DIRS})
-    list(APPEND GR_SWIG_INCLUDE_DIRS ${incdir}/gnuradio/swig)
-endforeach(incdir)
+########################################################################
+# Setup swig generation
+########################################################################
+set(GR_SWIG_INCLUDE_DIRS $<TARGET_PROPERTY:gnuradio::runtime_swig,INTERFACE_INCLUDE_DIRECTORIES>)
+set(GR_SWIG_TARGET_DEPS gnuradio::runtime_swig)
+
+set(GR_SWIG_LIBRARIES gnuradio-iqbalance)
 
 set(GR_SWIG_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/iqbalance_swig_doc.i)
 set(GR_SWIG_DOC_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../include/gnuradio/iqbalance)
 set(GR_SWIG_DOCS_TARGET_DEPS runtime_swig_swig_doc)
 
-set(GR_SWIG_LIBRARIES gnuradio-iqbalance)
-
 GR_SWIG_MAKE(iqbalance_swig iqbalance_swig.i)
 
+########################################################################
+# Install the build swig module
+########################################################################
 GR_SWIG_INSTALL(TARGETS iqbalance_swig DESTINATION ${GR_PYTHON_DIR}/gnuradio/iqbalance)
 
+########################################################################
+# Install swig .i files for development
+########################################################################
 install(
     FILES
     iqbalance_swig.i
-- 
2.20.1