diff options
Diffstat (limited to 'gr-howto-write-a-block-cmake')
29 files changed, 1988 insertions, 0 deletions
diff --git a/gr-howto-write-a-block-cmake/CMakeLists.txt b/gr-howto-write-a-block-cmake/CMakeLists.txt new file mode 100644 index 000000000..9de061414 --- /dev/null +++ b/gr-howto-write-a-block-cmake/CMakeLists.txt @@ -0,0 +1,103 @@ +# Copyright 2011 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. + + +######################################################################## +# Project setup +######################################################################## +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(gr-howto-write-a-block CXX) +ENABLE_TESTING() + +#select the release build type by default to get optimization flags +IF(NOT CMAKE_BUILD_TYPE) + SET(CMAKE_BUILD_TYPE "Release") + MESSAGE(STATUS "Build type not specified: defaulting to release.") +ENDIF(NOT CMAKE_BUILD_TYPE) +SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "") + +LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) + +######################################################################## +# Compiler specific setup +######################################################################## +IF(CMAKE_COMPILER_IS_GNUCXX AND NOT WIN32) + #http://gcc.gnu.org/wiki/Visibility + ADD_DEFINITIONS(-fvisibility=hidden) +ENDIF() + +######################################################################## +# Find boost +######################################################################## +IF(UNIX AND EXISTS "/usr/lib64") + LIST(APPEND BOOST_LIBRARYDIR "/usr/lib64") #fedora 64-bit fix +ENDIF(UNIX AND EXISTS "/usr/lib64") +SET(Boost_ADDITIONAL_VERSIONS + "1.35.0" "1.35" "1.36.0" "1.36" "1.37.0" "1.37" "1.38.0" "1.38" "1.39.0" "1.39" + "1.40.0" "1.40" "1.41.0" "1.41" "1.42.0" "1.42" "1.43.0" "1.43" "1.44.0" "1.44" + "1.45.0" "1.45" "1.46.0" "1.46" "1.47.0" "1.47" "1.48.0" "1.48" "1.49.0" "1.49" + "1.50.0" "1.50" "1.51.0" "1.51" "1.52.0" "1.52" "1.53.0" "1.53" "1.54.0" "1.54" + "1.55.0" "1.55" "1.56.0" "1.56" "1.57.0" "1.57" "1.58.0" "1.58" "1.59.0" "1.59" + "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") + +IF(NOT Boost_FOUND) + MESSAGE(FATAL_ERROR "Boost required to compile howto") +ENDIF() + +######################################################################## +# Find gnuradio build dependencies +######################################################################## +FIND_PACKAGE(Gruel) +FIND_PACKAGE(GnuradioCore) + +IF(NOT GRUEL_FOUND) + MESSAGE(FATAL_ERROR "Gruel required to compile howto") +ENDIF() + +IF(NOT GNURADIO_CORE_FOUND) + MESSAGE(FATAL_ERROR "GnuRadio Core required to compile howto") +ENDIF() + +######################################################################## +# Setup the include and linker paths +######################################################################## +INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR}/lib + ${Boost_INCLUDE_DIRS} + ${GRUEL_INCLUDE_DIRS} + ${GNURADIO_CORE_INCLUDE_DIRS} +) + +LINK_DIRECTORIES( + ${Boost_LIBRARY_DIRS} + ${GRUEL_LIBRARY_DIRS} + ${GNURADIO_CORE_LIBRARY_DIRS} +) + +######################################################################## +# Add subdirectories +######################################################################## +ADD_SUBDIRECTORY(lib) +ADD_SUBDIRECTORY(swig) +ADD_SUBDIRECTORY(python) +ADD_SUBDIRECTORY(grc) +ADD_SUBDIRECTORY(apps) diff --git a/gr-howto-write-a-block-cmake/apps/CMakeLists.txt b/gr-howto-write-a-block-cmake/apps/CMakeLists.txt new file mode 100644 index 000000000..e89cae26b --- /dev/null +++ b/gr-howto-write-a-block-cmake/apps/CMakeLists.txt @@ -0,0 +1,26 @@ +# Copyright 2011 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(GrPython) + +GR_PYTHON_INSTALL( + PROGRAMS + howto_square.py + DESTINATION bin +) diff --git a/gr-howto-write-a-block-cmake/apps/howto_square.grc b/gr-howto-write-a-block-cmake/apps/howto_square.grc new file mode 100644 index 000000000..a8563698b --- /dev/null +++ b/gr-howto-write-a-block-cmake/apps/howto_square.grc @@ -0,0 +1,325 @@ +<?xml version='1.0' encoding='ASCII'?> +<flow_graph> + <timestamp>Thu Nov 12 11:26:07 2009</timestamp> + <block> + <key>options</key> + <param> + <key>id</key> + <value>howto_square</value> + </param> + <param> + <key>_enabled</key> + <value>True</value> + </param> + <param> + <key>title</key> + <value></value> + </param> + <param> + <key>author</key> + <value></value> + </param> + <param> + <key>description</key> + <value></value> + </param> + <param> + <key>window_size</key> + <value>1280, 1024</value> + </param> + <param> + <key>generate_options</key> + <value>wx_gui</value> + </param> + <param> + <key>category</key> + <value>Custom</value> + </param> + <param> + <key>run_options</key> + <value>prompt</value> + </param> + <param> + <key>run</key> + <value>True</value> + </param> + <param> + <key>realtime_scheduling</key> + <value></value> + </param> + <param> + <key>_coordinate</key> + <value>(10, 10)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + </block> + <block> + <key>variable</key> + <param> + <key>id</key> + <value>samp_rate</value> + </param> + <param> + <key>_enabled</key> + <value>True</value> + </param> + <param> + <key>value</key> + <value>10e3</value> + </param> + <param> + <key>_coordinate</key> + <value>(10, 170)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + </block> + <block> + <key>wxgui_scopesink2</key> + <param> + <key>id</key> + <value>sink</value> + </param> + <param> + <key>_enabled</key> + <value>True</value> + </param> + <param> + <key>type</key> + <value>float</value> + </param> + <param> + <key>title</key> + <value>Input</value> + </param> + <param> + <key>samp_rate</key> + <value>samp_rate</value> + </param> + <param> + <key>v_scale</key> + <value>20</value> + </param> + <param> + <key>v_offset</key> + <value>0</value> + </param> + <param> + <key>t_scale</key> + <value>0.002</value> + </param> + <param> + <key>ac_couple</key> + <value>False</value> + </param> + <param> + <key>xy_mode</key> + <value>False</value> + </param> + <param> + <key>num_inputs</key> + <value>1</value> + </param> + <param> + <key>win_size</key> + <value></value> + </param> + <param> + <key>grid_pos</key> + <value></value> + </param> + <param> + <key>notebook</key> + <value></value> + </param> + <param> + <key>_coordinate</key> + <value>(691, 222)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + </block> + <block> + <key>howto_square_ff</key> + <param> + <key>id</key> + <value>sqr</value> + </param> + <param> + <key>_enabled</key> + <value>True</value> + </param> + <param> + <key>_coordinate</key> + <value>(709, 344)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + </block> + <block> + <key>gr_throttle</key> + <param> + <key>id</key> + <value>thr</value> + </param> + <param> + <key>_enabled</key> + <value>True</value> + </param> + <param> + <key>type</key> + <value>float</value> + </param> + <param> + <key>samples_per_second</key> + <value>samp_rate</value> + </param> + <param> + <key>vlen</key> + <value>1</value> + </param> + <param> + <key>_coordinate</key> + <value>(497, 340)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + </block> + <block> + <key>gr_vector_source_x</key> + <param> + <key>id</key> + <value>src</value> + </param> + <param> + <key>_enabled</key> + <value>True</value> + </param> + <param> + <key>type</key> + <value>float</value> + </param> + <param> + <key>vector</key> + <value>[float(n)-50 for n in range(100)]</value> + </param> + <param> + <key>repeat</key> + <value>True</value> + </param> + <param> + <key>vlen</key> + <value>1</value> + </param> + <param> + <key>_coordinate</key> + <value>(246, 332)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + </block> + <block> + <key>wxgui_scopesink2</key> + <param> + <key>id</key> + <value>sink2</value> + </param> + <param> + <key>_enabled</key> + <value>True</value> + </param> + <param> + <key>type</key> + <value>float</value> + </param> + <param> + <key>title</key> + <value>Output</value> + </param> + <param> + <key>samp_rate</key> + <value>samp_rate</value> + </param> + <param> + <key>v_scale</key> + <value>0</value> + </param> + <param> + <key>v_offset</key> + <value>0</value> + </param> + <param> + <key>t_scale</key> + <value>0.002</value> + </param> + <param> + <key>ac_couple</key> + <value>False</value> + </param> + <param> + <key>xy_mode</key> + <value>False</value> + </param> + <param> + <key>num_inputs</key> + <value>1</value> + </param> + <param> + <key>win_size</key> + <value></value> + </param> + <param> + <key>grid_pos</key> + <value></value> + </param> + <param> + <key>notebook</key> + <value></value> + </param> + <param> + <key>_coordinate</key> + <value>(869, 324)</value> + </param> + <param> + <key>_rotation</key> + <value>0</value> + </param> + </block> + <connection> + <source_block_id>thr</source_block_id> + <sink_block_id>sqr</sink_block_id> + <source_key>0</source_key> + <sink_key>0</sink_key> + </connection> + <connection> + <source_block_id>src</source_block_id> + <sink_block_id>thr</sink_block_id> + <source_key>0</source_key> + <sink_key>0</sink_key> + </connection> + <connection> + <source_block_id>thr</source_block_id> + <sink_block_id>sink</sink_block_id> + <source_key>0</source_key> + <sink_key>0</sink_key> + </connection> + <connection> + <source_block_id>sqr</source_block_id> + <sink_block_id>sink2</sink_block_id> + <source_key>0</source_key> + <sink_key>0</sink_key> + </connection> +</flow_graph> diff --git a/gr-howto-write-a-block-cmake/apps/howto_square.py b/gr-howto-write-a-block-cmake/apps/howto_square.py new file mode 100755 index 000000000..f14e28325 --- /dev/null +++ b/gr-howto-write-a-block-cmake/apps/howto_square.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python +################################################## +# Gnuradio Python Flow Graph +# Title: Howto Square +# Generated: Thu Nov 12 11:26:07 2009 +################################################## + +import howto +from gnuradio import eng_notation +from gnuradio import gr +from gnuradio.eng_option import eng_option +from gnuradio.gr import firdes +from gnuradio.wxgui import scopesink2 +from grc_gnuradio import wxgui as grc_wxgui +from optparse import OptionParser +import wx + +class howto_square(grc_wxgui.top_block_gui): + + def __init__(self): + grc_wxgui.top_block_gui.__init__(self, title="Howto Square") + + ################################################## + # Variables + ################################################## + self.samp_rate = samp_rate = 10e3 + + ################################################## + # Blocks + ################################################## + self.sink = scopesink2.scope_sink_f( + self.GetWin(), + title="Input", + sample_rate=samp_rate, + v_scale=20, + v_offset=0, + t_scale=0.002, + ac_couple=False, + xy_mode=False, + num_inputs=1, + ) + self.Add(self.sink.win) + self.sink2 = scopesink2.scope_sink_f( + self.GetWin(), + title="Output", + sample_rate=samp_rate, + v_scale=0, + v_offset=0, + t_scale=0.002, + ac_couple=False, + xy_mode=False, + num_inputs=1, + ) + self.Add(self.sink2.win) + self.sqr = howto.square_ff() + self.src = gr.vector_source_f(([float(n)-50 for n in range(100)]), True, 1) + self.thr = gr.throttle(gr.sizeof_float*1, samp_rate) + + ################################################## + # Connections + ################################################## + self.connect((self.thr, 0), (self.sqr, 0)) + self.connect((self.src, 0), (self.thr, 0)) + self.connect((self.thr, 0), (self.sink, 0)) + self.connect((self.sqr, 0), (self.sink2, 0)) + + def set_samp_rate(self, samp_rate): + self.samp_rate = samp_rate + self.sink.set_sample_rate(self.samp_rate) + self.sink2.set_sample_rate(self.samp_rate) + +if __name__ == '__main__': + parser = OptionParser(option_class=eng_option, usage="%prog: [options]") + (options, args) = parser.parse_args() + tb = howto_square() + tb.Run(True) + diff --git a/gr-howto-write-a-block-cmake/cmake/Modules/CMakeParseArgumentsCopy.cmake b/gr-howto-write-a-block-cmake/cmake/Modules/CMakeParseArgumentsCopy.cmake new file mode 100644 index 000000000..7ce4c49ae --- /dev/null +++ b/gr-howto-write-a-block-cmake/cmake/Modules/CMakeParseArgumentsCopy.cmake @@ -0,0 +1,138 @@ +# CMAKE_PARSE_ARGUMENTS(<prefix> <options> <one_value_keywords> <multi_value_keywords> args...) +# +# CMAKE_PARSE_ARGUMENTS() is intended to be used in macros or functions for +# parsing the arguments given to that macro or function. +# It processes the arguments and defines a set of variables which hold the +# values of the respective options. +# +# The <options> argument contains all options for the respective macro, +# i.e. keywords which can be used when calling the macro without any value +# following, like e.g. the OPTIONAL keyword of the install() command. +# +# The <one_value_keywords> argument contains all keywords for this macro +# which are followed by one value, like e.g. DESTINATION keyword of the +# install() command. +# +# The <multi_value_keywords> argument contains all keywords for this macro +# which can be followed by more than one value, like e.g. the TARGETS or +# FILES keywords of the install() command. +# +# When done, CMAKE_PARSE_ARGUMENTS() will have defined for each of the +# keywords listed in <options>, <one_value_keywords> and +# <multi_value_keywords> a variable composed of the given <prefix> +# followed by "_" and the name of the respective keyword. +# These variables will then hold the respective value from the argument list. +# For the <options> keywords this will be TRUE or FALSE. +# +# All remaining arguments are collected in a variable +# <prefix>_UNPARSED_ARGUMENTS, this can be checked afterwards to see whether +# your macro was called with unrecognized parameters. +# +# As an example here a my_install() macro, which takes similar arguments as the +# real install() command: +# +# function(MY_INSTALL) +# set(options OPTIONAL FAST) +# set(oneValueArgs DESTINATION RENAME) +# set(multiValueArgs TARGETS CONFIGURATIONS) +# cmake_parse_arguments(MY_INSTALL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) +# ... +# +# Assume my_install() has been called like this: +# my_install(TARGETS foo bar DESTINATION bin OPTIONAL blub) +# +# After the cmake_parse_arguments() call the macro will have set the following +# variables: +# MY_INSTALL_OPTIONAL = TRUE +# MY_INSTALL_FAST = FALSE (this option was not used when calling my_install() +# MY_INSTALL_DESTINATION = "bin" +# MY_INSTALL_RENAME = "" (was not used) +# MY_INSTALL_TARGETS = "foo;bar" +# MY_INSTALL_CONFIGURATIONS = "" (was not used) +# MY_INSTALL_UNPARSED_ARGUMENTS = "blub" (no value expected after "OPTIONAL" +# +# You can the continue and process these variables. +# +# Keywords terminate lists of values, e.g. if directly after a one_value_keyword +# another recognized keyword follows, this is interpreted as the beginning of +# the new option. +# E.g. my_install(TARGETS foo DESTINATION OPTIONAL) would result in +# MY_INSTALL_DESTINATION set to "OPTIONAL", but MY_INSTALL_DESTINATION would +# be empty and MY_INSTALL_OPTIONAL would be set to TRUE therefor. + +#============================================================================= +# Copyright 2010 Alexander Neundorf <neundorf@kde.org> +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + + +if(__CMAKE_PARSE_ARGUMENTS_INCLUDED) + return() +endif() +set(__CMAKE_PARSE_ARGUMENTS_INCLUDED TRUE) + + +function(CMAKE_PARSE_ARGUMENTS prefix _optionNames _singleArgNames _multiArgNames) + # first set all result variables to empty/FALSE + foreach(arg_name ${_singleArgNames} ${_multiArgNames}) + set(${prefix}_${arg_name}) + endforeach(arg_name) + + foreach(option ${_optionNames}) + set(${prefix}_${option} FALSE) + endforeach(option) + + set(${prefix}_UNPARSED_ARGUMENTS) + + set(insideValues FALSE) + set(currentArgName) + + # now iterate over all arguments and fill the result variables + foreach(currentArg ${ARGN}) + list(FIND _optionNames "${currentArg}" optionIndex) # ... then this marks the end of the arguments belonging to this keyword + list(FIND _singleArgNames "${currentArg}" singleArgIndex) # ... then this marks the end of the arguments belonging to this keyword + list(FIND _multiArgNames "${currentArg}" multiArgIndex) # ... then this marks the end of the arguments belonging to this keyword + + if(${optionIndex} EQUAL -1 AND ${singleArgIndex} EQUAL -1 AND ${multiArgIndex} EQUAL -1) + if(insideValues) + if("${insideValues}" STREQUAL "SINGLE") + set(${prefix}_${currentArgName} ${currentArg}) + set(insideValues FALSE) + elseif("${insideValues}" STREQUAL "MULTI") + list(APPEND ${prefix}_${currentArgName} ${currentArg}) + endif() + else(insideValues) + list(APPEND ${prefix}_UNPARSED_ARGUMENTS ${currentArg}) + endif(insideValues) + else() + if(NOT ${optionIndex} EQUAL -1) + set(${prefix}_${currentArg} TRUE) + set(insideValues FALSE) + elseif(NOT ${singleArgIndex} EQUAL -1) + set(currentArgName ${currentArg}) + set(${prefix}_${currentArgName}) + set(insideValues "SINGLE") + elseif(NOT ${multiArgIndex} EQUAL -1) + set(currentArgName ${currentArg}) + set(${prefix}_${currentArgName}) + set(insideValues "MULTI") + endif() + endif() + + endforeach(currentArg) + + # propagate the result variables to the caller: + foreach(arg_name ${_singleArgNames} ${_multiArgNames} ${_optionNames}) + set(${prefix}_${arg_name} ${${prefix}_${arg_name}} PARENT_SCOPE) + endforeach(arg_name) + set(${prefix}_UNPARSED_ARGUMENTS ${${prefix}_UNPARSED_ARGUMENTS} PARENT_SCOPE) + +endfunction(CMAKE_PARSE_ARGUMENTS _options _singleArgs _multiArgs) diff --git a/gr-howto-write-a-block-cmake/cmake/Modules/FindGnuradioCore.cmake b/gr-howto-write-a-block-cmake/cmake/Modules/FindGnuradioCore.cmake new file mode 100644 index 000000000..f76364acf --- /dev/null +++ b/gr-howto-write-a-block-cmake/cmake/Modules/FindGnuradioCore.cmake @@ -0,0 +1,26 @@ +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(GNURADIO_CORE gnuradio-core) +IF(NOT GNURADIO_CORE_FOUND) + +FIND_PATH( + GNURADIO_CORE_INCLUDE_DIRS + NAMES gr_random.h + HINTS $ENV{GNURADIO_CORE_DIR}/include/gnuradio + PATHS /usr/local/include/gnuradio + /usr/include/gnuradio +) + +FIND_LIBRARY( + GNURADIO_CORE_LIBRARIES + NAMES gnuradio-core + HINTS $ENV{GNURADIO_CORE_DIR}/lib + PATHS /usr/local/lib + /usr/local/lib64 + /usr/lib + /usr/lib64 +) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GNURADIO_CORE DEFAULT_MSG GNURADIO_CORE_LIBRARIES GNURADIO_CORE_INCLUDE_DIRS) + +ENDIF(NOT GNURADIO_CORE_FOUND) diff --git a/gr-howto-write-a-block-cmake/cmake/Modules/FindGruel.cmake b/gr-howto-write-a-block-cmake/cmake/Modules/FindGruel.cmake new file mode 100644 index 000000000..c142c905e --- /dev/null +++ b/gr-howto-write-a-block-cmake/cmake/Modules/FindGruel.cmake @@ -0,0 +1,26 @@ +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(GRUEL gnuradio-core) +IF(NOT GRUEL_FOUND) + +FIND_PATH( + GRUEL_INCLUDE_DIRS + NAMES gruel/attributes.h + HINTS $ENV{GRUEL_DIR}/include + PATHS /usr/local/include + /usr/include +) + +FIND_LIBRARY( + GRUEL_LIBRARIES + NAMES gruel + HINTS $ENV{GRUEL_DIR}/lib + PATHS /usr/local/lib + /usr/local/lib64 + /usr/lib + /usr/lib64 +) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GRUEL DEFAULT_MSG GRUEL_LIBRARIES GRUEL_INCLUDE_DIRS) + +ENDIF(NOT GRUEL_FOUND) diff --git a/gr-howto-write-a-block-cmake/cmake/Modules/GrPlatform.cmake b/gr-howto-write-a-block-cmake/cmake/Modules/GrPlatform.cmake new file mode 100644 index 000000000..85f318618 --- /dev/null +++ b/gr-howto-write-a-block-cmake/cmake/Modules/GrPlatform.cmake @@ -0,0 +1,46 @@ +# Copyright 2011 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. + +IF(DEFINED __INCLUDED_GR_PLATFORM_CMAKE) + RETURN() +ENDIF() +SET(__INCLUDED_GR_PLATFORM_CMAKE TRUE) + +######################################################################## +# Setup additional defines for OS types +######################################################################## +IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") + SET(LINUX TRUE) +ENDIF() + +IF(LINUX AND EXISTS "/etc/debian_version") + SET(DEBIAN TRUE) +ENDIF() + +IF(LINUX AND EXISTS "/etc/redhat-release") + SET(REDHAT TRUE) +ENDIF() + +######################################################################## +# when the library suffix should be 64 (applies to redhat linux family) +######################################################################## +IF(NOT DEFINED LIB_SUFFIX AND REDHAT AND CMAKE_SYSTEM_PROCESSOR MATCHES "64$") + SET(LIB_SUFFIX 64) +ENDIF() +SET(LIB_SUFFIX ${LIB_SUFFIX} CACHE STRING "lib directory suffix") diff --git a/gr-howto-write-a-block-cmake/cmake/Modules/GrPython.cmake b/gr-howto-write-a-block-cmake/cmake/Modules/GrPython.cmake new file mode 100644 index 000000000..f54dbc9ba --- /dev/null +++ b/gr-howto-write-a-block-cmake/cmake/Modules/GrPython.cmake @@ -0,0 +1,177 @@ +# Copyright 2010-2011 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. + +IF(DEFINED __INCLUDED_GR_PYTHON_CMAKE) + RETURN() +ENDIF() +SET(__INCLUDED_GR_PYTHON_CMAKE TRUE) + +######################################################################## +# Setup the python interpreter: +# This allows the user to specify a specific interpreter, +# or finds the interpreter via the built-in cmake module. +######################################################################## +#this allows the user to override PYTHON_EXECUTABLE +IF(PYTHON_EXECUTABLE) + + SET(PYTHONINTERP_FOUND TRUE) + +#otherwise if not set, try to automatically find it +ELSE(PYTHON_EXECUTABLE) + + #use the built-in find script + FIND_PACKAGE(PythonInterp) + + #and if that fails use the find program routine + IF(NOT PYTHONINTERP_FOUND) + FIND_PROGRAM(PYTHON_EXECUTABLE NAMES python python2.7 python2.6 python2.5) + IF(PYTHON_EXECUTABLE) + SET(PYTHONINTERP_FOUND TRUE) + ENDIF(PYTHON_EXECUTABLE) + ENDIF(NOT PYTHONINTERP_FOUND) + +ENDIF(PYTHON_EXECUTABLE) + +#make the path to the executable appear in the cmake gui +SET(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "python interpreter") + +######################################################################## +# Check for the existence of a python module: +# - desc a string description of the check +# - mod the name of the module to import +# - cmd an additional command to run +# - have the result variable to set +######################################################################## +MACRO(GR_PYTHON_CHECK_MODULE desc mod cmd have) + MESSAGE(STATUS "") + MESSAGE(STATUS "Python checking for ${desc}") + EXECUTE_PROCESS( + COMMAND ${PYTHON_EXECUTABLE} -c " +######################################### +try: import ${mod} +except: exit(-1) +try: assert ${cmd} +except: exit(-1) +#########################################" + RESULT_VARIABLE ${have} + ) + IF(${have} EQUAL 0) + MESSAGE(STATUS "Python checking for ${desc} - found") + SET(${have} TRUE) + ELSE(${have} EQUAL 0) + MESSAGE(STATUS "Python checking for ${desc} - not found") + SET(${have} FALSE) + ENDIF(${have} EQUAL 0) +ENDMACRO(GR_PYTHON_CHECK_MODULE) + +######################################################################## +# Sets the python installation directory GR_PYTHON_DIR +######################################################################## +EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c " +from distutils import sysconfig +print sysconfig.get_python_lib(plat_specific=True, prefix='') +" OUTPUT_VARIABLE GR_PYTHON_DIR OUTPUT_STRIP_TRAILING_WHITESPACE +) +FILE(TO_CMAKE_PATH ${GR_PYTHON_DIR} GR_PYTHON_DIR) + +######################################################################## +# Create an always-built target with a unique name +# Usage: GR_UNIQUE_TARGET(<description> <dependencies list>) +######################################################################## +FUNCTION(GR_UNIQUE_TARGET desc) + FILE(RELATIVE_PATH reldir ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import re, hashlib +unique = hashlib.md5('${reldir}${ARGN}').hexdigest()[:5] +print(re.sub('\\W', '_', '${desc} ${reldir} ' + unique))" + OUTPUT_VARIABLE _target OUTPUT_STRIP_TRAILING_WHITESPACE) + ADD_CUSTOM_TARGET(${_target} ALL DEPENDS ${ARGN}) +ENDFUNCTION(GR_UNIQUE_TARGET) + +######################################################################## +# Install python sources (also builds and installs byte-compiled python) +######################################################################## +FUNCTION(GR_PYTHON_INSTALL) + INCLUDE(CMakeParseArgumentsCopy) + CMAKE_PARSE_ARGUMENTS(GR_PYTHON_INSTALL "" "DESTINATION;COMPONENT" "FILES;PROGRAMS" ${ARGN}) + + #################################################################### + IF(GR_PYTHON_INSTALL_FILES) + #################################################################### + INSTALL(${ARGN}) #installs regular python files + + FOREACH(pyfile ${GR_PYTHON_INSTALL_FILES}) + GET_FILENAME_COMPONENT(pyfile_name ${pyfile} NAME) + GET_FILENAME_COMPONENT(pyfile ${pyfile} ABSOLUTE) + STRING(REPLACE "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" pycfile "${pyfile}c") + LIST(APPEND python_install_gen_targets ${pycfile}) + + GET_FILENAME_COMPONENT(pycfile_path ${pycfile} PATH) + FILE(MAKE_DIRECTORY ${pycfile_path}) + + #create a command to generate the byte-compiled pyc file + ADD_CUSTOM_COMMAND( + OUTPUT ${pycfile} DEPENDS ${pyfile} + COMMAND ${PYTHON_EXECUTABLE} -c + \"import py_compile\; py_compile.compile(file='${pyfile}', cfile='${pycfile}', doraise=True)\" + COMMENT "Byte-compiling ${pyfile_name}" + ) + INSTALL(FILES ${pycfile} + DESTINATION ${GR_PYTHON_INSTALL_DESTINATION} + COMPONENT ${GR_PYTHON_INSTALL_COMPONENT} + ) + ENDFOREACH(pyfile) + + #################################################################### + ELSEIF(GR_PYTHON_INSTALL_PROGRAMS) + #################################################################### + FILE(TO_NATIVE_PATH ${PYTHON_EXECUTABLE} pyexe_native) + + FOREACH(pyfile ${GR_PYTHON_INSTALL_PROGRAMS}) + GET_FILENAME_COMPONENT(pyfile_name ${pyfile} NAME) + GET_FILENAME_COMPONENT(pyfile ${pyfile} ABSOLUTE) + STRING(REPLACE "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" pyexefile "${pyfile}.exe") + LIST(APPEND python_install_gen_targets ${pyexefile}) + + GET_FILENAME_COMPONENT(pyexefile_path ${pyexefile} PATH) + FILE(MAKE_DIRECTORY ${pyexefile_path}) + + ADD_CUSTOM_COMMAND( + OUTPUT ${pyexefile} DEPENDS ${pyfile} + COMMAND ${PYTHON_EXECUTABLE} -c + \"open('${pyexefile}', 'w').write('\#!${pyexe_native}\\n'+open('${pyfile}').read())\" + COMMENT "Shebangin ${pyfile_name}" + ) + + #on windows, python files need an extension to execute + GET_FILENAME_COMPONENT(pyfile_ext ${pyfile} EXT) + IF(WIN32 AND NOT pyfile_ext) + SET(pyfile_name "${pyfile_name}.py") + ENDIF() + + INSTALL(PROGRAMS ${pyexefile} RENAME ${pyfile_name} + DESTINATION ${GR_PYTHON_INSTALL_DESTINATION} + COMPONENT ${GR_PYTHON_INSTALL_COMPONENT} + ) + ENDFOREACH(pyfile) + + ENDIF() + + GR_UNIQUE_TARGET("pygen" ${python_install_gen_targets}) + +ENDFUNCTION(GR_PYTHON_INSTALL) diff --git a/gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake b/gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake new file mode 100644 index 000000000..9fca29a4f --- /dev/null +++ b/gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake @@ -0,0 +1,90 @@ +# Copyright 2010-2011 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. + +IF(DEFINED __INCLUDED_GR_SWIG_CMAKE) + RETURN() +ENDIF() +SET(__INCLUDED_GR_SWIG_CMAKE TRUE) + +######################################################################## +# Build a swig target for the common gnuradio use case. Usage: +# GR_SWIG_MAKE(target ifile ifile ifile...) +# +# Set the following variables before calling: +# - GR_SWIG_FLAGS +# - GR_SWIG_INCLUDE_DIRS +# - GR_SWIG_LIBRARIES +# - GR_SWIG_SOURCE_DEPS +# - GR_SWIG_TARGET_DEPS +######################################################################## +MACRO(GR_SWIG_MAKE name) + SET(ifiles ${ARGN}) + + INCLUDE_DIRECTORIES(${GR_SWIG_INCLUDE_DIRS}) + SET(SWIG_MODULE_${name}_EXTRA_DEPS ${GR_SWIG_SOURCE_DEPS}) + + FIND_PACKAGE(PythonLibs) + INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS}) + + #setup the swig flags with flags and include directories + SET(CMAKE_SWIG_FLAGS -fvirtual -modern -keyword -w511 -module ${name} ${GR_SWIG_FLAGS}) + FOREACH(dir ${GR_SWIG_INCLUDE_DIRS}) + LIST(APPEND CMAKE_SWIG_FLAGS "-I${dir}") + ENDFOREACH(dir) + + #set the C++ property on the swig .i file so it builds + SET_SOURCE_FILES_PROPERTIES(${ifiles} PROPERTIES CPLUSPLUS ON) + + #setup the actual swig library target to be built + INCLUDE(UseSWIG) + SWIG_ADD_MODULE(${name} python ${ifiles}) + SWIG_LINK_LIBRARIES(${name} ${PYTHON_LIBRARIES} ${GR_SWIG_LIBRARIES}) + IF(GR_SWIG_TARGET_DEPS) + ADD_DEPENDENCIES(${SWIG_MODULE_${name}_REAL_NAME} ${GR_SWIG_TARGET_DEPS}) + ENDIF(GR_SWIG_TARGET_DEPS) + +ENDMACRO(GR_SWIG_MAKE) + +######################################################################## +# Install swig targets generated by GR_SWIG_MAKE. Usage: +# GR_SWIG_INSTALL( +# TARGETS target target target... +# [DESTINATION destination] +# [COMPONENT component] +# ) +######################################################################## +MACRO(GR_SWIG_INSTALL) + + INCLUDE(CMakeParseArgumentsCopy) + CMAKE_PARSE_ARGUMENTS(GR_SWIG_INSTALL "" "DESTINATION;COMPONENT" "TARGETS" ${ARGN}) + + FOREACH(name ${GR_SWIG_INSTALL_TARGETS}) + INSTALL(TARGETS ${SWIG_MODULE_${name}_REAL_NAME} + DESTINATION ${GR_SWIG_INSTALL_DESTINATION} + COMPONENT ${GR_SWIG_INSTALL_COMPONENT} + ) + + INCLUDE(GrPython) + GR_PYTHON_INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${name}.py + DESTINATION ${GR_SWIG_INSTALL_DESTINATION} + COMPONENT ${GR_SWIG_INSTALL_COMPONENT} + ) + ENDFOREACH(name) + +ENDMACRO(GR_SWIG_INSTALL) diff --git a/gr-howto-write-a-block-cmake/cmake/Modules/GrTest.cmake b/gr-howto-write-a-block-cmake/cmake/Modules/GrTest.cmake new file mode 100644 index 000000000..e9e2a0c2e --- /dev/null +++ b/gr-howto-write-a-block-cmake/cmake/Modules/GrTest.cmake @@ -0,0 +1,133 @@ +# Copyright 2010-2011 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. + +IF(DEFINED __INCLUDED_GR_TEST_CMAKE) + RETURN() +ENDIF() +SET(__INCLUDED_GR_TEST_CMAKE TRUE) + +######################################################################## +# Add a unit test and setup the environment for a unit test. +# Takes the same arguments as the ADD_TEST function. +# +# Before calling set the following variables: +# GR_TEST_TARGET_DEPS - built targets for the library path +# GR_TEST_LIBRARY_DIRS - directories for the library path +# GR_TEST_PYTHON_DIRS - directories for the python path +######################################################################## +FUNCTION(GR_ADD_TEST test_name) + + IF(WIN32) + #Ensure that the build exe also appears in the PATH. + LIST(APPEND GR_TEST_TARGET_DEPS ${ARGN}) + + #In the land of windows, all libraries must be in the PATH. + #Since the dependent libraries are not yet installed, + #we must manually set them in the PATH to run tests. + #The following appends the path of a target dependency. + FOREACH(target ${GR_TEST_TARGET_DEPS}) + GET_TARGET_PROPERTY(location ${target} LOCATION) + IF(location) + GET_FILENAME_COMPONENT(path ${location} PATH) + STRING(REGEX REPLACE "\\$\\(.*\\)" ${CMAKE_BUILD_TYPE} path ${path}) + LIST(APPEND GR_TEST_LIBRARY_DIRS ${path}) + ENDIF(location) + ENDFOREACH(target) + + #SWIG generates the python library files into a subdirectory. + #Therefore, we must append this subdirectory into PYTHONPATH. + #Only do this for the python directories matching the following: + FOREACH(pydir ${GR_TEST_PYTHON_DIRS}) + GET_FILENAME_COMPONENT(name ${pydir} NAME) + IF(name MATCHES "^(swig|lib|src)$") + LIST(APPEND GR_TEST_PYTHON_DIRS ${pydir}/${CMAKE_BUILD_TYPE}) + ENDIF() + ENDFOREACH(pydir) + ENDIF(WIN32) + + FILE(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} srcdir) + FILE(TO_NATIVE_PATH "${GR_TEST_LIBRARY_DIRS}" libpath) #ok to use on dir list? + FILE(TO_NATIVE_PATH "${GR_TEST_PYTHON_DIRS}" pypath) #ok to use on dir list? + + SET(environs "GR_DONT_LOAD_PREFS=1" "srcdir=${srcdir}") + + #http://www.cmake.org/pipermail/cmake/2009-May/029464.html + #Replaced this add test + set environs code with the shell script generation. + #Its nicer to be able to manually run the shell script to diagnose problems. + #ADD_TEST(${ARGV}) + #SET_TESTS_PROPERTIES(${test_name} PROPERTIES ENVIRONMENT "${environs}") + + IF(UNIX) + SET(binpath "${CMAKE_CURRENT_BINARY_DIR}:$PATH") + #set both LD and DYLD paths to cover multiple UNIX OS library paths + LIST(APPEND libpath "$LD_LIBRARY_PATH" "$DYLD_LIBRARY_PATH") + LIST(APPEND pypath "$PYTHONPATH") + + #replace list separator with the path separator + STRING(REPLACE ";" ":" libpath "${libpath}") + STRING(REPLACE ";" ":" pypath "${pypath}") + LIST(APPEND environs "PATH=${binpath}" "LD_LIBRARY_PATH=${libpath}" "DYLD_LIBRARY_PATH=${libpath}" "PYTHONPATH=${pypath}") + + #generate a bat file that sets the environment and runs the test + FIND_PROGRAM(SHELL sh) + SET(sh_file ${CMAKE_CURRENT_BINARY_DIR}/${test_name}_test.sh) + FILE(WRITE ${sh_file} "#!${SHELL}\n") + #each line sets an environment variable + FOREACH(environ ${environs}) + FILE(APPEND ${sh_file} "export ${environ}\n") + ENDFOREACH(environ) + #load the command to run with its arguments + FOREACH(arg ${ARGN}) + FILE(APPEND ${sh_file} "${arg} ") + ENDFOREACH(arg) + FILE(APPEND ${sh_file} "\n") + + #make the shell file executable + EXECUTE_PROCESS(COMMAND chmod +x ${sh_file}) + + ADD_TEST(${test_name} ${SHELL} ${sh_file}) + + ENDIF(UNIX) + + IF(WIN32) + LIST(APPEND libpath ${DLL_PATHS} "%PATH%") + LIST(APPEND pypath "%PYTHONPATH%") + + #replace list separator with the path separator (escaped) + STRING(REPLACE ";" "\\;" libpath "${libpath}") + STRING(REPLACE ";" "\\;" pypath "${pypath}") + LIST(APPEND environs "PATH=${libpath}" "PYTHONPATH=${pypath}") + + #generate a bat file that sets the environment and runs the test + SET(bat_file ${CMAKE_CURRENT_BINARY_DIR}/${test_name}_test.bat) + FILE(WRITE ${bat_file} "@echo off\n") + #each line sets an environment variable + FOREACH(environ ${environs}) + FILE(APPEND ${bat_file} "SET ${environ}\n") + ENDFOREACH(environ) + #load the command to run with its arguments + FOREACH(arg ${ARGN}) + FILE(APPEND ${bat_file} "${arg} ") + ENDFOREACH(arg) + FILE(APPEND ${bat_file} "\n") + + ADD_TEST(${test_name} ${bat_file}) + ENDIF(WIN32) + +ENDFUNCTION(GR_ADD_TEST) diff --git a/gr-howto-write-a-block-cmake/grc/CMakeLists.txt b/gr-howto-write-a-block-cmake/grc/CMakeLists.txt new file mode 100644 index 000000000..257113079 --- /dev/null +++ b/gr-howto-write-a-block-cmake/grc/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright 2011 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. + +INSTALL(FILES + howto_square_ff.xml + howto_square2_ff.xml + DESTINATION share/gnuradio/grc/blocks +) diff --git a/gr-howto-write-a-block-cmake/grc/howto_square2_ff.xml b/gr-howto-write-a-block-cmake/grc/howto_square2_ff.xml new file mode 100644 index 000000000..c58ef0047 --- /dev/null +++ b/gr-howto-write-a-block-cmake/grc/howto_square2_ff.xml @@ -0,0 +1,18 @@ +<?xml version="1.0"?> +<block> + <name>Square2</name> + <key>howto_square2_ff</key> + <category>HOWTO</category> + <import>import howto</import> + <make>howto.square2_ff()</make> + + <sink> + <name>in</name> + <type>float</type> + </sink> + + <source> + <name>out</name> + <type>float</type> + </source> +</block> diff --git a/gr-howto-write-a-block-cmake/grc/howto_square_ff.xml b/gr-howto-write-a-block-cmake/grc/howto_square_ff.xml new file mode 100644 index 000000000..34a0b0a3f --- /dev/null +++ b/gr-howto-write-a-block-cmake/grc/howto_square_ff.xml @@ -0,0 +1,18 @@ +<?xml version="1.0"?> +<block> + <name>Square</name> + <key>howto_square_ff</key> + <category>HOWTO</category> + <import>import howto</import> + <make>howto.square_ff()</make> + + <sink> + <name>in</name> + <type>float</type> + </sink> + + <source> + <name>out</name> + <type>float</type> + </source> +</block> diff --git a/gr-howto-write-a-block-cmake/lib/CMakeLists.txt b/gr-howto-write-a-block-cmake/lib/CMakeLists.txt new file mode 100644 index 000000000..798bc6ad6 --- /dev/null +++ b/gr-howto-write-a-block-cmake/lib/CMakeLists.txt @@ -0,0 +1,64 @@ +# Copyright 2011 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. + +######################################################################## +# Setup library +######################################################################## +INCLUDE(GrPlatform) #define LIB_SUFFIX + +ADD_LIBRARY(gnuradio-howto SHARED howto_square_ff.cc howto_square2_ff.cc) +TARGET_LINK_LIBRARIES(gnuradio-howto ${Boost_LIBRARIES} ${GRUEL_LIBRARIES} ${GNURADIO_CORE_LIBRARIES}) +SET_TARGET_PROPERTIES(gnuradio-howto PROPERTIES DEFINE_SYMBOL "gnuradio_howto_EXPORTS") + +######################################################################## +# Install built library files +######################################################################## +INSTALL(TARGETS gnuradio-howto + LIBRARY DESTINATION ${LIB_SUFFIX}/lib # .so/.dylib file + ARCHIVE DESTINATION ${LIB_SUFFIX}/lib # .lib file + RUNTIME DESTINATION bin # .dll file +) + +######################################################################## +# Install public header files +######################################################################## +INSTALL(FILES + howto_api.h + howto_square_ff.h + howto_square2_ff.h + DESTINATION include/howto +) + +######################################################################## +# Build and register unit test +######################################################################## +FIND_PACKAGE(Boost COMPONENTS unit_test_framework) + +INCLUDE(GrTest) +SET(GR_TEST_TARGET_DEPS gnuradio-howto) +#turn each test cpp file into an executable with an int main() function +ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN) + +ADD_EXECUTABLE(qa_howto_square_ff qa_howto_square_ff.cc) +TARGET_LINK_LIBRARIES(qa_howto_square_ff gnuradio-howto ${Boost_LIBRARIES}) +GR_ADD_TEST(qa_howto_square_ff qa_howto_square_ff) + +ADD_EXECUTABLE(qa_howto_square2_ff qa_howto_square2_ff.cc) +TARGET_LINK_LIBRARIES(qa_howto_square2_ff gnuradio-howto ${Boost_LIBRARIES}) +GR_ADD_TEST(qa_howto_square2_ff qa_howto_square2_ff) diff --git a/gr-howto-write-a-block-cmake/lib/howto_api.h b/gr-howto-write-a-block-cmake/lib/howto_api.h new file mode 100644 index 000000000..5263a1cf7 --- /dev/null +++ b/gr-howto-write-a-block-cmake/lib/howto_api.h @@ -0,0 +1,33 @@ +/* + * Copyright 2011 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. + */ + +#ifndef INCLUDED_HOWTO_API_H +#define INCLUDED_HOWTO_API_H + +#include <gruel/attributes.h> + +#ifdef gnuradio_howto_EXPORTS +# define HOWTO_API __GR_ATTR_EXPORT +#else +# define HOWTO_API __GR_ATTR_IMPORT +#endif + +#endif /* INCLUDED_HOWTO_API_H */ diff --git a/gr-howto-write-a-block-cmake/lib/howto_square2_ff.cc b/gr-howto-write-a-block-cmake/lib/howto_square2_ff.cc new file mode 100644 index 000000000..5e0fd7a43 --- /dev/null +++ b/gr-howto-write-a-block-cmake/lib/howto_square2_ff.cc @@ -0,0 +1,92 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2010 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. + */ + +/* + * config.h is generated by configure. It contains the results + * of probing for features, options etc. It should be the first + * file included in your .cc file. + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <howto_square2_ff.h> +#include <gr_io_signature.h> + +/* + * Create a new instance of howto_square2_ff and return + * a boost shared_ptr. This is effectively the public constructor. + */ +howto_square2_ff_sptr +howto_make_square2_ff () +{ + return gnuradio::get_initial_sptr(new howto_square2_ff ()); +} + +/* + * Specify constraints on number of input and output streams. + * This info is used to construct the input and output signatures + * (2nd & 3rd args to gr_block's constructor). The input and + * output signatures are used by the runtime system to + * check that a valid number and type of inputs and outputs + * are connected to this block. In this case, we accept + * only 1 input and 1 output. + */ +static const int MIN_IN = 1; // mininum number of input streams +static const int MAX_IN = 1; // maximum number of input streams +static const int MIN_OUT = 1; // minimum number of output streams +static const int MAX_OUT = 1; // maximum number of output streams + +/* + * The private constructor + */ +howto_square2_ff::howto_square2_ff () + : gr_sync_block ("square2_ff", + gr_make_io_signature (MIN_IN, MAX_IN, sizeof (float)), + gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (float))) +{ + // nothing else required in this example +} + +/* + * Our virtual destructor. + */ +howto_square2_ff::~howto_square2_ff () +{ + // nothing else required in this example +} + +int +howto_square2_ff::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; + + for (int i = 0; i < noutput_items; i++){ + out[i] = in[i] * in[i]; + } + + // Tell runtime system how many output items we produced. + return noutput_items; +} diff --git a/gr-howto-write-a-block-cmake/lib/howto_square2_ff.h b/gr-howto-write-a-block-cmake/lib/howto_square2_ff.h new file mode 100644 index 000000000..c45a1851f --- /dev/null +++ b/gr-howto-write-a-block-cmake/lib/howto_square2_ff.h @@ -0,0 +1,78 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ +#ifndef INCLUDED_HOWTO_SQUARE2_FF_H +#define INCLUDED_HOWTO_SQUARE2_FF_H + +#include <howto_api.h> +#include <gr_sync_block.h> + +class howto_square2_ff; + +/* + * We use boost::shared_ptr's instead of raw pointers for all access + * to gr_blocks (and many other data structures). The shared_ptr gets + * us transparent reference counting, which greatly simplifies storage + * management issues. This is especially helpful in our hybrid + * C++ / Python system. + * + * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm + * + * As a convention, the _sptr suffix indicates a boost::shared_ptr + */ +typedef boost::shared_ptr<howto_square2_ff> howto_square2_ff_sptr; + +/*! + * \brief Return a shared_ptr to a new instance of howto_square2_ff. + * + * To avoid accidental use of raw pointers, howto_square2_ff's + * constructor is private. howto_make_square2_ff is the public + * interface for creating new instances. + */ +HOWTO_API howto_square2_ff_sptr howto_make_square2_ff (); + +/*! + * \brief square2 a stream of floats. + * \ingroup block + * + * This uses the preferred technique: subclassing gr_sync_block. + */ +class HOWTO_API howto_square2_ff : public gr_sync_block +{ +private: + // The friend declaration allows howto_make_square2_ff to + // access the private constructor. + + friend HOWTO_API howto_square2_ff_sptr howto_make_square2_ff (); + + howto_square2_ff (); // private constructor + + public: + ~howto_square2_ff (); // public destructor + + // Where all the action really happens + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_HOWTO_SQUARE2_FF_H */ diff --git a/gr-howto-write-a-block-cmake/lib/howto_square_ff.cc b/gr-howto-write-a-block-cmake/lib/howto_square_ff.cc new file mode 100644 index 000000000..f1d5a7848 --- /dev/null +++ b/gr-howto-write-a-block-cmake/lib/howto_square_ff.cc @@ -0,0 +1,98 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2010 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. + */ + +/* + * config.h is generated by configure. It contains the results + * of probing for features, options etc. It should be the first + * file included in your .cc file. + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <howto_square_ff.h> +#include <gr_io_signature.h> + +/* + * Create a new instance of howto_square_ff and return + * a boost shared_ptr. This is effectively the public constructor. + */ +howto_square_ff_sptr +howto_make_square_ff () +{ + return gnuradio::get_initial_sptr(new howto_square_ff ()); +} + +/* + * Specify constraints on number of input and output streams. + * This info is used to construct the input and output signatures + * (2nd & 3rd args to gr_block's constructor). The input and + * output signatures are used by the runtime system to + * check that a valid number and type of inputs and outputs + * are connected to this block. In this case, we accept + * only 1 input and 1 output. + */ +static const int MIN_IN = 1; // mininum number of input streams +static const int MAX_IN = 1; // maximum number of input streams +static const int MIN_OUT = 1; // minimum number of output streams +static const int MAX_OUT = 1; // maximum number of output streams + +/* + * The private constructor + */ +howto_square_ff::howto_square_ff () + : gr_block ("square_ff", + gr_make_io_signature (MIN_IN, MAX_IN, sizeof (float)), + gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (float))) +{ + // nothing else required in this example +} + +/* + * Our virtual destructor. + */ +howto_square_ff::~howto_square_ff () +{ + // nothing else required in this example +} + +int +howto_square_ff::general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; + + for (int i = 0; i < noutput_items; i++){ + out[i] = in[i] * in[i]; + } + + // Tell runtime system how many input items we consumed on + // each input stream. + + consume_each (noutput_items); + + // Tell runtime system how many output items we produced. + return noutput_items; +} diff --git a/gr-howto-write-a-block-cmake/lib/howto_square_ff.h b/gr-howto-write-a-block-cmake/lib/howto_square_ff.h new file mode 100644 index 000000000..f07a1d4f6 --- /dev/null +++ b/gr-howto-write-a-block-cmake/lib/howto_square_ff.h @@ -0,0 +1,79 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ +#ifndef INCLUDED_HOWTO_SQUARE_FF_H +#define INCLUDED_HOWTO_SQUARE_FF_H + +#include <howto_api.h> +#include <gr_block.h> + +class howto_square_ff; + +/* + * We use boost::shared_ptr's instead of raw pointers for all access + * to gr_blocks (and many other data structures). The shared_ptr gets + * us transparent reference counting, which greatly simplifies storage + * management issues. This is especially helpful in our hybrid + * C++ / Python system. + * + * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm + * + * As a convention, the _sptr suffix indicates a boost::shared_ptr + */ +typedef boost::shared_ptr<howto_square_ff> howto_square_ff_sptr; + +/*! + * \brief Return a shared_ptr to a new instance of howto_square_ff. + * + * To avoid accidental use of raw pointers, howto_square_ff's + * constructor is private. howto_make_square_ff is the public + * interface for creating new instances. + */ +HOWTO_API howto_square_ff_sptr howto_make_square_ff (); + +/*! + * \brief square a stream of floats. + * \ingroup block + * + * \sa howto_square2_ff for a version that subclasses gr_sync_block. + */ +class HOWTO_API howto_square_ff : public gr_block +{ +private: + // The friend declaration allows howto_make_square_ff to + // access the private constructor. + + friend HOWTO_API howto_square_ff_sptr howto_make_square_ff (); + + howto_square_ff (); // private constructor + + public: + ~howto_square_ff (); // public destructor + + // Where all the action really happens + + int general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_HOWTO_SQUARE_FF_H */ diff --git a/gr-howto-write-a-block-cmake/lib/qa_howto_square2_ff.cc b/gr-howto-write-a-block-cmake/lib/qa_howto_square2_ff.cc new file mode 100644 index 000000000..9c37b62c1 --- /dev/null +++ b/gr-howto-write-a-block-cmake/lib/qa_howto_square2_ff.cc @@ -0,0 +1,32 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <boost/test/unit_test.hpp> + +BOOST_AUTO_TEST_CASE(qa_howto_square2_ff_t1){ + BOOST_CHECK_EQUAL(2 + 2, 4); + // TODO BOOST_* test macros here +} + +BOOST_AUTO_TEST_CASE(qa_howto_square2_ff_t2){ + BOOST_CHECK_EQUAL(2 + 2, 4); + // TODO BOOST_* test macros here +} diff --git a/gr-howto-write-a-block-cmake/lib/qa_howto_square_ff.cc b/gr-howto-write-a-block-cmake/lib/qa_howto_square_ff.cc new file mode 100644 index 000000000..da1d3040a --- /dev/null +++ b/gr-howto-write-a-block-cmake/lib/qa_howto_square_ff.cc @@ -0,0 +1,32 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <boost/test/unit_test.hpp> + +BOOST_AUTO_TEST_CASE(qa_howto_square_ff_t1){ + BOOST_CHECK_EQUAL(2 + 2, 4); + // TODO BOOST_* test macros here +} + +BOOST_AUTO_TEST_CASE(qa_howto_square_ff_t2){ + BOOST_CHECK_EQUAL(2 + 2, 4); + // TODO BOOST_* test macros here +} diff --git a/gr-howto-write-a-block-cmake/python/CMakeLists.txt b/gr-howto-write-a-block-cmake/python/CMakeLists.txt new file mode 100644 index 000000000..6208f8a87 --- /dev/null +++ b/gr-howto-write-a-block-cmake/python/CMakeLists.txt @@ -0,0 +1,44 @@ +# Copyright 2011 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 python install macros +######################################################################## +INCLUDE(GrPython) +IF(NOT PYTHONINTERP_FOUND) + RETURN() +ENDIF() + +######################################################################## +# Install python sources +######################################################################## +GR_PYTHON_INSTALL( + FILES + __init__.py + DESTINATION ${GR_PYTHON_DIR}/howto +) + +######################################################################## +# Handle the unit tests +######################################################################## +INCLUDE(GrTest) + +SET(GR_TEST_TARGET_DEPS gnuradio-howto) +SET(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/swig) +GR_ADD_TEST(qa_howto ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_howto.py) diff --git a/gr-howto-write-a-block-cmake/python/__init__.py b/gr-howto-write-a-block-cmake/python/__init__.py new file mode 100644 index 000000000..d4a41c271 --- /dev/null +++ b/gr-howto-write-a-block-cmake/python/__init__.py @@ -0,0 +1,49 @@ +# +# Copyright 2008,2009 Free Software Foundation, Inc. +# +# This application 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. +# +# This application 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 this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +# The presence of this file turns this directory into a Python package + +# ---------------------------------------------------------------- +# Temporary workaround for ticket:181 (swig+python problem) +import sys +_RTLD_GLOBAL = 0 +try: + from dl import RTLD_GLOBAL as _RTLD_GLOBAL +except ImportError: + try: + from DLFCN import RTLD_GLOBAL as _RTLD_GLOBAL + except ImportError: + pass + +if _RTLD_GLOBAL != 0: + _dlopenflags = sys.getdlopenflags() + sys.setdlopenflags(_dlopenflags|_RTLD_GLOBAL) +# ---------------------------------------------------------------- + + +# import swig generated symbols into the howto namespace +from howto_swig import * + +# import any pure python here +# + +# ---------------------------------------------------------------- +# Tail of workaround +if _RTLD_GLOBAL != 0: + sys.setdlopenflags(_dlopenflags) # Restore original flags +# ---------------------------------------------------------------- diff --git a/gr-howto-write-a-block-cmake/python/qa_howto.py b/gr-howto-write-a-block-cmake/python/qa_howto.py new file mode 100755 index 000000000..630f57bf4 --- /dev/null +++ b/gr-howto-write-a-block-cmake/python/qa_howto.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007 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. +# + +from gnuradio import gr, gr_unittest +import howto_swig + +class qa_howto (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001_square_ff (self): + src_data = (-3, 4, -5.5, 2, 3) + expected_result = (9, 16, 30.25, 4, 9) + src = gr.vector_source_f (src_data) + sqr = howto_swig.square_ff () + dst = gr.vector_sink_f () + self.tb.connect (src, sqr) + self.tb.connect (sqr, dst) + self.tb.run () + result_data = dst.data () + self.assertFloatTuplesAlmostEqual (expected_result, result_data, 6) + + def test_002_square2_ff (self): + src_data = (-3, 4, -5.5, 2, 3) + expected_result = (9, 16, 30.25, 4, 9) + src = gr.vector_source_f (src_data) + sqr = howto_swig.square2_ff () + dst = gr.vector_sink_f () + self.tb.connect (src, sqr) + self.tb.connect (sqr, dst) + self.tb.run () + result_data = dst.data () + self.assertFloatTuplesAlmostEqual (expected_result, result_data, 6) + +if __name__ == '__main__': + gr_unittest.main () diff --git a/gr-howto-write-a-block-cmake/swig/CMakeLists.txt b/gr-howto-write-a-block-cmake/swig/CMakeLists.txt new file mode 100644 index 000000000..40f2b1051 --- /dev/null +++ b/gr-howto-write-a-block-cmake/swig/CMakeLists.txt @@ -0,0 +1,55 @@ +# Copyright 2011 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 swig generation macros +######################################################################## +FIND_PACKAGE(SWIG) +FIND_PACKAGE(PythonLibs) +IF(NOT SWIG_FOUND OR NOT PYTHONLIBS_FOUND) + RETURN() +ENDIF() +INCLUDE(GrSwig) + +######################################################################## +# Setup swig generation +######################################################################## +FOREACH(incdir ${GNURADIO_CORE_INCLUDE_DIRS}) + LIST(APPEND GR_SWIG_INCLUDE_DIRS ${incdir}/swig) +ENDFOREACH(incdir) + +SET(GR_SWIG_LIBRARIES gnuradio-howto) + +GR_SWIG_MAKE(howto_swig howto_swig.i) + +######################################################################## +# Install the build swig module +######################################################################## +GR_SWIG_INSTALL(TARGETS howto_swig DESTINATION ${GR_PYTHON_DIR}/howto) + +######################################################################## +# Install swig .i files for development +######################################################################## +INSTALL( + FILES + howto_swig.i + howto_square_ff.i + howto_square2_ff.i + DESTINATION include/howto/swig +) diff --git a/gr-howto-write-a-block-cmake/swig/howto_square2_ff.i b/gr-howto-write-a-block-cmake/swig/howto_square2_ff.i new file mode 100644 index 000000000..683a93d61 --- /dev/null +++ b/gr-howto-write-a-block-cmake/swig/howto_square2_ff.i @@ -0,0 +1,9 @@ +GR_SWIG_BLOCK_MAGIC(howto,square2_ff); + +howto_square2_ff_sptr howto_make_square2_ff (); + +class howto_square2_ff : public gr_sync_block +{ +private: + howto_square2_ff (); +}; diff --git a/gr-howto-write-a-block-cmake/swig/howto_square_ff.i b/gr-howto-write-a-block-cmake/swig/howto_square_ff.i new file mode 100644 index 000000000..f8ae76986 --- /dev/null +++ b/gr-howto-write-a-block-cmake/swig/howto_square_ff.i @@ -0,0 +1,16 @@ +/* + * First arg is the package prefix. + * Second arg is the name of the class minus the prefix. + * + * This does some behind-the-scenes magic so we can + * access howto_square_ff from python as howto.square_ff + */ +GR_SWIG_BLOCK_MAGIC(howto,square_ff); + +howto_square_ff_sptr howto_make_square_ff (); + +class howto_square_ff : public gr_block +{ +private: + howto_square_ff (); +}; diff --git a/gr-howto-write-a-block-cmake/swig/howto_swig.i b/gr-howto-write-a-block-cmake/swig/howto_swig.i new file mode 100644 index 000000000..d0bbcdc11 --- /dev/null +++ b/gr-howto-write-a-block-cmake/swig/howto_swig.i @@ -0,0 +1,21 @@ +/* -*- c++ -*- */ + +%include "gnuradio.i" // the common stuff + +%{ +#include "howto_square_ff.h" +#include "howto_square2_ff.h" +%} + +%include "howto_square_ff.i" +%include "howto_square2_ff.i" + +#if SWIGGUILE +%scheme %{ +(load-extension-global "libguile-gnuradio-howto_swig" "scm_init_gnuradio_howto_swig_module") +%} + +%goops %{ +(use-modules (gnuradio gnuradio_core_runtime)) +%} +#endif |