summaryrefslogtreecommitdiff
path: root/cmake/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/Modules')
-rw-r--r--cmake/Modules/CodeCoverage.cmake2
-rw-r--r--cmake/Modules/GnuradioConfig.cmake.in7
-rw-r--r--cmake/Modules/GrMiscUtils.cmake4
-rw-r--r--cmake/Modules/GrPybind.cmake280
-rw-r--r--cmake/Modules/GrSwig.cmake158
-rw-r--r--cmake/Modules/GrTest.cmake2
-rw-r--r--cmake/Modules/UseSWIG.cmake690
7 files changed, 284 insertions, 859 deletions
diff --git a/cmake/Modules/CodeCoverage.cmake b/cmake/Modules/CodeCoverage.cmake
index 285a185ec1..863e342527 100644
--- a/cmake/Modules/CodeCoverage.cmake
+++ b/cmake/Modules/CodeCoverage.cmake
@@ -124,7 +124,7 @@ FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${coverage_info}
- COMMAND ${LCOV_PATH} --remove ${coverage_info} 'tests/*' '/usr/*' 'swig/*' '*/swig/*' '*/qa_*' --output-file ${coverage_cleaned}
+ COMMAND ${LCOV_PATH} --remove ${coverage_info} 'tests/*' '/usr/*' '*/qa_*' --output-file ${coverage_cleaned}
COMMAND ${GENHTML_PATH} -o ${_outputname} ${coverage_cleaned}
# Don't remove fragments so CI can upload them to codecov
diff --git a/cmake/Modules/GnuradioConfig.cmake.in b/cmake/Modules/GnuradioConfig.cmake.in
index ccd5be0d2a..7cbe7d50f7 100644
--- a/cmake/Modules/GnuradioConfig.cmake.in
+++ b/cmake/Modules/GnuradioConfig.cmake.in
@@ -32,7 +32,7 @@ endif(ENABLE_TESTING)
find_dependency(Boost "@Boost_MAJOR_VERSION@.@Boost_MINOR_VERSION@.@Boost_SUBMINOR_VERSION@" COMPONENTS ${BOOST_REQUIRED_COMPONENTS})
find_dependency(Volk)
-set(ENABLE_PYTHON @ENABLE_PYTHON@ CACHE BOOL "Enable Python & SWIG")
+set(ENABLE_PYTHON @ENABLE_PYTHON@ CACHE BOOL "Enable Python & pybind11 Bindings")
if(${ENABLE_PYTHON})
set(PYTHON_EXECUTABLE @PYTHON_EXECUTABLE@)
set(GR_PYTHON_DIR @GR_PYTHON_DIR@)
@@ -44,11 +44,6 @@ include("${CMAKE_CURRENT_LIST_DIR}/gnuradio-runtimeConfig.cmake")
cmake_policy(SET CMP0012 NEW)
cmake_policy(SET CMP0057 NEW)
-#Can't use Python if GNU Radio was built without support for it
-if(${ENABLE_PYTHON})
- include("${CMAKE_CURRENT_LIST_DIR}/runtime_swigTargets.cmake")
-endif()
-
# Propagate the enabledness of GRC:
# Since GRC doesn't contain proper CMake targets (yet?), we need to do this
# manually
diff --git a/cmake/Modules/GrMiscUtils.cmake b/cmake/Modules/GrMiscUtils.cmake
index 7db3bfe2d1..da95a27586 100644
--- a/cmake/Modules/GrMiscUtils.cmake
+++ b/cmake/Modules/GrMiscUtils.cmake
@@ -145,8 +145,6 @@ function(GRCC)
list(APPEND PYTHONPATHS
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/gnuradio-runtime/python
- ${CMAKE_SOURCE_DIR}/gnuradio-runtime/lib/swig
- ${CMAKE_BINARY_DIR}/gnuradio-runtime/lib/swig
)
if(WIN32)
@@ -155,7 +153,7 @@ function(GRCC)
#Only do this for the python directories matching the following:
foreach(pydir ${PYTHONPATHS})
get_filename_component(name ${pydir} NAME)
- if(name MATCHES "^(swig|lib|src)$")
+ if(name MATCHES "^(lib|src)$")
list(APPEND PYTHONPATHS ${pydir}/${CMAKE_BUILD_TYPE})
endif()
endforeach(pydir)
diff --git a/cmake/Modules/GrPybind.cmake b/cmake/Modules/GrPybind.cmake
new file mode 100644
index 0000000000..fd5c9a2511
--- /dev/null
+++ b/cmake/Modules/GrPybind.cmake
@@ -0,0 +1,280 @@
+include(GrPython)
+
+macro(GR_PYBIND_MAKE name updir filter files)
+
+configure_file(${CMAKE_SOURCE_DIR}/docs/doxygen/pydoc_macros.h ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
+
+pybind11_add_module(${name}_python ${files})
+
+SET(MODULE_NAME ${name})
+if (${name} STREQUAL gr)
+ SET(MODULE_NAME "runtime")
+endif()
+
+if(ENABLE_DOXYGEN)
+ add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/docstring_status
+ COMMAND python3 ${CMAKE_SOURCE_DIR}/docs/doxygen/update_pydoc.py "sub"
+ "--json_path" ${CMAKE_BINARY_DIR}/docs/doxygen/gnuradio_docstrings.json
+ "--bindings_dir" ${CMAKE_CURRENT_SOURCE_DIR}/docstrings
+ "--output_dir" ${CMAKE_CURRENT_BINARY_DIR}
+ "--filter" ${filter}
+ COMMENT "Adding docstrings into ${name} pybind headers ..."
+ DEPENDS gnuradio_docstrings)
+ add_custom_target(${name}_docstrings ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/docstring_status)
+else(ENABLE_DOXYGEN)
+ add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/docstring_status
+ COMMAND python3 ${CMAKE_SOURCE_DIR}/docs/doxygen/update_pydoc.py "copy"
+ "--bindings_dir" ${CMAKE_CURRENT_SOURCE_DIR}/docstrings
+ "--output_dir" ${CMAKE_CURRENT_BINARY_DIR}
+ COMMENT "Copying ${name} docstring templates as pybind headers ...")
+ add_custom_target(${name}_docstrings ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/docstring_status)
+endif(ENABLE_DOXYGEN)
+
+target_include_directories(${name}_python PUBLIC
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${PYTHON_NUMPY_INCLUDE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/${updir}/lib
+ ${CMAKE_CURRENT_SOURCE_DIR}/${updir}/include
+ ${PYBIND11_INCLUDE_DIR}
+)
+target_link_libraries(${name}_python PUBLIC ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} gnuradio-${MODULE_NAME})
+target_compile_options(${name}_python PRIVATE -Wno-unused-variable) # disable warnings for docstring templates
+add_dependencies(${name}_python ${name}_docstrings)
+
+endmacro(GR_PYBIND_MAKE)
+
+
+macro(GR_PYBIND_MAKE_CHECK_HASH name updir filter files)
+
+configure_file(${CMAKE_SOURCE_DIR}/docs/doxygen/pydoc_macros.h ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
+
+list(APPEND regen_targets "")
+foreach(file ${files})
+
+ execute_process(COMMAND "python3"
+ ${CMAKE_SOURCE_DIR}/gr-utils/bindtool/scripts/header_utils.py
+ "all"
+ ${CMAKE_CURRENT_SOURCE_DIR}/${file}
+ OUTPUT_VARIABLE flags_all
+ )
+ list(GET flags_all 0 flag_auto)
+ list(GET flags_all 1 flag_pygccxml)
+ list(GET flags_all 2 header_filename)
+ list(GET flags_all 3 header_file_hash
+ )
+ # message(STATUS ${file} ":" ${flag_auto} ":" ${flag_pygccxml} ":" ${header_filename} ":" ${header_file_hash})
+
+ if (NOT ${header_filename} STREQUAL "None") # If no header filename is specified, don't bother checking for a rebuild
+ if (${name} STREQUAL gr)
+ set(header_full_path ${CMAKE_CURRENT_SOURCE_DIR}/${updir}/include/gnuradio/${header_filename})
+ else()
+ set(header_full_path ${CMAKE_CURRENT_SOURCE_DIR}/${updir}/include/gnuradio/${name}/${header_filename})
+ endif()
+
+ file(MD5 ${header_full_path} calc_hash)
+ # message(STATUS ${ii} " " ${calc_hash} " " ${saved_hash})
+ if (NOT ${calc_hash} STREQUAL ${header_file_hash})
+ # check the file and see if bindings should be automatically regenerated
+ if (flag_auto STREQUAL "False") # the regex match was not found, manual bindings
+ # if (NOT bindtool_use_pygccxml STREQUAL )
+ message(FATAL_ERROR "Python bindings for " ${header_filename} " are out of sync" )
+ else()
+ if (flag_pygccxml STREQUAL "True")
+ if(NOT PYGCCXML_FOUND)
+ message(FATAL_ERROR "Python bindings for " ${header_filename} " require pygccxml for automatic regeneration" )
+ endif()
+ endif()
+
+ message(STATUS "Regenerating Bindings in-place for " ${header_filename})
+
+ file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${file}.regen_status)
+ # Automatically regenerate the bindings
+ add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}}/${file}
+ COMMAND "python3"
+ ${CMAKE_SOURCE_DIR}/gr-utils/bindtool/scripts/bind_intree_file.py
+ "--output_dir" ${CMAKE_CURRENT_SOURCE_DIR}/..
+ "--prefix" ${CMAKE_INSTALL_PREFIX}
+ "--src" ${CMAKE_SOURCE_DIR}
+ "--module" ${name}
+ "--filename" ${header_full_path}
+ "--status" ${CMAKE_CURRENT_BINARY_DIR}/${file}.regen_status
+ "--flag_automatic" ${flag_auto}
+ "--flag_pygccxml" ${flag_pygccxml}
+ # "--include" "$<INSTALL_INTERFACE:include>" #FIXME: Make the pygccxml generation use the source tree headers
+ COMMENT "Automatic generation of pybind11 bindings for " ${header_full_path})
+ add_custom_target(${file}_regen_bindings ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}}/${file})
+ list(APPEND regen_targets ${file}_regen_bindings)
+ endif()
+
+ endif()
+ endif()
+endforeach()
+
+pybind11_add_module(${name}_python ${files})
+
+SET(MODULE_NAME ${name})
+if (${name} STREQUAL gr)
+ SET(MODULE_NAME "runtime")
+endif()
+if (${name} STREQUAL video_sdl)
+ SET(MODULE_NAME "video-sdl")
+endif()
+
+
+if(ENABLE_DOXYGEN)
+ add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/docstring_status
+ COMMAND python3 ${CMAKE_SOURCE_DIR}/docs/doxygen/update_pydoc.py "sub"
+ "--json_path" ${CMAKE_BINARY_DIR}/docs/doxygen/gnuradio_docstrings.json
+ "--bindings_dir" ${CMAKE_CURRENT_SOURCE_DIR}/docstrings
+ "--output_dir" ${CMAKE_CURRENT_BINARY_DIR}
+ "--filter" ${filter}
+ COMMENT "Adding docstrings into ${name} pybind headers ..."
+ DEPENDS gnuradio_docstrings)
+ add_custom_target(${name}_docstrings ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/docstring_status)
+else(ENABLE_DOXYGEN)
+ add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/docstring_status
+ COMMAND python3 ${CMAKE_SOURCE_DIR}/docs/doxygen/update_pydoc.py "copy"
+ "--bindings_dir" ${CMAKE_CURRENT_SOURCE_DIR}/docstrings
+ "--output_dir" ${CMAKE_CURRENT_BINARY_DIR}
+ COMMENT "Copying ${name} docstring templates as pybind headers ...")
+ add_custom_target(${name}_docstrings ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/docstring_status)
+endif(ENABLE_DOXYGEN)
+
+target_include_directories(${name}_python PUBLIC
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${PYTHON_NUMPY_INCLUDE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/${updir}/lib
+ ${CMAKE_CURRENT_SOURCE_DIR}/${updir}/include
+ ${PYBIND11_INCLUDE_DIR}
+)
+target_link_libraries(${name}_python PUBLIC ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} gnuradio-${MODULE_NAME})
+target_compile_options(${name}_python PRIVATE -Wno-unused-variable) # disable warnings for docstring templates
+add_dependencies(${name}_python ${name}_docstrings ${regen_targets})
+
+endmacro(GR_PYBIND_MAKE_CHECK_HASH)
+
+
+
+macro(GR_PYBIND_MAKE_OOT name updir filter files)
+
+list(APPEND regen_targets "")
+foreach(file ${files})
+
+ execute_process(COMMAND "python3"
+ ${CMAKE_CURRENT_SOURCE_DIR}/header_utils.py
+ "all"
+ ${CMAKE_CURRENT_SOURCE_DIR}/${file}
+ OUTPUT_VARIABLE flags_all
+ )
+ list(GET flags_all 0 flag_auto)
+ list(GET flags_all 1 flag_pygccxml)
+ list(GET flags_all 2 header_filename)
+ list(GET flags_all 3 header_file_hash
+ )
+
+ # message(STATUS ${file} ":" ${flag_auto} ":" ${flag_pygccxml} ":" ${header_filename} ":" ${header_file_hash})
+
+ if (NOT ${header_filename} STREQUAL "None") # If no header filename is specified, don't bother checking for a rebuild
+ set(header_full_path ${CMAKE_CURRENT_SOURCE_DIR}/${updir}/include/${name}/${header_filename}) # NOTE OOT version does not have gnuradio/ here
+ file(MD5 ${header_full_path} calc_hash)
+ # message(STATUS ${ii} " " ${calc_hash} " " ${saved_hash})
+ if (NOT ${calc_hash} STREQUAL ${header_file_hash})
+ # check the file and see if bindings should be automatically regenerated
+ if (flag_auto STREQUAL "False") # the regex match was not found, manual bindings
+ # if (NOT bindtool_use_pygccxml STREQUAL )
+ message(FATAL_ERROR "Python bindings for " ${header_filename} " are out of sync" )
+ else()
+ if (flag_pygccxml STREQUAL "True")
+ if(NOT PYGCCXML_FOUND)
+ message(FATAL_ERROR "Python bindings for " ${header_filename} " require pygccxml for automatic regeneration" )
+ endif()
+ endif()
+
+ message(STATUS "Regenerating Bindings in-place for " ${header_filename})
+
+ file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${file}.regen_status)
+ # Automatically regenerate the bindings
+ add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}}/${file}
+ COMMAND "python3"
+ ${CMAKE_CURRENT_SOURCE_DIR}/bind_oot_file.py
+ "--output_dir" ${CMAKE_CURRENT_SOURCE_DIR}/..
+ "--prefix" ${CMAKE_INSTALL_PREFIX}
+ "--src" ${CMAKE_SOURCE_DIR}
+ "--module" ${name}
+ "--filename" ${header_full_path}
+ "--status" ${CMAKE_CURRENT_BINARY_DIR}/${file}.regen_status
+ "--flag_automatic" ${flag_auto}
+ "--flag_pygccxml" ${flag_pygccxml}
+ # "--include" "$<INSTALL_INTERFACE:include>" #FIXME: Make the pygccxml generation use the source tree headers
+ COMMENT "Automatic generation of pybind11 bindings for " ${header_full_path})
+ add_custom_target(${file}_regen_bindings ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}}/${file})
+ list(APPEND regen_targets ${file}_regen_bindings)
+ endif()
+
+ endif()
+ endif()
+endforeach()
+
+
+configure_file(${CMAKE_SOURCE_DIR}/docs/doxygen/pydoc_macros.h ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
+
+pybind11_add_module(${name}_python ${files})
+
+SET(MODULE_NAME ${name})
+if (${name} STREQUAL gr)
+ SET(MODULE_NAME "runtime")
+endif()
+
+if(ENABLE_DOXYGEN)
+
+ add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/extracted_docstrings.json
+ COMMAND python3 ${CMAKE_SOURCE_DIR}/docs/doxygen/update_pydoc.py "scrape"
+ "--xml_path" ${CMAKE_BINARY_DIR}/docs/doxygen/xml
+ "--json_path" ${CMAKE_CURRENT_BINARY_DIR}/extracted_docstrings.json
+ COMMENT "Scraping generated documentation for docstrings ..."
+ DEPENDS gnuradio-${MODULE_NAME} doxygen_target)
+
+ add_custom_target(
+ extracted_docstrings ALL
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/extracted_docstrings.json
+ )
+
+ add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/docstring_status
+ COMMAND python3 ${CMAKE_SOURCE_DIR}/docs/doxygen/update_pydoc.py "sub"
+ "--json_path" ${CMAKE_CURRENT_BINARY_DIR}/extracted_docstrings.json
+ "--bindings_dir" ${CMAKE_CURRENT_SOURCE_DIR}/docstrings
+ "--output_dir" ${CMAKE_CURRENT_BINARY_DIR}
+ "--filter" ${filter}
+ COMMENT "Adding docstrings into ${name} pybind headers ..."
+ DEPENDS extracted_docstrings)
+ add_custom_target(${name}_docstrings ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/docstring_status)
+else(ENABLE_DOXYGEN)
+ add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/docstring_status
+ COMMAND python3 ${CMAKE_SOURCE_DIR}/docs/doxygen/update_pydoc.py "copy"
+ "--bindings_dir" ${CMAKE_CURRENT_SOURCE_DIR}/docstrings
+ "--output_dir" ${CMAKE_CURRENT_BINARY_DIR}
+ COMMENT "Copying ${name} docstring templates as pybind headers ...")
+ add_custom_target(${name}_docstrings ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/docstring_status)
+endif(ENABLE_DOXYGEN)
+
+target_include_directories(${name}_python PUBLIC
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${PYTHON_NUMPY_INCLUDE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/${updir}/lib
+ ${CMAKE_CURRENT_SOURCE_DIR}/${updir}/include
+ ${PYBIND11_INCLUDE_DIR}
+)
+target_link_libraries(${name}_python PUBLIC ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} gnuradio-${MODULE_NAME})
+target_compile_options(${name}_python PRIVATE -Wno-unused-variable) # disable warnings for docstring templates
+add_dependencies(${name}_python ${name}_docstrings ${regen_targets})
+
+endmacro(GR_PYBIND_MAKE_OOT) \ No newline at end of file
diff --git a/cmake/Modules/GrSwig.cmake b/cmake/Modules/GrSwig.cmake
deleted file mode 100644
index 950884fa27..0000000000
--- a/cmake/Modules/GrSwig.cmake
+++ /dev/null
@@ -1,158 +0,0 @@
-# Copyright 2010-2011,2019 Free Software Foundation, Inc.
-#
-# This file is part of GNU Radio
-#
-# SPDX-License-Identifier: GPL-3.0-or-later
-#
-
-if(DEFINED __INCLUDED_GR_SWIG_CMAKE)
- return()
-endif()
-set(__INCLUDED_GR_SWIG_CMAKE TRUE)
-
-include(GrPython)
-
-########################################################################
-# Builds a swig documentation file to be generated into python docstrings
-# Usage: GR_SWIG_MAKE_DOCS(output_file input_path input_path....)
-#
-# Set the following variable to specify extra dependent targets:
-# - GR_SWIG_DOCS_SOURCE_DEPS
-# - GR_SWIG_DOCS_TARGET_DEPS
-########################################################################
-function(GR_SWIG_MAKE_DOCS output_file)
- if(ENABLE_DOXYGEN)
-
- #setup the input files variable list, quote formatted
- set(input_files)
- unset(INPUT_PATHS)
- foreach(input_path ${ARGN})
- if(IS_DIRECTORY ${input_path}) #when input path is a directory
- file(GLOB input_path_h_files ${input_path}/*.h)
- else() #otherwise its just a file, no glob
- set(input_path_h_files ${input_path})
- endif()
- list(APPEND input_files ${input_path_h_files})
- set(INPUT_PATHS "${INPUT_PATHS} \"${input_path}\"")
- endforeach(input_path)
-
- #determine the output directory
- get_filename_component(name ${output_file} NAME_WE)
- get_filename_component(OUTPUT_DIRECTORY ${output_file} PATH)
- set(OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY}/${name}_swig_docs)
- make_directory(${OUTPUT_DIRECTORY})
-
- #generate the Doxyfile used by doxygen
- configure_file(
- ${CMAKE_SOURCE_DIR}/docs/doxygen/Doxyfile.swig_doc.in
- ${OUTPUT_DIRECTORY}/Doxyfile
- @ONLY)
-
- #Create a dummy custom command that depends on other targets
- include(GrMiscUtils)
- GR_GEN_TARGET_DEPS(_${name}_tag tag_deps ${GR_SWIG_DOCS_TARGET_DEPS})
-
- #call doxygen on the Doxyfile + input headers
- add_custom_command(
- OUTPUT ${OUTPUT_DIRECTORY}/xml/index.xml
- DEPENDS ${input_files} ${GR_SWIG_DOCS_SOURCE_DEPS} ${tag_deps}
- COMMAND ${DOXYGEN_EXECUTABLE} ${OUTPUT_DIRECTORY}/Doxyfile
- COMMENT "Generating doxygen xml for ${name} docs"
- )
-
- #call the swig_doc script on the xml files
- add_custom_command(
- OUTPUT ${output_file}
- DEPENDS ${input_files} ${stamp-file} ${OUTPUT_DIRECTORY}/xml/index.xml
- COMMAND ${PYTHON_EXECUTABLE} -B
- ${CMAKE_SOURCE_DIR}/docs/doxygen/swig_doc.py
- ${OUTPUT_DIRECTORY}/xml
- ${output_file}
- COMMENT "Generating python docstrings for ${name}"
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/docs/doxygen
- )
-
- else(ENABLE_DOXYGEN)
- file(WRITE ${output_file} "\n") #no doxygen -> empty file
- endif(ENABLE_DOXYGEN)
-endfunction(GR_SWIG_MAKE_DOCS)
-
-########################################################################
-# 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
-# - GR_SWIG_DOC_FILE
-# - GR_SWIG_DOC_DIRS
-########################################################################
-macro(GR_SWIG_MAKE name)
- set(ifiles ${ARGN})
-
- #do swig doc generation if specified
- if(GR_SWIG_DOC_FILE)
- set(GR_SWIG_DOCS_SOURCE_DEPS ${GR_SWIG_SOURCE_DEPS})
- list(APPEND GR_SWIG_DOCS_TARGET_DEPS ${GR_SWIG_TARGET_DEPS})
- GR_SWIG_MAKE_DOCS(${GR_SWIG_DOC_FILE} ${GR_SWIG_DOC_DIRS})
- add_custom_target(${name}_swig_doc DEPENDS ${GR_SWIG_DOC_FILE})
- list(APPEND GR_SWIG_TARGET_DEPS ${name}_swig_doc)
- endif()
-
- #prepend local swig directories
- list(INSERT GR_SWIG_INCLUDE_DIRS 0 "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")
- list(INSERT GR_SWIG_INCLUDE_DIRS 0 "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")
-
- #setup the swig flags with flags and include directories
- set(modern_keyword "-modern")
- if("${SWIG_VERSION}" VERSION_GREATER "3.0.12")
- set(modern_keyword "")
- endif()
- set(CMAKE_SWIG_FLAGS -fvirtual ${modern_keyword} -keyword -w511 -w314 -relativeimport -py3 -module ${name} ${GR_SWIG_FLAGS})
-
- #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_library(${name} LANGUAGE python SOURCES ${ifiles})
- if(${name} STREQUAL "runtime_swig")
- set_target_properties(runtime_swig PROPERTIES DEFINE_SYMBOL "gnuradio_runtime_EXPORTS")
- endif(${name} STREQUAL "runtime_swig")
- set_target_properties(${name} PROPERTIES
- SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE
- )
- target_include_directories(${name} PUBLIC ${GR_SWIG_INCLUDE_DIRS})
- set_property(TARGET ${name} PROPERTY SWIG_DEPENDS ${GR_SWIG_TARGET_DEPS})
- target_link_libraries(${name} Python::Python ${GR_SWIG_LIBRARIES})
-endmacro(GR_SWIG_MAKE)
-
-########################################################################
-# Install swig targets generated by GR_SWIG_MAKE. Usage:
-# GR_SWIG_INSTALL(
-# TARGETS target target target...
-# [DESTINATION destination]
-# )
-########################################################################
-macro(GR_SWIG_INSTALL)
-
- include(CMakeParseArgumentsCopy)
- CMAKE_PARSE_ARGUMENTS(GR_SWIG_INSTALL "" "DESTINATION" "TARGETS" ${ARGN})
-
- foreach(name ${GR_SWIG_INSTALL_TARGETS})
- install(TARGETS ${name}
- DESTINATION ${GR_SWIG_INSTALL_DESTINATION}
- )
-
- include(GrPython)
- GR_PYTHON_INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${name}.py
- DESTINATION ${GR_SWIG_INSTALL_DESTINATION}
- DEPENDS ${name}
- )
-
- endforeach(name)
-
-endmacro(GR_SWIG_INSTALL)
diff --git a/cmake/Modules/GrTest.cmake b/cmake/Modules/GrTest.cmake
index d404a71078..7c8522a2a4 100644
--- a/cmake/Modules/GrTest.cmake
+++ b/cmake/Modules/GrTest.cmake
@@ -48,7 +48,7 @@ function(GR_ADD_TEST test_name)
#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)$")
+ if(name MATCHES "^(lib|src)$")
list(APPEND GR_TEST_PYTHON_DIRS ${pydir}/${CMAKE_BUILD_TYPE})
endif()
endforeach(pydir)
diff --git a/cmake/Modules/UseSWIG.cmake b/cmake/Modules/UseSWIG.cmake
deleted file mode 100644
index 015d9804bf..0000000000
--- a/cmake/Modules/UseSWIG.cmake
+++ /dev/null
@@ -1,690 +0,0 @@
-# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
-# file Copyright.txt or https://cmake.org/licensing for details.
-
-#[=======================================================================[.rst:
-UseSWIG
--------
-
-This file provides support for ``SWIG``. It is assumed that :module:`FindSWIG`
-module has already been loaded.
-
-Defines the following command for use with ``SWIG``:
-
-.. command:: swig_add_library
-
- Define swig module with given name and specified language::
-
- swig_add_library(<name>
- [TYPE <SHARED|MODULE|STATIC|USE_BUILD_SHARED_LIBS>]
- LANGUAGE <language>
- [NO_PROXY]
- [OUTPUT_DIR <directory>]
- [OUTFILE_DIR <directory>]
- SOURCES <file>...
- )
-
- Targets created with the ``swig_add_library`` command have the same
- capabilities as targets created with the :command:`add_library` command, so
- those targets can be used with any command expecting a target (e.g.
- :command:`target_link_libraries`).
-
- .. note::
-
- For multi-config generators, this module does not support
- configuration-specific files generated by ``SWIG``. All build
- configurations must result in the same generated source file.
-
- ``TYPE``
- ``SHARED``, ``MODULE`` and ``STATIC`` have the same semantic as for the
- :command:`add_library` command. If ``USE_BUILD_SHARED_LIBS`` is specified,
- the library type will be ``STATIC`` or ``SHARED`` based on whether the
- current value of the :variable:`BUILD_SHARED_LIBS` variable is ``ON``. If
- no type is specified, ``MODULE`` will be used.
-
- ``LANGUAGE``
- Specify the target language.
-
- ``NO_PROXY``
- Prevent the generation of the wrapper layer (swig ``-noproxy`` option).
-
- ``OUTPUT_DIR``
- Specify where to write the language specific files (swig ``-outdir``
- option). If not given, the ``CMAKE_SWIG_OUTDIR`` variable will be used.
- If neither is specified, the default depends on the value of the
- ``UseSWIG_MODULE_VERSION`` variable as follows:
-
- * If ``UseSWIG_MODULE_VERSION`` is 1 or is undefined, output is written to
- the :variable:`CMAKE_CURRENT_BINARY_DIR` directory.
- * If ``UseSWIG_MODULE_VERSION`` is 2, a dedicated directory will be used.
- The path of this directory can be retrieved from the
- ``SWIG_SUPPORT_FILES_DIRECTORY`` target property.
-
- ``OUTFILE_DIR``
- Specify an output directory name where the generated source file will be
- placed (swig -o option). If not specified, the ``SWIG_OUTFILE_DIR`` variable
- will be used. If neither is specified, ``OUTPUT_DIR`` or
- ``CMAKE_SWIG_OUTDIR`` is used instead.
-
- ``SOURCES``
- List of sources for the library. Files with extension ``.i`` will be
- identified as sources for the ``SWIG`` tool. Other files will be handled in
- the standard way.
-
-.. note::
-
- If ``UseSWIG_MODULE_VERSION`` is set to 2, it is **strongly** recommended
- to use a dedicated directory unique to the target when either the
- ``OUTPUT_DIR`` option or the ``CMAKE_SWIG_OUTDIR`` variable are specified.
- The output directory contents are erased as part of the target build, so
- to prevent interference between targets or losing other important files, each
- target should have its own dedicated output directory.
-
-Source file properties on module files **must** be set before the invocation
-of the ``swig_add_library`` command to specify special behavior of SWIG and
-ensure generated files will receive the required settings.
-
-``CPLUSPLUS``
- Call SWIG in c++ mode. For example:
-
- .. code-block:: cmake
-
- set_property(SOURCE mymod.i PROPERTY CPLUSPLUS ON)
- swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
-
-``INCLUDE_DIRECTORIES``, ``COMPILE_DEFINITIONS`` and ``COMPILE_OPTIONS``
- Add custom flags to SWIG compiler and have same semantic as properties
- :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and
- :prop_sf:`COMPILE_OPTIONS`.
-
-``GENERATED_INCLUDE_DIRECTORIES``, ``GENERATED_COMPILE_DEFINITIONS`` and ``GENERATED_COMPILE_OPTIONS``
- Add custom flags to the C/C++ generated source. They will fill, respectively,
- properties :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and
- :prop_sf:`COMPILE_OPTIONS` of generated C/C++ file.
-
-``DEPENDS``
- Specify additional dependencies to the source file.
-
-``SWIG_MODULE_NAME``
- Specify the actual import name of the module in the target language.
- This is required if it cannot be scanned automatically from source
- or different from the module file basename. For example:
-
- .. code-block:: cmake
-
- set_property(SOURCE mymod.i PROPERTY SWIG_MODULE_NAME mymod_realname)
-
-Target library properties can be set to apply same configuration to all SWIG
-input files.
-
-``SWIG_INCLUDE_DIRECTORIES``, ``SWIG_COMPILE_DEFINITIONS`` and ``SWIG_COMPILE_OPTIONS``
- These properties will be applied to all SWIG input files and have same
- semantic as target properties :prop_tgt:`INCLUDE_DIRECTORIES`,
- :prop_tgt:`COMPILE_DEFINITIONS` and :prop_tgt:`COMPILE_OPTIONS`.
-
- .. code-block:: cmake
-
- swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
- set_property(TARGET mymod PROPERTY SWIG_COMPILE_DEFINITIONS MY_DEF1 MY_DEF2)
- set_property(TARGET mymod PROPERTY SWIG_COMPILE_OPTIONS -bla -blb)
-
-``SWIG_GENERATED_INCLUDE_DIRECTORIES``, ``SWIG_GENERATED_COMPILE_DEFINITIONS`` and ``SWIG_GENERATED_COMPILE_OPTIONS``
- These properties will populate, respectively, properties
- :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and
- :prop_sf:`COMPILE_FLAGS` of all generated C/C++ files.
-
-``SWIG_DEPENDS``
- Add dependencies to all SWIG input files.
-
-The following target properties are output properties and can be used to get
-information about support files generated by ``SWIG`` interface compilation.
-
-``SWIG_SUPPORT_FILES``
- This output property list of wrapper files generated during SWIG compilation.
-
- .. code-block:: cmake
-
- swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
- get_property(support_files TARGET mymod PROPERTY SWIG_SUPPORT_FILES)
-
- .. note::
-
- Only most principal support files are listed. In case some advanced
- features of ``SWIG`` are used (for example ``%template``), associated
- support files may not be listed. Prefer to use the
- ``SWIG_SUPPORT_FILES_DIRECTORY`` property to handle support files.
-
-``SWIG_SUPPORT_FILES_DIRECTORY``
- This output property specifies the directory where support files will be
- generated.
-
-Some variables can be set to customize the behavior of ``swig_add_library``
-as well as ``SWIG``:
-
-``UseSWIG_MODULE_VERSION``
- Specify different behaviors for ``UseSWIG`` module.
-
- * Set to 1 or undefined: Legacy behavior is applied.
- * Set to 2: A new strategy is applied regarding support files: the output
- directory of support files is erased before ``SWIG`` interface compilation.
-
-``CMAKE_SWIG_FLAGS``
- Add flags to all swig calls.
-
-``CMAKE_SWIG_OUTDIR``
- Specify where to write the language specific files (swig ``-outdir`` option).
-
-``SWIG_OUTFILE_DIR``
- Specify an output directory name where the generated source file will be
- placed. If not specified, ``CMAKE_SWIG_OUTDIR`` is used.
-
-``SWIG_MODULE_<name>_EXTRA_DEPS``
- Specify extra dependencies for the generated module for ``<name>``.
-#]=======================================================================]
-
-
-cmake_policy (VERSION 3.8)
-
-set(SWIG_CXX_EXTENSION "cxx")
-set(SWIG_EXTRA_LIBRARIES "")
-
-set(SWIG_PYTHON_EXTRA_FILE_EXTENSIONS ".py")
-set(SWIG_JAVA_EXTRA_FILE_EXTENSIONS ".java" "JNI.java")
-
-##
-## PRIVATE functions
-##
-function (__SWIG_COMPUTE_TIMESTAMP name language infile workingdir __timestamp)
- get_filename_component(filename "${infile}" NAME_WE)
- set(${__timestamp}
- "${workingdir}/${filename}${language}.stamp" PARENT_SCOPE)
- # get_filename_component(filename "${infile}" ABSOLUTE)
- # string(UUID uuid NAMESPACE 9735D882-D2F8-4E1D-88C9-A0A4F1F6ECA4
- # NAME ${name}-${language}-${filename} TYPE SHA1)
- # set(${__timestamp} "${workingdir}/${uuid}.stamp" PARENT_SCOPE)
-endfunction()
-
-#
-# For given swig module initialize variables associated with it
-#
-macro(SWIG_MODULE_INITIALIZE name language)
- string(TOUPPER "${language}" SWIG_MODULE_${name}_LANGUAGE)
- string(TOLOWER "${language}" SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG)
-
- set(SWIG_MODULE_${name}_EXTRA_FLAGS)
- if (NOT DEFINED SWIG_MODULE_${name}_NOPROXY)
- set (SWIG_MODULE_${name}_NOPROXY FALSE)
- endif()
- if ("-noproxy" IN_LIST CMAKE_SWIG_FLAGS)
- set (SWIG_MODULE_${name}_NOPROXY TRUE)
- endif ()
-
- if (SWIG_MODULE_${name}_NOPROXY AND NOT "-noproxy" IN_LIST CMAKE_SWIG_FLAGS)
- list (APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-noproxy")
- endif()
- if(SWIG_MODULE_${name}_LANGUAGE STREQUAL "UNKNOWN")
- message(FATAL_ERROR "SWIG Error: Language \"${language}\" not found")
- elseif(SWIG_MODULE_${name}_LANGUAGE STREQUAL "PERL")
- list(APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-shadow")
- endif()
-endmacro()
-
-#
-# For a given language, input file, and output file, determine extra files that
-# will be generated. This is internal swig macro.
-#
-
-function(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile)
- set(files)
- get_source_file_property(module_basename
- "${infile}" SWIG_MODULE_NAME)
- if(NOT swig_module_basename)
-
- # try to get module name from "%module foo" syntax
- if ( EXISTS "${infile}" )
- file ( STRINGS "${infile}" module_basename REGEX "[ ]*%module[ ]*[a-zA-Z0-9_]+.*" )
- endif ()
- if ( module_basename )
- string ( REGEX REPLACE "[ ]*%module[ ]*([a-zA-Z0-9_]+).*" "\\1" module_basename "${module_basename}" )
-
- else ()
- # try to get module name from "%module (options=...) foo" syntax
- if ( EXISTS "${infile}" )
- file ( STRINGS "${infile}" module_basename REGEX "[ ]*%module[ ]*\\(.*\\)[ ]*[a-zA-Z0-9_]+.*" )
- endif ()
- if ( module_basename )
- string ( REGEX REPLACE "[ ]*%module[ ]*\\(.*\\)[ ]*([a-zA-Z0-9_]+).*" "\\1" module_basename "${module_basename}" )
-
- else ()
- # fallback to file basename
- get_filename_component(module_basename "${infile}" NAME_WE)
- endif ()
- endif ()
-
- endif()
- foreach(it ${SWIG_${language}_EXTRA_FILE_EXTENSIONS})
- set(extra_file "${generatedpath}/${module_basename}${it}")
- list(APPEND files "${extra_file}")
- endforeach()
- # Treat extra outputs as plain files regardless of language.
- set_source_files_properties(${files} PROPERTIES LANGUAGE "")
-
- set (${outfiles} ${files} PARENT_SCOPE)
-endfunction()
-
-#
-# Take swig (*.i) file and add proper custom commands for it
-#
-function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
- get_filename_component(swig_source_file_name_we "${infile}" NAME_WE)
- get_source_file_property(swig_source_file_cplusplus "${infile}" CPLUSPLUS)
-
- # If CMAKE_SWIG_OUTDIR was specified then pass it to -outdir
- if(CMAKE_SWIG_OUTDIR)
- set(outdir ${CMAKE_SWIG_OUTDIR})
- else()
- set(outdir ${CMAKE_CURRENT_BINARY_DIR})
- endif()
-
- if(SWIG_OUTFILE_DIR)
- set(outfiledir ${SWIG_OUTFILE_DIR})
- else()
- set(outfiledir ${outdir})
- endif()
-
- if(SWIG_WORKING_DIR)
- set (workingdir "${SWIG_WORKING_DIR}")
- else()
- set(workingdir "${outdir}")
- endif()
-
- set (swig_source_file_flags ${CMAKE_SWIG_FLAGS})
- # handle various swig compile flags properties
- get_source_file_property (include_directories "${infile}" INCLUDE_DIRECTORIES)
- if (include_directories)
- list (APPEND swig_source_file_flags "$<$<BOOL:${include_directories}>:-I$<JOIN:${include_directories},$<SEMICOLON>-I>>")
- endif()
- set (property "$<TARGET_PROPERTY:${name},SWIG_INCLUDE_DIRECTORIES>")
- list (APPEND swig_source_file_flags "$<$<BOOL:${property}>:-I$<JOIN:${property},$<SEMICOLON>-I>>")
-
- set (property "$<TARGET_PROPERTY:${name},INCLUDE_DIRECTORIES>")
- list (APPEND swig_source_file_flags "$<$<BOOL:${property}>:-I$<JOIN:${property},$<SEMICOLON>-I>>")
-
- set (property "$<TARGET_PROPERTY:${name},INCLUDE_DIRECTORIES>")
- get_source_file_property(use_target_include_dirs "${infile}" USE_TARGET_INCLUDE_DIRECTORIES)
- if (use_target_include_dirs)
- list (APPEND swig_source_file_flags "$<$<BOOL:${property}>:-I$<JOIN:${property},$<SEMICOLON>-I>>")
- elseif(use_target_include_dirs STREQUAL "NOTFOUND")
- # not defined at source level, rely on target level
- list (APPEND swig_source_file_flags "$<$<AND:$<BOOL:$<TARGET_PROPERTY:${name},SWIG_USE_TARGET_INCLUDE_DIRECTORIES>>,$<BOOL:${property}>>:-I$<JOIN:${property},$<SEMICOLON>-I>>")
- endif()
-
- set (property "$<TARGET_PROPERTY:${name},SWIG_COMPILE_DEFINITIONS>")
- list (APPEND swig_source_file_flags "$<$<BOOL:${property}>:-D$<JOIN:${property},$<SEMICOLON>-D>>")
- get_source_file_property (compile_definitions "${infile}" COMPILE_DEFINITIONS)
- if (compile_definitions)
- list (APPEND swig_source_file_flags "$<$<BOOL:${compile_definitions}>:-D$<JOIN:${compile_definitions},$<SEMICOLON>-D>>")
- endif()
-
- list (APPEND swig_source_file_flags "$<TARGET_PROPERTY:${name},SWIG_COMPILE_OPTIONS>")
- get_source_file_property (compile_options "${infile}" COMPILE_OPTIONS)
- if (compile_options)
- list (APPEND swig_source_file_flags ${compile_options})
- endif()
-
- # legacy support
- get_source_file_property (swig_flags "${infile}" SWIG_FLAGS)
- if (swig_flags)
- list (APPEND swig_source_file_flags ${swig_flags})
- endif()
-
- get_filename_component(swig_source_file_fullname "${infile}" ABSOLUTE)
-
- if (NOT SWIG_MODULE_${name}_NOPROXY)
- SWIG_GET_EXTRA_OUTPUT_FILES(${SWIG_MODULE_${name}_LANGUAGE}
- swig_extra_generated_files
- "${outdir}"
- "${swig_source_file_fullname}")
- endif()
- set(swig_generated_file_fullname
- "${outfiledir}/${swig_source_file_name_we}")
- # add the language into the name of the file (i.e. TCL_wrap)
- # this allows for the same .i file to be wrapped into different languages
- string(APPEND swig_generated_file_fullname
- "${SWIG_MODULE_${name}_LANGUAGE}_wrap")
-
- if(swig_source_file_cplusplus)
- string(APPEND swig_generated_file_fullname
- ".${SWIG_CXX_EXTENSION}")
- else()
- string(APPEND swig_generated_file_fullname
- ".c")
- endif()
-
- get_directory_property (cmake_include_directories INCLUDE_DIRECTORIES)
- list (REMOVE_DUPLICATES cmake_include_directories)
- set (swig_include_dirs)
- if (cmake_include_directories)
- set (swig_include_dirs "$<$<BOOL:${cmake_include_directories}>:-I$<JOIN:${cmake_include_directories},$<SEMICOLON>-I>>")
- endif()
-
- set(swig_special_flags)
- # default is c, so add c++ flag if it is c++
- if(swig_source_file_cplusplus)
- list (APPEND swig_special_flags "-c++")
- endif()
-
- set (swig_extra_flags)
- if(SWIG_MODULE_${name}_LANGUAGE STREQUAL "CSHARP")
- if(NOT ("-dllimport" IN_LIST swig_source_file_flags OR "-dllimport" IN_LIST SWIG_MODULE_${name}_EXTRA_FLAGS))
- # This makes sure that the name used in the generated DllImport
- # matches the library name created by CMake
- list (APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-dllimport" "${name}")
- endif()
- endif()
- list (APPEND swig_extra_flags ${SWIG_MODULE_${name}_EXTRA_FLAGS})
-
- # dependencies
- set (swig_dependencies ${SWIG_MODULE_${name}_EXTRA_DEPS} $<TARGET_PROPERTY:${name},SWIG_DEPENDS>)
- get_source_file_property(file_depends "${infile}" DEPENDS)
- if (file_depends)
- list (APPEND swig_dependencies ${file_depends})
- endif()
-
- if (UseSWIG_MODULE_VERSION VERSION_GREATER 1)
- # as part of custom command, start by removing old generated files
- # to ensure obsolete files do not stay
- set (swig_cleanup_command COMMAND "${CMAKE_COMMAND}" -E remove_directory "${outdir}")
- else()
- unset (swig_cleanup_command)
- endif()
-
- # IMPLICIT_DEPENDS below can not handle situations where a dependent file is
- # removed. We need an extra step with timestamp and custom target, see #16830
- # As this is needed only for Makefile generator do it conditionally
- if(CMAKE_GENERATOR MATCHES "Make")
- __swig_compute_timestamp(${name} ${SWIG_MODULE_${name}_LANGUAGE}
- "${infile}" "${workingdir}" swig_generated_timestamp)
- set(swig_custom_output "${swig_generated_timestamp}")
- set(swig_custom_products
- BYPRODUCTS "${swig_generated_file_fullname}" ${swig_extra_generated_files})
- set(swig_timestamp_command
- COMMAND ${CMAKE_COMMAND} -E touch "${swig_generated_timestamp}")
- else()
- set(swig_custom_output
- "${swig_generated_file_fullname}" ${swig_extra_generated_files})
- set(swig_custom_products)
- set(swig_timestamp_command)
- endif()
- add_custom_command(
- OUTPUT ${swig_custom_output}
- ${swig_custom_products}
- ${swig_cleanup_command}
- # Let's create the ${outdir} at execution time, in case dir contains $(OutDir)
- COMMAND "${CMAKE_COMMAND}" -E make_directory ${outdir} ${outfiledir}
- ${swig_timestamp_command}
- COMMAND "${CMAKE_COMMAND}" -E env "SWIG_LIB=${SWIG_DIR}" "${SWIG_EXECUTABLE}"
- "-${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}"
- "${swig_source_file_flags}"
- -outdir "${outdir}"
- ${swig_special_flags}
- ${swig_extra_flags}
- "${swig_include_dirs}"
- -o "${swig_generated_file_fullname}"
- "${swig_source_file_fullname}"
- MAIN_DEPENDENCY "${swig_source_file_fullname}"
- DEPENDS ${swig_dependencies}
- IMPLICIT_DEPENDS CXX "${swig_source_file_fullname}"
- COMMENT "Swig source ${infile}"
- COMMAND_EXPAND_LISTS)
- set_source_files_properties("${swig_generated_file_fullname}" ${swig_extra_generated_files}
- PROPERTIES GENERATED 1)
-
- ## add all properties for generated file to various properties
- get_property (include_directories SOURCE "${infile}" PROPERTY GENERATED_INCLUDE_DIRECTORIES)
- set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY INCLUDE_DIRECTORIES ${include_directories} $<TARGET_PROPERTY:${name},SWIG_GENERATED_INCLUDE_DIRECTORIES>)
-
- # get_property (compile_definitions SOURCE "${infile}" PROPERTY GENERATED_COMPILE_DEFINITIONS)
- # set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY COMPILE_DEFINITIONS $<TARGET_PROPERTY:${name},SWIG_GENERATED_COMPILE_DEFINITIONS> ${compile_definitions})
-
- # get_property (compile_options SOURCE "${infile}" PROPERTY GENERATED_COMPILE_OPTIONS)
- # set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY COMPILE_OPTIONS $<TARGET_PROPERTY:${name},SWIG_GENERATED_COMPILE_OPTIONS> ${compile_options})
-
- set(${outfiles} "${swig_generated_file_fullname}" ${swig_extra_generated_files} PARENT_SCOPE)
-
- # legacy support
- set (swig_generated_file_fullname "${swig_generated_file_fullname}" PARENT_SCOPE)
-endfunction()
-
-#
-# Create Swig module
-#
-macro(SWIG_ADD_MODULE name language)
- message(DEPRECATION "SWIG_ADD_MODULE is deprecated. Use SWIG_ADD_LIBRARY instead.")
- swig_add_library(${name}
- LANGUAGE ${language}
- TYPE MODULE
- SOURCES ${ARGN})
-endmacro()
-
-
-function(SWIG_ADD_LIBRARY name)
- set(options NO_PROXY)
- set(oneValueArgs LANGUAGE
- TYPE
- OUTPUT_DIR
- OUTFILE_DIR)
- set(multiValueArgs SOURCES)
- cmake_parse_arguments(_SAM "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
-
- if (TARGET ${name})
- # a target with same name is already defined.
- # call NOW add_library command to raise the most useful error message
- add_library(${name})
- return()
- endif()
-
- if (_SAM_UNPARSED_ARGUMENTS)
- message(FATAL_ERROR "SWIG_ADD_LIBRARY: ${_SAM_UNPARSED_ARGUMENTS}: unexpected arguments")
- endif()
-
- if(NOT DEFINED _SAM_LANGUAGE)
- message(FATAL_ERROR "SWIG_ADD_LIBRARY: Missing LANGUAGE argument")
- endif()
-
- if(NOT DEFINED _SAM_SOURCES)
- message(FATAL_ERROR "SWIG_ADD_LIBRARY: Missing SOURCES argument")
- endif()
-
- if(NOT DEFINED _SAM_TYPE)
- set(_SAM_TYPE MODULE)
- elseif(_SAM_TYPE STREQUAL "USE_BUILD_SHARED_LIBS")
- unset(_SAM_TYPE)
- endif()
-
- if (NOT DEFINED UseSWIG_MODULE_VERSION)
- set (UseSWIG_MODULE_VERSION 1)
- elseif (NOT UseSWIG_MODULE_VERSION MATCHES "^(1|2)$")
- message (FATAL_ERROR "UseSWIG_MODULE_VERSION: ${UseSWIG_MODULE_VERSION}: invalid value. 1 or 2 is expected.")
- endif()
-
- set (workingdir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${name}.dir")
- # set special variable to pass extra information to command SWIG_ADD_SOURCE_TO_MODULE
- # which cannot be changed due to legacy compatibility
- set (SWIG_WORKING_DIR "${workingdir}")
-
- set (outputdir "${_SAM_OUTPUT_DIR}")
- if (NOT _SAM_OUTPUT_DIR)
- if (CMAKE_SWIG_OUTDIR)
- set (outputdir "${CMAKE_SWIG_OUTDIR}")
- else()
- if (UseSWIG_MODULE_VERSION VERSION_GREATER 1)
- set (outputdir "${workingdir}/${_SAM_LANGUAGE}.files")
- else()
- set (outputdir "${CMAKE_CURRENT_BINARY_DIR}")
- endif()
- endif()
- endif()
-
- set (outfiledir "${_SAM_OUTFILE_DIR}")
- if(NOT _SAM_OUTFILE_DIR)
- if (SWIG_OUTFILE_DIR)
- set (outfiledir "${SWIG_OUTFILE_DIR}")
- else()
- if (_SAM_OUTPUT_DIR OR CMAKE_SWIG_OUTDIR)
- set (outfiledir "${outputdir}")
- else()
- set (outfiledir "${workingdir}")
- endif()
- endif()
- endif()
- # set again, locally, predefined variables to ensure compatibility
- # with command SWIG_ADD_SOURCE_TO_MODULE
- set(CMAKE_SWIG_OUTDIR "${outputdir}")
- set(SWIG_OUTFILE_DIR "${outfiledir}")
-
- set (SWIG_MODULE_${name}_NOPROXY ${_SAM_NO_PROXY})
- swig_module_initialize(${name} ${_SAM_LANGUAGE})
-
- set(swig_dot_i_sources ${_SAM_SOURCES})
- list(FILTER swig_dot_i_sources INCLUDE REGEX "\\.i$")
- if (NOT swig_dot_i_sources)
- message(FATAL_ERROR "SWIG_ADD_LIBRARY: no SWIG interface files specified")
- endif()
- set(swig_other_sources ${_SAM_SOURCES})
- list(REMOVE_ITEM swig_other_sources ${swig_dot_i_sources})
-
- set(swig_generated_sources)
- set(swig_generated_timestamps)
- foreach(swig_it IN LISTS swig_dot_i_sources)
- SWIG_ADD_SOURCE_TO_MODULE(${name} swig_generated_source "${swig_it}")
- list (APPEND swig_generated_sources "${swig_generated_source}")
- if(CMAKE_GENERATOR MATCHES "Make")
- __swig_compute_timestamp(${name} ${SWIG_MODULE_${name}_LANGUAGE} "${swig_it}"
- "${workingdir}" swig_timestamp)
- list (APPEND swig_generated_timestamps "${swig_timestamp}")
- endif()
- endforeach()
- set_property (DIRECTORY APPEND PROPERTY
- ADDITIONAL_MAKE_CLEAN_FILES ${swig_generated_sources} ${swig_generated_timestamps})
- if (UseSWIG_MODULE_VERSION VERSION_GREATER 1)
- set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${outputdir}")
- endif()
-
- add_library(${name}
- ${_SAM_TYPE}
- ${swig_generated_sources}
- ${swig_other_sources})
- if(CMAKE_GENERATOR MATCHES "Make")
- # see IMPLICIT_DEPENDS above
- add_custom_target(${name}_swig_compilation DEPENDS ${swig_generated_timestamps})
- add_dependencies(${name} ${name}_swig_compilation)
- endif()
- if(_SAM_TYPE STREQUAL "MODULE")
- set_target_properties(${name} PROPERTIES NO_SONAME ON)
- endif()
- string(TOLOWER "${_SAM_LANGUAGE}" swig_lowercase_language)
- if (swig_lowercase_language STREQUAL "octave")
- set_target_properties(${name} PROPERTIES PREFIX "")
- set_target_properties(${name} PROPERTIES SUFFIX ".oct")
- elseif (swig_lowercase_language STREQUAL "go")
- set_target_properties(${name} PROPERTIES PREFIX "")
- elseif (swig_lowercase_language STREQUAL "java")
- # In java you want:
- # System.loadLibrary("LIBRARY");
- # then JNI will look for a library whose name is platform dependent, namely
- # MacOS : libLIBRARY.jnilib
- # Windows: LIBRARY.dll
- # Linux : libLIBRARY.so
- if (APPLE)
- set_target_properties (${name} PROPERTIES SUFFIX ".jnilib")
- endif()
- if ((WIN32 AND MINGW) OR CYGWIN OR CMAKE_SYSTEM_NAME STREQUAL MSYS)
- set_target_properties(${name} PROPERTIES PREFIX "")
- endif()
- elseif (swig_lowercase_language STREQUAL "lua")
- if(_SAM_TYPE STREQUAL "MODULE")
- set_target_properties(${name} PROPERTIES PREFIX "")
- endif()
- elseif (swig_lowercase_language STREQUAL "python")
- if (SWIG_MODULE_${name}_NOPROXY)
- set_target_properties(${name} PROPERTIES PREFIX "")
- else()
- # swig will produce a module.py containing an 'import _modulename' statement,
- # which implies having a corresponding _modulename.so (*NIX), _modulename.pyd (Win32),
- # unless the -noproxy flag is used
- set_target_properties(${name} PROPERTIES PREFIX "_")
- endif()
- # Python extension modules on Windows must have the extension ".pyd"
- # instead of ".dll" as of Python 2.5. Older python versions do support
- # this suffix.
- # http://docs.python.org/whatsnew/ports.html#SECTION0001510000000000000000
- # <quote>
- # Windows: .dll is no longer supported as a filename extension for extension modules.
- # .pyd is now the only filename extension that will be searched for.
- # </quote>
- if(WIN32 AND NOT CYGWIN)
- set_target_properties(${name} PROPERTIES SUFFIX ".pyd")
- endif()
- elseif (swig_lowercase_language STREQUAL "r")
- set_target_properties(${name} PROPERTIES PREFIX "")
- elseif (swig_lowercase_language STREQUAL "ruby")
- # In ruby you want:
- # require 'LIBRARY'
- # then ruby will look for a library whose name is platform dependent, namely
- # MacOS : LIBRARY.bundle
- # Windows: LIBRARY.dll
- # Linux : LIBRARY.so
- set_target_properties (${name} PROPERTIES PREFIX "")
- if (APPLE)
- set_target_properties (${name} PROPERTIES SUFFIX ".bundle")
- endif ()
- elseif (swig_lowercase_language STREQUAL "perl")
- # assume empty prefix because we expect the module to be dynamically loaded
- set_target_properties (${name} PROPERTIES PREFIX "")
- if (APPLE)
- set_target_properties (${name} PROPERTIES SUFFIX ".dylib")
- endif ()
- else()
- # assume empty prefix because we expect the module to be dynamically loaded
- set_target_properties (${name} PROPERTIES PREFIX "")
- endif ()
-
- # target property SWIG_SUPPORT_FILES_DIRECTORY specify output directory of support files
- set_property (TARGET ${name} PROPERTY SWIG_SUPPORT_FILES_DIRECTORY "${outputdir}")
- # target property SWIG_SUPPORT_FILES lists principal proxy support files
- if (NOT SWIG_MODULE_${name}_NOPROXY)
- string(TOUPPER "${_SAM_LANGUAGE}" swig_uppercase_language)
- set(swig_all_support_files)
- foreach (swig_it IN LISTS SWIG_${swig_uppercase_language}_EXTRA_FILE_EXTENSIONS)
- set (swig_support_files ${swig_generated_sources})
- list (FILTER swig_support_files INCLUDE REGEX ".*${swig_it}$")
- list(APPEND swig_all_support_files ${swig_support_files})
- endforeach()
- if (swig_all_support_files)
- list(REMOVE_DUPLICATES swig_all_support_files)
- endif()
- set_property (TARGET ${name} PROPERTY SWIG_SUPPORT_FILES ${swig_all_support_files})
- endif()
-
- # to ensure legacy behavior, export some variables
- set (SWIG_MODULE_${name}_LANGUAGE "${SWIG_MODULE_${name}_LANGUAGE}" PARENT_SCOPE)
- set (SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG "${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}" PARENT_SCOPE)
- set (SWIG_MODULE_${name}_REAL_NAME "${name}" PARENT_SCOPE)
- set (SWIG_MODULE_${name}_NOPROXY "${SWIG_MODULE_${name}_NOPROXY}" PARENT_SCOPE)
- set (SWIG_MODULE_${name}_EXTRA_FLAGS "${SWIG_MODULE_${name}_EXTRA_FLAGS}" PARENT_SCOPE)
- # the last one is a bit crazy but it is documented, so...
- # NOTA: works as expected if only ONE input file is specified
- set (swig_generated_file_fullname "${swig_generated_file_fullname}" PARENT_SCOPE)
-endfunction()
-
-#
-# Like TARGET_LINK_LIBRARIES but for swig modules
-#
-function(SWIG_LINK_LIBRARIES name)
- message(DEPRECATION "SWIG_LINK_LIBRARIES is deprecated. Use TARGET_LINK_LIBRARIES instead.")
- if(SWIG_MODULE_${name}_REAL_NAME)
- target_link_libraries(${name} ${ARGN})
- else()
- message(SEND_ERROR "Cannot find Swig library \"${name}\".")
- endif()
-endfunction()