summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorJosh Blum2013-07-31 01:10:32 -0700
committerJosh Blum2013-07-31 01:10:32 -0700
commit20b413bce5c22bcc44bfc58105288df94a0a592d (patch)
treee4df40c82c89fda275ec36df42715b27b7a75708 /cmake
parent79128f57c01a2453a71f9b0aa00d919c0a79666f (diff)
parent8fc35a79f138cc9c5d60affd20ca91767d16927f (diff)
downloadsandhi-20b413bce5c22bcc44bfc58105288df94a0a592d.tar.gz
sandhi-20b413bce5c22bcc44bfc58105288df94a0a592d.tar.bz2
sandhi-20b413bce5c22bcc44bfc58105288df94a0a592d.zip
Merge branch 'gras_tool3'
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Modules/CMakeLists.txt20
-rw-r--r--cmake/Modules/GRASCommon.cmake64
-rw-r--r--cmake/Modules/GRASTool.in.cmake262
-rw-r--r--cmake/Modules/GrPython.cmake232
-rw-r--r--cmake/Modules/GrTest.cmake139
5 files changed, 717 insertions, 0 deletions
diff --git a/cmake/Modules/CMakeLists.txt b/cmake/Modules/CMakeLists.txt
new file mode 100644
index 0000000..d275f71
--- /dev/null
+++ b/cmake/Modules/CMakeLists.txt
@@ -0,0 +1,20 @@
+########################################################################
+# Install cmake modules to known location
+########################################################################
+configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/GRASTool.in.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/GRASTool.cmake
+@ONLY)
+list(APPEND GRAS_TOOL_SOURCES
+ ${CMAKE_CURRENT_BINARY_DIR}/GRASTool.cmake
+)
+
+install(
+ FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/GRASTool.cmake
+ GRASCommon.cmake
+ GrTest.cmake
+ GrPython.cmake
+ DESTINATION share/gras/cmake/Modules
+ COMPONENT ${GRAS_COMP_DEVEL}
+)
diff --git a/cmake/Modules/GRASCommon.cmake b/cmake/Modules/GRASCommon.cmake
new file mode 100644
index 0000000..6844dd4
--- /dev/null
+++ b/cmake/Modules/GRASCommon.cmake
@@ -0,0 +1,64 @@
+if(DEFINED __INCLUDED_GRAS_COMMON_CMAKE)
+ return()
+endif()
+set(__INCLUDED_GRAS_COMMON_CMAKE TRUE)
+
+########################################################################
+# 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 "")
+
+########################################################################
+# Setup Boost defines that get used before find_package(Boost)
+########################################################################
+if(UNIX AND NOT BOOST_ROOT AND EXISTS "/usr/lib64" AND NOT BOOST_LIBRARYDIR)
+ list(APPEND BOOST_LIBRARYDIR "/usr/lib64") #fedora 64-bit fix
+endif(UNIX AND NOT BOOST_ROOT AND EXISTS "/usr/lib64" AND NOT BOOST_LIBRARYDIR)
+
+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"
+)
+
+if(NOT Boost_INCLUDE_DIRS)
+ find_package(Boost)
+ if(NOT Boost_FOUND)
+ message(FATAL_ERROR "Boost C++ headers not found - required for GRAS_TOOL")
+ endif()
+endif()
+
+########################################################################
+# Linux detection stuff
+########################################################################
+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()
+
+if(LINUX AND EXISTS "/etc/slackware-version")
+ set(SLACKWARE TRUE)
+endif()
+
+########################################################################
+# Automatic LIB_SUFFIX detection + configuration option
+########################################################################
+IF(NOT DEFINED LIB_SUFFIX AND (REDHAT OR SLACKWARE) AND CMAKE_SYSTEM_PROCESSOR MATCHES "64$")
+ SET(LIB_SUFFIX 64)
+ENDIF()
+SET(LIB_SUFFIX ${LIB_SUFFIX} CACHE STRING "lib directory suffix")
diff --git a/cmake/Modules/GRASTool.in.cmake b/cmake/Modules/GRASTool.in.cmake
new file mode 100644
index 0000000..502b271
--- /dev/null
+++ b/cmake/Modules/GRASTool.in.cmake
@@ -0,0 +1,262 @@
+if(DEFINED __INCLUDED_GRAS_TOOL_CMAKE)
+ return()
+endif()
+set(__INCLUDED_GRAS_TOOL_CMAKE TRUE)
+
+include(GRASCommon)
+
+########################################################################
+## Define GRAS_TOOL_PATH_SEP for utility purposes
+########################################################################
+if(UNIX)
+ set(GRAS_TOOL_PATH_SEP ":")
+elseif(WIN32)
+ set(GRAS_TOOL_PATH_SEP "\\;")
+else()
+ set(GRAS_TOOL_PATH_SEP ":")
+endif()
+
+########################################################################
+## Set installation constants
+## The GRAS_ROOT can be set via arg or environment variable
+########################################################################
+if(GRAS_ROOT)
+ #its already set
+elseif($ENV{GRAS_ROOT})
+ set(GRAS_ROOT $ENV{GRAS_ROOT})
+else()
+ set(GRAS_ROOT "@CMAKE_INSTALL_PREFIX@")
+endif()
+
+########################################################################
+## where to look for development files
+########################################################################
+set(GRAS_TOOL_INCLUDE_DIR ${GRAS_ROOT}/include)
+set(GRAS_TOOL_LIBRARY_DIR ${GRAS_ROOT}/lib@LIBSUFFIX@)
+
+#locate PMC and GRAS includes
+if (NOT PMC_INCLUDE_DIRS)
+ find_path(
+ PMC_INCLUDE_DIRS
+ NAMES PMC/PMC.hpp
+ PATHS ${GRAS_TOOL_INCLUDE_DIR}
+ )
+endif()
+if (NOT GRAS_INCLUDE_DIRS)
+ find_path(
+ GRAS_INCLUDE_DIRS
+ NAMES gras/gras.hpp
+ PATHS ${GRAS_TOOL_INCLUDE_DIR}
+ )
+endif()
+
+#locate PMC and GRAS libraries
+if (NOT PMC_LIBRARIES)
+ find_library(
+ PMC_LIBRARIES
+ NAMES pmc
+ PATHS ${GRAS_TOOL_LIBRARY_DIR}
+ )
+endif()
+if (NOT GRAS_LIBRARIES)
+ find_library(
+ GRAS_LIBRARIES
+ NAMES gras
+ PATHS ${GRAS_TOOL_LIBRARY_DIR}
+ )
+endif()
+
+########################################################################
+## GRAS_TOOL cmake function - the swiss army knife for GRAS users
+##
+## Options:
+## SOURCES - list of C++, Python, and GRC sources
+## TARGET - project name, used for library, and install prefix
+## DIRECTORY - name of installation directory or ${TARGET}
+## COMPONENT - name of installation component or ${TARGET}
+##
+## External vars:
+## GRAS_TOOL_LIBRARIES - list of additional libraries to link to
+########################################################################
+function(GRAS_TOOL)
+
+ include(CMakeParseArguments)
+ CMAKE_PARSE_ARGUMENTS(GRAS_TOOL "" "TARGET;DIRECTORY;COMPONENT" "SOURCES" ${ARGN})
+
+ #give an install directory if not specified
+ if(NOT GRAS_TOOL_DIRECTORY)
+ set(GRAS_TOOL_DIRECTORY ${GRAS_TOOL_TARGET})
+ endif()
+
+ #give the target a component name if not specified
+ if(NOT GRAS_TOOL_COMPONENT)
+ set(GRAS_TOOL_COMPONENT ${GRAS_TOOL_TARGET})
+ endif()
+
+ unset(GRAS_TOOL_CPP_SOURCES)
+ unset(GRAS_TOOL_PY_SOURCES)
+ unset(GRAS_TOOL_GRC_SOURCES)
+ foreach(source ${GRAS_TOOL_SOURCES})
+ get_filename_component(source_ext ${source} EXT)
+ if ("${source_ext}" STREQUAL ".cpp")
+ list(APPEND GRAS_TOOL_CPP_SOURCES ${source})
+ endif()
+ if ("${source_ext}" STREQUAL ".cxx")
+ list(APPEND GRAS_TOOL_CPP_SOURCES ${source})
+ endif()
+ if ("${source_ext}" STREQUAL ".cc")
+ list(APPEND GRAS_TOOL_CPP_SOURCES ${source})
+ endif()
+ if ("${source_ext}" STREQUAL ".c")
+ list(APPEND GRAS_TOOL_CPP_SOURCES ${source})
+ endif()
+ if ("${source_ext}" STREQUAL ".py")
+ list(APPEND GRAS_TOOL_PY_SOURCES ${source})
+ endif()
+ if ("${source_ext}" STREQUAL ".xml")
+ list(APPEND GRAS_TOOL_GRC_SOURCES ${source})
+ endif()
+ if ("${source_ext}" STREQUAL ".yml")
+ list(APPEND GRAS_TOOL_GRC_SOURCES ${source})
+ endif()
+ endforeach(source)
+
+ #suffix install path for project name
+ set(GRAS_TOOL_MOD_DIR lib@LIBSUFFIX@/gras/modules/${GRAS_TOOL_DIRECTORY})
+ set(GRAS_TOOL_PYTHON_DIR lib@LIBSUFFIX@/gras/python/${GRAS_TOOL_DIRECTORY})
+ set(GRAS_TOOL_GRC_DIR share/gnuradio/grc/blocks/${GRAS_TOOL_DIRECTORY})
+
+ #development and framework directories
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+ include_directories(${PMC_INCLUDE_DIRS})
+ include_directories(${GRAS_INCLUDE_DIRS})
+ list(APPEND GRAS_TOOL_LIBRARIES ${PMC_LIBRARIES})
+ list(APPEND GRAS_TOOL_LIBRARIES ${GRAS_LIBRARIES})
+
+ #and boost includes as well
+ include_directories(${Boost_INCLUDE_DIRS})
+
+ #build and install module to path
+ if (GRAS_TOOL_CPP_SOURCES)
+ add_library(${GRAS_TOOL_TARGET} MODULE ${GRAS_TOOL_CPP_SOURCES})
+ target_link_libraries(${GRAS_TOOL_TARGET} ${GRAS_TOOL_LIBRARIES})
+ install(TARGETS ${GRAS_TOOL_TARGET}
+ LIBRARY DESTINATION ${GRAS_TOOL_MOD_DIR} COMPONENT ${GRAS_TOOL_COMPONENT} # .so file
+ ARCHIVE DESTINATION ${GRAS_TOOL_MOD_DIR} COMPONENT ${GRAS_TOOL_COMPONENT} # .lib file
+ RUNTIME DESTINATION ${GRAS_TOOL_MOD_DIR} COMPONENT ${GRAS_TOOL_COMPONENT} # .dll file
+ )
+
+ #export global variables for help locating build targets
+ get_target_property(module_location ${GRAS_TOOL_TARGET} LOCATION)
+ string(REGEX REPLACE "\\$\\(.*\\)" ${CMAKE_BUILD_TYPE} module_location ${module_location})
+ list(APPEND GRAS_TOOL_MODULE_LOCATIONS ${module_location})
+ set(GRAS_TOOL_MODULE_LOCATIONS ${GRAS_TOOL_MODULE_LOCATIONS} CACHE INTERNAL "")
+ string(REPLACE ";" "${GRAS_TOOL_PATH_SEP}" GRAS_TOOL_MODULE_PATH "${GRAS_TOOL_MODULE_LOCATIONS}")
+ set(GRAS_TOOL_MODULE_PATH ${GRAS_TOOL_MODULE_PATH} CACHE INTERNAL "")
+ set(${GRAS_TOOL_TARGET}_LOCATION ${module_location} CACHE INTERNAL "")
+ endif()
+
+ #python module install
+ if (GRAS_TOOL_PY_SOURCES)
+ install(
+ FILES ${GRAS_TOOL_PY_SOURCES}
+ DESTINATION ${GRAS_TOOL_PYTHON_DIR}
+ COMPONENT ${GRAS_TOOL_COMPONENT}
+ )
+ endif()
+
+ #install GRC files
+ if (GRAS_TOOL_GRC_SOURCES)
+ install(
+ FILES ${GRAS_TOOL_GRC_SOURCES}
+ DESTINATION ${GRAS_TOOL_GRC_DIR}
+ COMPONENT ${GRAS_TOOL_COMPONENT}
+ )
+ endif()
+
+endfunction(GRAS_TOOL)
+
+########################################################################
+## GRAS_SWIG_TOOL cmake function - export new types for the loader
+##
+## Options:
+## SOURCE - the swig .i file
+## TARGET - target name for the build products
+## DIRECTORY - name of installation directory or ${TARGET}
+## COMPONENT - name of installation component or ${TARGET}
+##
+## External vars:
+## GRAS_SWIG_TOOL_INCLUDES - list of additional include directories
+## GRAS_SWIG_TOOL_LIBRARIES - list of additional libraries to link to
+########################################################################
+function(GRAS_SWIG_TOOL)
+
+ find_package(SWIG)
+ if(NOT SWIG_FOUND)
+ return()
+ endif()
+
+ find_package(PythonLibs)
+ if(NOT PYTHONLIBS_FOUND)
+ return()
+ endif()
+
+ include(CMakeParseArguments)
+ CMAKE_PARSE_ARGUMENTS(GRAS_SWIG_TOOL "" "SOURCE;TARGET;DIRECTORY;COMPONENT" "" ${ARGN})
+
+ #give an install directory if not specified
+ if(NOT GRAS_SWIG_TOOL_DIRECTORY)
+ set(GRAS_SWIG_TOOL_DIRECTORY ${GRAS_SWIG_TOOL_TARGET})
+ endif()
+
+ #give the target a component name if not specified
+ if(NOT GRAS_SWIG_TOOL_COMPONENT)
+ set(GRAS_SWIG_TOOL_COMPONENT ${GRAS_SWIG_TOOL_TARGET})
+ endif()
+
+ #development and framework directories
+ list(APPEND GRAS_SWIG_TOOL_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR})
+ list(APPEND GRAS_SWIG_TOOL_INCLUDES ${PMC_SWIG_INCLUDE_DIRS})
+ list(APPEND GRAS_SWIG_TOOL_INCLUDES ${GRAS_SWIG_INCLUDE_DIRS})
+ list(APPEND GRAS_SWIG_TOOL_LIBRARIES ${PMC_LIBRARIES})
+ list(APPEND GRAS_SWIG_TOOL_LIBRARIES ${GRAS_LIBRARIES})
+
+ #and boost includes as well
+ include_directories(${Boost_INCLUDE_DIRS})
+
+ #setup python includes/libs
+ include_directories(${PYTHON_INCLUDE_PATH})
+ include_directories(${PYTHON_INCLUDE_DIRS})
+ list(APPEND GRAS_SWIG_TOOL_LIBRARIES ${PYTHON_LIBRARIES})
+
+ #include swig generation deps for compiling
+ include_directories(${GRAS_SWIG_TOOL_INCLUDES})
+
+ #set the C++ property on the swig .i file so it builds
+ set_source_files_properties(${GRAS_SWIG_TOOL_SOURCE} PROPERTIES CPLUSPLUS ON)
+
+ #setup swig flags
+ foreach(inc ${GRAS_SWIG_TOOL_INCLUDES})
+ list(APPEND CMAKE_SWIG_FLAGS "-I${inc}")
+ endforeach(inc)
+ set(CMAKE_SWIG_FLAGS -fvirtual -module ${GRAS_SWIG_TOOL_TARGET} ${CMAKE_SWIG_FLAGS})
+
+ #register swig build
+ include(UseSWIG)
+ SWIG_ADD_MODULE(${GRAS_SWIG_TOOL_TARGET} python ${GRAS_SWIG_TOOL_SOURCE})
+ SWIG_LINK_LIBRARIES(${GRAS_SWIG_TOOL_TARGET} ${GRAS_SWIG_TOOL_LIBRARIES})
+
+ #install rules for generated module and py file
+ set(GRAS_TOOL_PYTHON_DIR lib@LIBSUFFIX@/gras/python/${GRAS_SWIG_TOOL_DIRECTORY})
+ install(
+ TARGETS ${SWIG_MODULE_${GRAS_SWIG_TOOL_TARGET}_REAL_NAME}
+ DESTINATION ${GRAS_TOOL_PYTHON_DIR}
+ COMPONENT ${GRAS_SWIG_TOOL_COMPONENT}
+ )
+ install(
+ FILES ${CMAKE_CURRENT_BINARY_DIR}/${GRAS_SWIG_TOOL_TARGET}.py
+ DESTINATION ${GRAS_TOOL_PYTHON_DIR}
+ COMPONENT ${GRAS_SWIG_TOOL_COMPONENT}
+ )
+
+endfunction(GRAS_SWIG_TOOL)
diff --git a/cmake/Modules/GrPython.cmake b/cmake/Modules/GrPython.cmake
new file mode 100644
index 0000000..e598df4
--- /dev/null
+++ b/cmake/Modules/GrPython.cmake
@@ -0,0 +1,232 @@
+# 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")
+
+#make sure we can use -B with python (introduced in 2.6)
+if(PYTHON_EXECUTABLE)
+ execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} -B -c ""
+ OUTPUT_QUIET ERROR_QUIET
+ RESULT_VARIABLE PYTHON_HAS_DASH_B_RESULT
+ )
+ if(PYTHON_HAS_DASH_B_RESULT EQUAL 0)
+ set(PYTHON_DASH_B "-B")
+ endif()
+endif(PYTHON_EXECUTABLE)
+
+########################################################################
+# 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}
+ assert ${cmd}
+except ImportError, AssertionError: exit(-1)
+except: pass
+#########################################"
+ 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(CMakeParseArguments)
+ CMAKE_PARSE_ARGUMENTS(GR_PYTHON_INSTALL "" "DESTINATION;COMPONENT" "FILES;PROGRAMS" ${ARGN})
+
+ ####################################################################
+ if(GR_PYTHON_INSTALL_FILES)
+ ####################################################################
+ install(${ARGN}) #installs regular python files
+
+ #create a list of all generated files
+ unset(pysrcfiles)
+ unset(pycfiles)
+ unset(pyofiles)
+ foreach(pyfile ${GR_PYTHON_INSTALL_FILES})
+ get_filename_component(pyfile ${pyfile} ABSOLUTE)
+ list(APPEND pysrcfiles ${pyfile})
+
+ #determine if this file is in the source or binary directory
+ file(RELATIVE_PATH source_rel_path ${CMAKE_CURRENT_SOURCE_DIR} ${pyfile})
+ string(LENGTH "${source_rel_path}" source_rel_path_len)
+ file(RELATIVE_PATH binary_rel_path ${CMAKE_CURRENT_BINARY_DIR} ${pyfile})
+ string(LENGTH "${binary_rel_path}" binary_rel_path_len)
+
+ #and set the generated path appropriately
+ if(${source_rel_path_len} GREATER ${binary_rel_path_len})
+ set(pygenfile ${CMAKE_CURRENT_BINARY_DIR}/${binary_rel_path})
+ else()
+ set(pygenfile ${CMAKE_CURRENT_BINARY_DIR}/${source_rel_path})
+ endif()
+ list(APPEND pycfiles ${pygenfile}c)
+ list(APPEND pyofiles ${pygenfile}o)
+
+ #ensure generation path exists
+ get_filename_component(pygen_path ${pygenfile} PATH)
+ file(MAKE_DIRECTORY ${pygen_path})
+
+ endforeach(pyfile)
+
+ #the command to generate the pyc files
+ add_custom_command(
+ DEPENDS ${pysrcfiles} OUTPUT ${pycfiles}
+ COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_BINARY_DIR}/python_compile_helper.py ${pysrcfiles} ${pycfiles}
+ )
+
+ #the command to generate the pyo files
+ add_custom_command(
+ DEPENDS ${pysrcfiles} OUTPUT ${pyofiles}
+ COMMAND ${PYTHON_EXECUTABLE} -O ${CMAKE_BINARY_DIR}/python_compile_helper.py ${pysrcfiles} ${pyofiles}
+ )
+
+ #create install rule and add generated files to target list
+ set(python_install_gen_targets ${pycfiles} ${pyofiles})
+ install(FILES ${python_install_gen_targets}
+ DESTINATION ${GR_PYTHON_INSTALL_DESTINATION}
+ COMPONENT ${GR_PYTHON_INSTALL_COMPONENT}
+ )
+
+
+ ####################################################################
+ elseif(GR_PYTHON_INSTALL_PROGRAMS)
+ ####################################################################
+ file(TO_NATIVE_PATH ${PYTHON_EXECUTABLE} pyexe_native)
+
+ if (CMAKE_CROSSCOMPILING)
+ set(pyexe_native /usr/bin/env python)
+ endif()
+
+ 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)
+
+########################################################################
+# Write the python helper script that generates byte code files
+########################################################################
+file(WRITE ${CMAKE_BINARY_DIR}/python_compile_helper.py "
+import sys, py_compile
+files = sys.argv[1:]
+srcs, gens = files[:len(files)/2], files[len(files)/2:]
+for src, gen in zip(srcs, gens):
+ py_compile.compile(file=src, cfile=gen, doraise=True)
+")
diff --git a/cmake/Modules/GrTest.cmake b/cmake/Modules/GrTest.cmake
new file mode 100644
index 0000000..bb045dc
--- /dev/null
+++ b/cmake/Modules/GrTest.cmake
@@ -0,0 +1,139 @@
+# 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
+# GR_TEST_ENVIRONS - other environment key/value pairs
+########################################################################
+function(GR_ADD_TEST test_name)
+
+ #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)
+
+ if(WIN32)
+ #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}")
+ list(APPEND environs ${GR_TEST_ENVIRONS})
+
+ #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(LD_PATH_VAR "LD_LIBRARY_PATH")
+ if(APPLE)
+ set(LD_PATH_VAR "DYLD_LIBRARY_PATH")
+ endif()
+
+ set(binpath "${CMAKE_CURRENT_BINARY_DIR}:$PATH")
+ list(APPEND libpath "$${LD_PATH_VAR}")
+ 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_PATH_VAR}=${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)