diff options
author | Josh Blum | 2013-07-31 19:43:16 -0700 |
---|---|---|
committer | Josh Blum | 2013-07-31 19:43:16 -0700 |
commit | 66e0614b1867045d5dc3bf7ba997b9ed79546adb (patch) | |
tree | c76b88e8966441bc3569dd9ea140600e2138c26c | |
parent | 20b413bce5c22bcc44bfc58105288df94a0a592d (diff) | |
download | sandhi-66e0614b1867045d5dc3bf7ba997b9ed79546adb.tar.gz sandhi-66e0614b1867045d5dc3bf7ba997b9ed79546adb.tar.bz2 sandhi-66e0614b1867045d5dc3bf7ba997b9ed79546adb.zip |
grextras: create test macro that works w/ tool
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | cmake/Modules/CMakeLists.txt | 12 | ||||
-rw-r--r-- | cmake/Modules/GRASCommon.cmake | 11 | ||||
-rw-r--r-- | cmake/Modules/GRASPython.cmake (renamed from cmake/Modules/GrPython.cmake) | 4 | ||||
-rw-r--r-- | cmake/Modules/GRASSwig.in.cmake | 91 | ||||
-rw-r--r-- | cmake/Modules/GRASTest.cmake (renamed from cmake/Modules/GrTest.cmake) | 46 | ||||
-rw-r--r-- | cmake/Modules/GRASTool.in.cmake | 103 |
7 files changed, 144 insertions, 129 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d7f533c..459ff90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,7 +153,7 @@ CPACK_COMPONENT("${GRAS_COMP_PYTHON}" list(APPEND CMAKE_MODULE_PATH ${GRAS_SOURCE_DIR}/cmake/Modules) list(APPEND CMAKE_MODULE_PATH ${GRAS_BINARY_DIR}/cmake/Modules) set(GRAS_ROOT ${GRAS_SOURCE_DIR}) -list(APPEND GR_TEST_ENVIRONS "GRAS_ROOT=${GRAS_SOURCE_DIR}") +list(APPEND GRAS_TEST_ENVIRONS "GRAS_ROOT=${GRAS_SOURCE_DIR}") set(CMAKE_SOURCE_DIR ${GRAS_SOURCE_DIR}/grextras) set(CMAKE_BINARY_DIR ${GRAS_BINARY_DIR}/grextras) @@ -203,6 +203,10 @@ if(ENABLE_GR_DIGITAL) list(APPEND GR_TEST_TARGET_DEPS gnuradio-digital gnuradio-filter gnuradio-fft gnuradio-analog) endif(ENABLE_GR_DIGITAL) +list(APPEND GRAS_TEST_TARGET_DEPS "${GR_TEST_TARGET_DEPS}") +list(APPEND GRAS_TEST_LIBRARY_DIRS "${GR_TEST_LIBRARY_DIRS}") +list(APPEND GRAS_TEST_PYTHON_DIRS "${GR_TEST_PYTHON_DIRS}") + add_subdirectory(grextras) ######################################################################## diff --git a/cmake/Modules/CMakeLists.txt b/cmake/Modules/CMakeLists.txt index d275f71..9774ea1 100644 --- a/cmake/Modules/CMakeLists.txt +++ b/cmake/Modules/CMakeLists.txt @@ -5,16 +5,18 @@ 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 -) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/GRASSwig.in.cmake + ${CMAKE_CURRENT_BINARY_DIR}/GRASSwig.cmake +@ONLY) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/GRASTool.cmake + ${CMAKE_CURRENT_BINARY_DIR}/GRASSwig.cmake GRASCommon.cmake - GrTest.cmake - GrPython.cmake + GRASTest.cmake + GRASPython.cmake DESTINATION share/gras/cmake/Modules COMPONENT ${GRAS_COMP_DEVEL} ) diff --git a/cmake/Modules/GRASCommon.cmake b/cmake/Modules/GRASCommon.cmake index 6844dd4..b5440f2 100644 --- a/cmake/Modules/GRASCommon.cmake +++ b/cmake/Modules/GRASCommon.cmake @@ -4,6 +4,17 @@ endif() set(__INCLUDED_GRAS_COMMON_CMAKE TRUE) ######################################################################## +## Define ENV_VAR_PATH_SEP for utility purposes +######################################################################## +if(UNIX) + set(ENV_VAR_PATH_SEP ":") +elseif(WIN32) + set(ENV_VAR_PATH_SEP "\\;") +else() + set(ENV_VAR_PATH_SEP ":") +endif() + +######################################################################## # select the release build type by default to get optimization flags ######################################################################## if(NOT CMAKE_BUILD_TYPE) diff --git a/cmake/Modules/GrPython.cmake b/cmake/Modules/GRASPython.cmake index e598df4..60af1c1 100644 --- a/cmake/Modules/GrPython.cmake +++ b/cmake/Modules/GRASPython.cmake @@ -17,10 +17,10 @@ # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. -if(DEFINED __INCLUDED_GR_PYTHON_CMAKE) +if(DEFINED __INCLUDED_GRAS_PYTHON_CMAKE) return() endif() -set(__INCLUDED_GR_PYTHON_CMAKE TRUE) +set(__INCLUDED_GRAS_PYTHON_CMAKE TRUE) ######################################################################## # Setup the python interpreter: diff --git a/cmake/Modules/GRASSwig.in.cmake b/cmake/Modules/GRASSwig.in.cmake new file mode 100644 index 0000000..8be4945 --- /dev/null +++ b/cmake/Modules/GRASSwig.in.cmake @@ -0,0 +1,91 @@ +if(DEFINED __INCLUDED_GRAS_SWIG_CMAKE) + return() +endif() +set(__INCLUDED_GRAS_SWIG_CMAKE TRUE) + +include(GRASTool) + +######################################################################## +## 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/GrTest.cmake b/cmake/Modules/GRASTest.cmake index bb045dc..474b6de 100644 --- a/cmake/Modules/GrTest.cmake +++ b/cmake/Modules/GRASTest.cmake @@ -17,36 +17,40 @@ # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. -if(DEFINED __INCLUDED_GR_TEST_CMAKE) +if(DEFINED __INCLUDED_GRAS_TEST_CMAKE) return() endif() -set(__INCLUDED_GR_TEST_CMAKE TRUE) +set(__INCLUDED_GRAS_TEST_CMAKE TRUE) + +#set GRAS_TEST_PYEXE as PYTHON_EXECUTABLE with the -B for convenience +include(GRASPython) +set(GRAS_TEST_PYEXE ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}) ######################################################################## # 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 +# GRAS_TEST_TARGET_DEPS - built targets for the library path +# GRAS_TEST_LIBRARY_DIRS - directories for the library path +# GRAS_TEST_PYTHON_DIRS - directories for the python path +# GRAS_TEST_ENVIRONS - other environment key/value pairs ######################################################################## -function(GR_ADD_TEST test_name) +function(GRAS_ADD_TEST test_name) #Ensure that the build exe also appears in the PATH. - list(APPEND GR_TEST_TARGET_DEPS ${ARGN}) + list(APPEND GRAS_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}) + foreach(target ${GRAS_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}) + list(APPEND GRAS_TEST_LIBRARY_DIRS ${path}) endif(location) endforeach(target) @@ -54,20 +58,18 @@ function(GR_ADD_TEST test_name) #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}) + foreach(pydir ${GRAS_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}) + list(APPEND GRAS_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}) + file(TO_NATIVE_PATH "${GRAS_TEST_LIBRARY_DIRS}" libpath) #ok to use on dir list? + file(TO_NATIVE_PATH "${GRAS_TEST_PYTHON_DIRS}" pypath) #ok to use on dir list? + file(TO_NATIVE_PATH "${GRAS_TOOL_MODULE_LOCATIONS}" modpath) #ok to use on dir list? + list(APPEND environs "${GRAS_TEST_ENVIRONS}") #http://www.cmake.org/pipermail/cmake/2009-May/029464.html #Replaced this add test + set environs code with the shell script generation. @@ -88,7 +90,8 @@ function(GR_ADD_TEST test_name) #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}") + string(REPLACE ";" ":" modpath "${modpath}") + list(APPEND environs "PATH=${binpath}" "${LD_PATH_VAR}=${libpath}" "PYTHONPATH=${pypath}" "GRAS_MODULE_PATH=${modpath}") #generate a bat file that sets the environment and runs the test find_program(SHELL sh) @@ -118,7 +121,8 @@ function(GR_ADD_TEST test_name) #replace list separator with the path separator (escaped) string(REPLACE ";" "\\;" libpath "${libpath}") string(REPLACE ";" "\\;" pypath "${pypath}") - list(APPEND environs "PATH=${libpath}" "PYTHONPATH=${pypath}") + string(REPLACE ";" "\\;" modpath "${modpath}") + list(APPEND environs "PATH=${libpath}" "PYTHONPATH=${pypath}" "GRAS_MODULE_PATH=${modpath}") #generate a bat file that sets the environment and runs the test set(bat_file ${CMAKE_CURRENT_BINARY_DIR}/${test_name}_test.bat) @@ -136,4 +140,4 @@ function(GR_ADD_TEST test_name) add_test(${test_name} ${bat_file}) endif(WIN32) -endfunction(GR_ADD_TEST) +endfunction(GRAS_ADD_TEST) diff --git a/cmake/Modules/GRASTool.in.cmake b/cmake/Modules/GRASTool.in.cmake index 502b271..9295839 100644 --- a/cmake/Modules/GRASTool.in.cmake +++ b/cmake/Modules/GRASTool.in.cmake @@ -5,16 +5,8 @@ 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() +#reset global variable on include +set(GRAS_TOOL_MODULE_LOCATIONS "" CACHE INTERNAL "") ######################################################################## ## Set installation constants @@ -149,11 +141,7 @@ function(GRAS_TOOL) #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 "") + set(GRAS_TOOL_MODULE_LOCATIONS "${GRAS_TOOL_MODULE_LOCATIONS};${module_location}" CACHE INTERNAL "") endif() #python module install @@ -175,88 +163,3 @@ function(GRAS_TOOL) 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) |