summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorAndrej Rode <mail@andrejro.de>2018-06-23 23:41:42 +0200
committerAndrej Rode <mail@andrejro.de>2018-06-24 00:03:35 +0200
commit167a6152bad060fc53dd29e0fa79ef83eff1be5b (patch)
treea01049672d9d7d1bf3d295ed96698a323941f8e8 /cmake
parent3c8e6008b092287246234001db7cf1a4038300da (diff)
parentfcd002b6ac82e1e0c1224e24506410ff0833e1aa (diff)
Merge branch 'python3_fix' into next
Manual merge conflict resolution has been applied to following conflicts: * Typos: * gnuradio-runtime/python/gnuradio/ctrlport/GrDataPlotter.py * gr-blocks/python/blocks/qa_wavfile.py * gr-filter/examples/gr_filtdes_api.py * grc/blocks/parameter.xml * gr-uhd/python/uhd/__init__.py * ValueError -> RuntimeError: * gr-blocks/python/blocks/qa_hier_block2.py * relative Imports & other Py3k: * gr-digital/python/digital/psk_constellations.py * gr-digital/python/digital/qam_constellations.py * gr-digital/python/digital/test_soft_decisions.py * gr-digital/python/digital/gfsk.py * SequenceCompleter: * gr-utils/python/modtool/modtool_add.py * gr-utils/python/modtool/modtool_rename.py * gr-utils/python/modtool/modtool_rm.py * Updated API on next: * gr-blocks/grc/blocks_file_source.xml * gr-blocks/python/blocks/qa_file_source_sink.py * gr-qtgui/grc/qtgui_time_sink_x.xml * GRC Py3k Updates: * grc/core/Block.py * grc/core/Constants.py * grc/core/Platform.py * grc/core/utils/odict.py * grc/gui/Actions.py * grc/gui/Block.py * grc/gui/Executor.py * grc/gui/Port.py
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Modules/GrMiscUtils.cmake10
-rw-r--r--cmake/Modules/GrPython.cmake164
-rw-r--r--cmake/Modules/GrSwig.cmake13
-rw-r--r--cmake/Modules/UseSWIG.cmake2
4 files changed, 129 insertions, 60 deletions
diff --git a/cmake/Modules/GrMiscUtils.cmake b/cmake/Modules/GrMiscUtils.cmake
index 79bb70c03e..6f0c8ac270 100644
--- a/cmake/Modules/GrMiscUtils.cmake
+++ b/cmake/Modules/GrMiscUtils.cmake
@@ -339,7 +339,7 @@ if __name__ == '__main__':
add_custom_command(
OUTPUT ${expanded_files_h}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${root}.h.t
- COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+ COMMAND ${PYTHON_EXECUTABLE} -B
${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
${root} ${root}.h.t ${ARGN}
)
@@ -384,7 +384,7 @@ if __name__ == '__main__':
add_custom_command(
OUTPUT ${expanded_files_cc}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${root}.cc.t
- COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+ COMMAND ${PYTHON_EXECUTABLE} -B
${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
${root} ${root}.cc.t ${ARGN}
)
@@ -393,7 +393,7 @@ if __name__ == '__main__':
add_custom_command(
OUTPUT ${expanded_files_h}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${root}.h.t
- COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+ COMMAND ${PYTHON_EXECUTABLE} -B
${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
${root} ${root}.h.t ${ARGN}
)
@@ -446,7 +446,7 @@ if __name__ == '__main__':
add_custom_command(
OUTPUT ${expanded_files_cc_impl}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${root}_impl.cc.t
- COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+ COMMAND ${PYTHON_EXECUTABLE} -B
${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
${root} ${root}_impl.cc.t ${ARGN}
)
@@ -455,7 +455,7 @@ if __name__ == '__main__':
add_custom_command(
OUTPUT ${expanded_files_h_impl}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${root}_impl.h.t
- COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+ COMMAND ${PYTHON_EXECUTABLE} -B
${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
${root} ${root}_impl.h.t ${ARGN}
)
diff --git a/cmake/Modules/GrPython.cmake b/cmake/Modules/GrPython.cmake
index 0bfa92db8d..49a351d3a7 100644
--- a/cmake/Modules/GrPython.cmake
+++ b/cmake/Modules/GrPython.cmake
@@ -1,4 +1,4 @@
-# Copyright 2010-2011 Free Software Foundation, Inc.
+# Copyright 2010-2016 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -27,26 +27,21 @@ set(__INCLUDED_GR_PYTHON_CMAKE TRUE)
# 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)
+if (PYTHON_EXECUTABLE)
+ message(STATUS "User set python executable ${PYTHON_EXECUTABLE}")
+ find_package(PythonInterp ${GR_PYTHON_MIN_VERSION} REQUIRED)
+else (PYTHON_EXECUTABLE)
+ message(STATUS "PYTHON_EXECUTABLE not set - using default python3")
+ message(STATUS "Use -DPYTHON_EXECUTABLE=/path/to/python2 to build for python2.")
+ find_package(PythonInterp ${GR_PYTHON3_MIN_VERSION} REQUIRED)
+endif (PYTHON_EXECUTABLE)
-#otherwise if not set, try to automatically find it
-else(PYTHON_EXECUTABLE)
+if (${PYTHON_VERSION_MAJOR} VERSION_EQUAL 3)
+ set(PYTHON3 TRUE)
+endif ()
- #use the built-in find script
- find_package(PythonInterp 2)
-
- #and if that fails use the find program routine
- if(NOT PYTHONINTERP_FOUND)
- find_program(PYTHON_EXECUTABLE NAMES python python2 python2.7 python2.6 python2.5)
- if(PYTHON_EXECUTABLE)
- set(PYTHONINTERP_FOUND TRUE)
- endif(PYTHON_EXECUTABLE)
- endif(NOT PYTHONINTERP_FOUND)
-
-endif(PYTHON_EXECUTABLE)
+find_package(PythonLibs ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} EXACT)
if (CMAKE_CROSSCOMPILING)
set(QA_PYTHON_EXECUTABLE "/usr/bin/python")
@@ -58,18 +53,6 @@ endif(CMAKE_CROSSCOMPILING)
set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "python interpreter")
set(QA_PYTHON_EXECUTABLE ${QA_PYTHON_EXECUTABLE} CACHE FILEPATH "python interpreter for QA tests")
-#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
@@ -77,27 +60,32 @@ endif(PYTHON_EXECUTABLE)
# - 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}")
+macro(GR_PYTHON_CHECK_MODULE_RAW desc python_code have)
execute_process(
- COMMAND ${PYTHON_EXECUTABLE} -c "
+ COMMAND ${PYTHON_EXECUTABLE} -c "${python_code}"
+ OUTPUT_QUIET ERROR_QUIET
+ RESULT_VARIABLE return_code
+ )
+ if(return_code EQUAL 0)
+ message(STATUS "Python checking for ${desc} - found")
+ set(${have} TRUE)
+ else()
+ message(STATUS "Python checking for ${desc} - not found")
+ set(${have} FALSE)
+ endif()
+endmacro(GR_PYTHON_CHECK_MODULE_RAW)
+
+macro(GR_PYTHON_CHECK_MODULE desc mod cmd have)
+ GR_PYTHON_CHECK_MODULE_RAW(
+ "${desc}" "
#########################################
try:
import ${mod}
assert ${cmd}
-except ImportError, AssertionError: exit(-1)
+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)
+ "${have}")
endmacro(GR_PYTHON_CHECK_MODULE)
########################################################################
@@ -105,8 +93,12 @@ endmacro(GR_PYTHON_CHECK_MODULE)
########################################################################
if(NOT DEFINED GR_PYTHON_DIR)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "
-from distutils import sysconfig
-print sysconfig.get_python_lib(plat_specific=True, prefix='')
+import os
+import sys
+if os.name == 'posix':
+ print(os.path.join('lib', 'python' + sys.version[:3], 'dist-packages'))
+if os.name == 'nt':
+ print(os.path.join('Lib', 'site-packages'))
" OUTPUT_VARIABLE GR_PYTHON_DIR OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
@@ -119,7 +111,7 @@ file(TO_CMAKE_PATH ${GR_PYTHON_DIR} GR_PYTHON_DIR)
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]
+unique = hashlib.md5(b'${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})
@@ -130,7 +122,7 @@ endfunction(GR_UNIQUE_TARGET)
########################################################################
function(GR_PYTHON_INSTALL)
include(CMakeParseArgumentsCopy)
- CMAKE_PARSE_ARGUMENTS(GR_PYTHON_INSTALL "" "DESTINATION" "FILES;PROGRAMS" ${ARGN})
+ CMAKE_PARSE_ARGUMENTS(GR_PYTHON_INSTALL "" "DESTINATION" "FILES;PROGRAMS;DIRECTORY" ${ARGN})
####################################################################
if(GR_PYTHON_INSTALL_FILES)
@@ -185,6 +177,80 @@ function(GR_PYTHON_INSTALL)
)
####################################################################
+ elseif(GR_PYTHON_INSTALL_DIRECTORY)
+ ####################################################################
+ install(${ARGN}) #installs regular python files
+
+ # collect all python files in given directories
+ # #############################################
+ unset(pysrcfiles)
+ foreach(pydir ${GR_PYTHON_INSTALL_DIRECTORY})
+ file(GLOB_RECURSE pysrcfiles_tmp "${pydir}/*.py")
+ list(APPEND pysrcfiles ${pysrcfiles_tmp})
+ endforeach(pydir)
+
+ # build target lists
+ # ##################
+ unset(pycfiles) # pyc targets
+ unset(pyofiles) # pyo targets
+ unset(pygen_paths) # all paths of py[oc] targets
+ foreach(pyfile ${pysrcfiles})
+ # 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")
+
+ get_filename_component(pygen_path "${pygenfile}" DIRECTORY)
+ list(APPEND pygen_paths "${pygen_path}")
+ file(MAKE_DIRECTORY "${pygen_path}")
+ endforeach(pyfile)
+ list(REMOVE_DUPLICATES pygen_paths)
+ list(SORT pygen_paths)
+
+ # generate the py[oc] files
+ # #########################
+ add_custom_command(
+ DEPENDS ${pysrcfiles} OUTPUT ${pycfiles}
+ COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_BINARY_DIR}/python_compile_helper.py ${pysrcfiles} ${pycfiles}
+ )
+ add_custom_command(
+ DEPENDS ${pysrcfiles} OUTPUT ${pyofiles}
+ COMMAND ${PYTHON_EXECUTABLE} -O ${CMAKE_BINARY_DIR}/python_compile_helper.py ${pysrcfiles} ${pyofiles}
+ )
+ set(python_install_gen_targets ${pycfiles} ${pyofiles})
+
+ # per-directory install rules
+ # ###########################
+ foreach(pygen_path ${pygen_paths})
+ # find all targets in that directory (no "list(FILTER ...)")
+ unset(pygen_path_targets)
+ foreach(pyget_target ${python_install_gen_targets})
+ get_filename_component(pyget_target_path "${pyget_target}" PATH)
+ if(pygen_path STREQUAL pyget_target_path)
+ list(APPEND pygen_path_targets "${pyget_target}")
+ endif()
+ endforeach(pyget_target)
+
+ # install relative to current binary dir
+ file(RELATIVE_PATH pygen_path_rel "${CMAKE_CURRENT_BINARY_DIR}" "${pygen_path}")
+ list(SORT pygen_path_targets)
+ install(
+ FILES ${pygen_path_targets}
+ DESTINATION "${GR_PYTHON_INSTALL_DESTINATION}/${pygen_path_rel}"
+ )
+ endforeach(pygen_path)
+
+ ####################################################################
elseif(GR_PYTHON_INSTALL_PROGRAMS)
####################################################################
file(TO_NATIVE_PATH ${PYTHON_EXECUTABLE} pyexe_native)
@@ -233,7 +299,7 @@ endfunction(GR_PYTHON_INSTALL)
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:]
+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/GrSwig.cmake b/cmake/Modules/GrSwig.cmake
index 0115c4da98..87d5e60d8a 100644
--- a/cmake/Modules/GrSwig.cmake
+++ b/cmake/Modules/GrSwig.cmake
@@ -76,7 +76,7 @@ function(GR_SWIG_MAKE_DOCS output_file)
add_custom_command(
OUTPUT ${output_file}
DEPENDS ${input_files} ${stamp-file} ${OUTPUT_DIRECTORY}/xml/index.xml
- COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+ COMMAND ${PYTHON_EXECUTABLE} -B
${CMAKE_SOURCE_DIR}/docs/doxygen/swig_doc.py
${OUTPUT_DIRECTORY}/xml
${output_file}
@@ -146,7 +146,6 @@ macro(GR_SWIG_MAKE name)
endif()
#append additional include directories
- find_package(PythonLibs 2)
list(APPEND GR_SWIG_INCLUDE_DIRS ${PYTHON_INCLUDE_PATH}) #deprecated name (now dirs)
list(APPEND GR_SWIG_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS})
@@ -178,8 +177,12 @@ macro(GR_SWIG_MAKE name)
include_directories(${GR_SWIG_INCLUDE_DIRS})
list(APPEND SWIG_MODULE_${name}_EXTRA_DEPS ${tag_file})
+ if (PYTHON3)
+ set(py3 "-py3")
+ endif (PYTHON3)
+
#setup the swig flags with flags and include directories
- set(CMAKE_SWIG_FLAGS -fvirtual -modern -keyword -w511 -w314 -module ${name} ${GR_SWIG_FLAGS})
+ set(CMAKE_SWIG_FLAGS -fvirtual -modern -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)
@@ -238,7 +241,7 @@ endmacro(GR_SWIG_INSTALL)
########################################################################
file(WRITE ${CMAKE_BINARY_DIR}/get_swig_deps.py "
-import os, sys, re
+import os, sys, re, io
i_include_matcher = re.compile('%(include|import)\\s*[<|\"](.*)[>|\"]')
h_include_matcher = re.compile('#(include)\\s*[<|\"](.*)[>|\"]')
@@ -247,7 +250,7 @@ include_dirs = sys.argv[2].split(';')
def get_swig_incs(file_path):
if file_path.endswith('.i'): matcher = i_include_matcher
else: matcher = h_include_matcher
- file_contents = open(file_path, 'r').read()
+ file_contents = io.open(file_path, 'r', encoding='utf-8').read()
return matcher.findall(file_contents, re.MULTILINE)
def get_swig_deps(file_path, level):
diff --git a/cmake/Modules/UseSWIG.cmake b/cmake/Modules/UseSWIG.cmake
index e55543532f..a37cc41ae4 100644
--- a/cmake/Modules/UseSWIG.cmake
+++ b/cmake/Modules/UseSWIG.cmake
@@ -176,7 +176,7 @@ macro(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
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]
+unique = hashlib.md5(b'${reldir}${ARGN}').hexdigest()[:5]
print(re.sub('\\W', '_', '${name} ${reldir} ' + unique))"
OUTPUT_VARIABLE _target OUTPUT_STRIP_TRAILING_WHITESPACE
)