diff options
author | Josh Blum | 2013-07-28 00:07:38 -0700 |
---|---|---|
committer | Josh Blum | 2013-07-28 00:07:38 -0700 |
commit | e867fc098a73aadf52cace1020e8aae4c5d178ff (patch) | |
tree | 9d65e1ea9eba0700faf81b66107714bca8b76d2a /cmake/Modules | |
parent | 68d1ba60dc7b38ec4571a2e957c4136d3170177a (diff) | |
download | sandhi-e867fc098a73aadf52cace1020e8aae4c5d178ff.tar.gz sandhi-e867fc098a73aadf52cace1020e8aae4c5d178ff.tar.bz2 sandhi-e867fc098a73aadf52cace1020e8aae4c5d178ff.zip |
gras: squashed tool work with changes
Diffstat (limited to 'cmake/Modules')
-rw-r--r-- | cmake/Modules/CMakeLists.txt | 18 | ||||
-rw-r--r-- | cmake/Modules/GRASTool.in.cmake | 163 | ||||
-rw-r--r-- | cmake/Modules/GrTest.cmake | 139 |
3 files changed, 320 insertions, 0 deletions
diff --git a/cmake/Modules/CMakeLists.txt b/cmake/Modules/CMakeLists.txt new file mode 100644 index 0000000..d2eb07f --- /dev/null +++ b/cmake/Modules/CMakeLists.txt @@ -0,0 +1,18 @@ +######################################################################## +# 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 + ${CMAKE_CURRENT_SOURCE_DIR}/GrTest.cmake + DESTINATION share/gras/cmake/Modules + COMPONENT ${GRAS_COMP_DEVEL} +) diff --git a/cmake/Modules/GRASTool.in.cmake b/cmake/Modules/GRASTool.in.cmake new file mode 100644 index 0000000..5991b03 --- /dev/null +++ b/cmake/Modules/GRASTool.in.cmake @@ -0,0 +1,163 @@ +if(DEFINED __INCLUDED_GRAS_TOOL_CMAKE) + return() +endif() +set(__INCLUDED_GRAS_TOOL_CMAKE TRUE) + +######################################################################## +## 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() + +######################################################################## +## 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}) + + #were to look for development files + set(GRAS_TOOL_INCLUDE_DIR ${GRAS_ROOT}/include) + set(GRAS_TOOL_LIBRARY_DIR ${GRAS_ROOT}/lib@LIBSUFFIX@) + + include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + + #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() + include_directories(${PMC_INCLUDE_DIRS}) + if (NOT GRAS_INCLUDE_DIRS) + find_path( + GRAS_INCLUDE_DIRS + NAMES gras/gras.hpp + PATHS ${GRAS_TOOL_INCLUDE_DIR} + ) + endif() + include_directories(${GRAS_INCLUDE_DIRS}) + + #locate PMC and GRAS libraries + if (NOT PMC_LIBRARIES) + find_library( + PMC_LIBRARIES + NAMES pmc + PATHS ${GRAS_TOOL_LIBRARY_DIR} + ) + endif() + list(APPEND GRAS_TOOL_LIBRARIES ${PMC_LIBRARIES}) + if (NOT GRAS_LIBRARIES) + find_library( + GRAS_LIBRARIES + NAMES gras + PATHS ${GRAS_TOOL_LIBRARY_DIR} + ) + endif() + list(APPEND GRAS_TOOL_LIBRARIES ${GRAS_LIBRARIES}) + + #and boost includes as well + if (NOT Boost_FOUND) + find_package(Boost COMPONENTS) + if (NOT Boost_FOUND) + message(FATAL_ERROR "GRAS_TOOL could not find boost headers!") + endif() + endif() + 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 + ) + + get_target_property(module_location ${GRAS_TOOL_TARGET} LOCATION) + string(REPLACE "$(Configuration)" ${CMAKE_BUILD_TYPE} module_location ${module_location}) + set(${GRAS_TOOL_TARGET}_LOCATION ${module_location} PARENT_SCOPE) + + 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) 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) |