| 1 |
# |
| 2 |
# Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
# or more contributor license agreements. See the NOTICE file |
| 4 |
# distributed with this work for additional information |
| 5 |
# regarding copyright ownership. The ASF licenses this file |
| 6 |
# to you under the Apache License, Version 2.0 (the |
| 7 |
# "License"); you may not use this file except in compliance |
| 8 |
# with the License. You may obtain a copy of the License at |
| 9 |
# |
| 10 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
# |
| 12 |
# Unless required by applicable law or agreed to in writing, |
| 13 |
# software distributed under the License is distributed on an |
| 14 |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
# KIND, either express or implied. See the License for the |
| 16 |
# specific language governing permissions and limitations |
| 17 |
# under the License. |
| 18 |
# |
| 19 |
|
| 20 |
# NB For python the SWIG module name must have the same name as the input .i file for CMake to generate the |
| 21 |
# correct dependencies |
| 22 |
|
| 23 |
set(CMAKE_SWIG_FLAGS "-threads" "-DUINTPTR_SIZE=${CMAKE_SIZEOF_VOID_P}") |
| 24 |
|
| 25 |
include_directories (${PN_C_INCLUDE_DIR} ${Python_INCLUDE_DIRS}) |
| 26 |
|
| 27 |
set_source_files_properties(cproton.i PROPERTIES CPLUSPLUS NO) |
| 28 |
|
| 29 |
# Suppress warnings in swig generated code. |
| 30 |
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
| 31 |
|
| 32 |
# Set Compiler extra flags for Solaris when using SunStudio |
| 33 |
if (CMAKE_C_COMPILER_ID STREQUAL "SunPro") |
| 34 |
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSWIGEXPORT=__global") |
| 35 |
endif () |
| 36 |
|
| 37 |
|
| 38 |
list(APPEND SWIG_MODULE_cproton_EXTRA_DEPS |
| 39 |
${CMAKE_SOURCE_DIR}/c/include/proton/cproton.i |
| 40 |
${PROTON_HEADERS} |
| 41 |
) |
| 42 |
|
| 43 |
swig_add_library(cproton LANGUAGE python SOURCES cproton.i) |
| 44 |
swig_link_libraries(cproton ${BINDING_DEPS} ${Python_LIBRARIES} -lm) |
| 45 |
set_target_properties(${SWIG_MODULE_cproton_REAL_NAME} |
| 46 |
PROPERTIES |
| 47 |
LINK_FLAGS "${CATCH_UNDEFINED}") |
| 48 |
|
| 49 |
if (CHECK_SYSINSTALL_PYTHON) |
| 50 |
execute_process(COMMAND ${Python_EXECUTABLE} |
| 51 |
-c "from distutils.sysconfig import get_python_lib; print(get_python_lib(True))" |
| 52 |
OUTPUT_VARIABLE PYTHON_SITEARCH_PACKAGES_DEFAULT |
| 53 |
OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 54 |
else () |
| 55 |
set (PYTHON_SITEARCH_PACKAGES_DEFAULT ${BINDINGS_DIR}/python) |
| 56 |
endif () |
| 57 |
|
| 58 |
if (NOT PYTHON_SITEARCH_PACKAGES) |
| 59 |
set (PYTHON_SITEARCH_PACKAGES ${PYTHON_SITEARCH_PACKAGES_DEFAULT}) |
| 60 |
endif() |
| 61 |
|
| 62 |
set (pysrc-generated cproton.py) |
| 63 |
set (pysrc |
| 64 |
proton/__init__.py |
| 65 |
proton/_common.py |
| 66 |
proton/_condition.py |
| 67 |
proton/_data.py |
| 68 |
proton/_delivery.py |
| 69 |
proton/_endpoints.py |
| 70 |
proton/_events.py |
| 71 |
proton/_exceptions.py |
| 72 |
proton/_io.py |
| 73 |
proton/_message.py |
| 74 |
proton/_tracing.py |
| 75 |
proton/_transport.py |
| 76 |
proton/_url.py |
| 77 |
proton/_wrapper.py |
| 78 |
|
| 79 |
proton/handlers.py |
| 80 |
proton/reactor.py |
| 81 |
proton/tracing.py |
| 82 |
proton/utils.py |
| 83 |
|
| 84 |
proton/_handlers.py |
| 85 |
proton/_reactor.py |
| 86 |
proton/_selectable.py |
| 87 |
proton/_utils.py |
| 88 |
) |
| 89 |
# extra files included in the source distribution |
| 90 |
set(py_dist_files |
| 91 |
cproton.i |
| 92 |
MANIFEST.in |
| 93 |
setuputils/__init__.py |
| 94 |
setuputils/log.py |
| 95 |
setuputils/misc.py |
| 96 |
setuputils/PYZMQ_LICENSE.BSD |
| 97 |
docs/conf.py |
| 98 |
docs/index.rst |
| 99 |
docs/overview.rst |
| 100 |
docs/tutorial.rst |
| 101 |
) |
| 102 |
|
| 103 |
macro (py_compile directory files artifacts) |
| 104 |
foreach (src_file ${files}) |
| 105 |
install(CODE "execute_process(COMMAND \"${Python_EXECUTABLE}\" -c \"import py_compile; py_compile.compile('${src_file}', cfile='${src_file}c')\" |
| 106 |
WORKING_DIRECTORY ${directory})") |
| 107 |
install(CODE "execute_process(COMMAND \"${Python_EXECUTABLE}\" -O -c \"import py_compile; py_compile.compile('${src_file}', cfile='${src_file}o')\" |
| 108 |
WORKING_DIRECTORY ${directory})") |
| 109 |
list(APPEND ${artifacts} ${directory}/${src_file} |
| 110 |
${directory}/${src_file}c |
| 111 |
${directory}/${src_file}o) |
| 112 |
endforeach (src_file) |
| 113 |
endmacro(py_compile) |
| 114 |
|
| 115 |
py_compile(${CMAKE_CURRENT_BINARY_DIR} ${pysrc-generated} CPROTON_ARTIFACTS) |
| 116 |
py_compile(${CMAKE_CURRENT_SOURCE_DIR} "${pysrc}" PROTON_ARTIFACTS) |
| 117 |
|
| 118 |
# Sphinx documentation |
| 119 |
check_python_module("sphinx" SPHINX_MODULE_FOUND) |
| 120 |
if (NOT SPHINX_MODULE_FOUND) |
| 121 |
message(STATUS "Sphinx modules not found; doc generation disabled.") |
| 122 |
else () |
| 123 |
add_custom_target(docs-py |
| 124 |
COMMAND ${PN_ENV_SCRIPT} -- |
| 125 |
PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:${CMAKE_CURRENT_SOURCE_DIR} |
| 126 |
LD_LIBRARY_PATH="${CMAKE_CURRENT_BINARY_DIR}/c" |
| 127 |
${Python_EXECUTABLE} -m sphinx "${CMAKE_CURRENT_SOURCE_DIR}/docs" "${CMAKE_CURRENT_BINARY_DIR}/docs") |
| 128 |
add_dependencies(docs docs-py) |
| 129 |
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/docs/" |
| 130 |
DESTINATION "${PROTON_SHARE}/docs/api-py" |
| 131 |
COMPONENT documentation |
| 132 |
OPTIONAL) |
| 133 |
endif () |
| 134 |
|
| 135 |
install(FILES ${CPROTON_ARTIFACTS} |
| 136 |
DESTINATION ${PYTHON_SITEARCH_PACKAGES} |
| 137 |
COMPONENT Python) |
| 138 |
install(FILES ${PROTON_ARTIFACTS} |
| 139 |
DESTINATION "${PYTHON_SITEARCH_PACKAGES}/proton/" |
| 140 |
COMPONENT Python) |
| 141 |
install(TARGETS ${SWIG_MODULE_cproton_REAL_NAME} |
| 142 |
DESTINATION ${PYTHON_SITEARCH_PACKAGES} |
| 143 |
COMPONENT Python) |
| 144 |
install(DIRECTORY examples/ |
| 145 |
DESTINATION "${PROTON_SHARE}/examples/python" |
| 146 |
COMPONENT Python |
| 147 |
USE_SOURCE_PERMISSIONS) |
| 148 |
|
| 149 |
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES docs) |
| 150 |
|
| 151 |
# |
| 152 |
# Set up the directory 'dist' for building the python native package |
| 153 |
# source distribution for Pypi/pip |
| 154 |
# |
| 155 |
|
| 156 |
set(py_dist_dir ${CMAKE_CURRENT_BINARY_DIR}/dist) |
| 157 |
|
| 158 |
add_custom_target(py_src_dist ALL) |
| 159 |
add_dependencies(py_src_dist generated_c_files) |
| 160 |
|
| 161 |
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README.rst.in |
| 162 |
${py_dist_dir}/README.rst |
| 163 |
) |
| 164 |
|
| 165 |
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in |
| 166 |
${py_dist_dir}/setup.py |
| 167 |
) |
| 168 |
|
| 169 |
add_custom_command(TARGET py_src_dist |
| 170 |
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PN_C_INCLUDE_DIR} "${py_dist_dir}/include") |
| 171 |
|
| 172 |
add_custom_command(TARGET py_src_dist |
| 173 |
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PN_C_SOURCE_DIR}/core "${py_dist_dir}/src/core") |
| 174 |
|
| 175 |
add_custom_command(TARGET py_src_dist |
| 176 |
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PN_C_SOURCE_DIR}/compiler "${py_dist_dir}/src/compiler") |
| 177 |
|
| 178 |
add_custom_command(TARGET py_src_dist |
| 179 |
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PN_C_SOURCE_DIR}/platform "${py_dist_dir}/src/platform") |
| 180 |
|
| 181 |
add_custom_command(TARGET py_src_dist |
| 182 |
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PN_C_SOURCE_DIR}/ssl "${py_dist_dir}/src/ssl") |
| 183 |
|
| 184 |
add_custom_command(TARGET py_src_dist |
| 185 |
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PN_C_SOURCE_DIR}/sasl "${py_dist_dir}/src/sasl") |
| 186 |
|
| 187 |
add_custom_command(TARGET py_src_dist |
| 188 |
COMMAND ${CMAKE_COMMAND} -E copy ${PN_C_SOURCE_DIR}/encodings.h "${py_dist_dir}/src") |
| 189 |
|
| 190 |
add_custom_command(TARGET py_src_dist |
| 191 |
COMMAND ${CMAKE_COMMAND} -E copy ${PN_C_SOURCE_DIR}/protocol.h "${py_dist_dir}/src") |
| 192 |
|
| 193 |
foreach(file IN LISTS py_dist_files pysrc) |
| 194 |
add_custom_command(TARGET py_src_dist |
| 195 |
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${file} "${py_dist_dir}/${file}") |
| 196 |
endforeach() |
| 197 |
|
| 198 |
# Make python source and binary packages if we have prerequisistes |
| 199 |
check_python_module("setuptools" SETUPTOOLS_MODULE_FOUND) |
| 200 |
check_python_module("wheel" WHEEL_MODULE_FOUND) |
| 201 |
if (SETUPTOOLS_MODULE_FOUND) |
| 202 |
add_custom_target(py_pkg_src ALL |
| 203 |
WORKING_DIRECTORY dist |
| 204 |
DEPENDS py_src_dist |
| 205 |
COMMAND ${PN_ENV_SCRIPT} "SWIG=${SWIG_EXECUTABLE}" -- |
| 206 |
${Python_EXECUTABLE} setup.py sdist --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/pkgs) |
| 207 |
if (WHEEL_MODULE_FOUND) |
| 208 |
add_custom_target(py_pkg_wheel ALL |
| 209 |
WORKING_DIRECTORY dist |
| 210 |
DEPENDS py_pkg_src |
| 211 |
COMMAND ${Python_EXECUTABLE} setup.py bdist_wheel --dist-dir ${CMAKE_CURRENT_BINARY_DIR}/pkgs) |
| 212 |
endif () |
| 213 |
endif () |
| 214 |
|
| 215 |
# python test: python/tests/proton-test |
| 216 |
set (py_src "${CMAKE_CURRENT_SOURCE_DIR}") |
| 217 |
set (py_bin "${CMAKE_CURRENT_BINARY_DIR}") |
| 218 |
set (py_dll "$<TARGET_FILE_DIR:_cproton>") |
| 219 |
set (py_bld "$<TARGET_FILE_DIR:qpid-proton-core>") # For windows |
| 220 |
set (py_tests "${py_src}/tests") |
| 221 |
set (tests_py "${py_src}/../tests/py") |
| 222 |
|
| 223 |
set (py_path ${CMAKE_BINARY_DIR}/c/tools ${py_bld} $ENV{PATH}) |
| 224 |
set (py_pythonpath ${py_tests} ${py_src} ${py_bin} ${py_dll} ${tests_py} $ENV{PYTHONPATH}) |
| 225 |
to_native_path ("${py_pythonpath}" py_pythonpath) |
| 226 |
to_native_path ("${py_path}" py_path) |
| 227 |
|
| 228 |
if (CMAKE_BUILD_TYPE MATCHES "Coverage") |
| 229 |
set (python_coverage_options -m coverage run --parallel-mode) |
| 230 |
endif(CMAKE_BUILD_TYPE MATCHES "Coverage") |
| 231 |
|
| 232 |
pn_add_test( |
| 233 |
INTERPRETED |
| 234 |
NAME python-test |
| 235 |
PREPEND_ENVIRONMENT |
| 236 |
"PATH=${py_path}" |
| 237 |
"PYTHONPATH=${py_pythonpath}" |
| 238 |
"SASLPASSWD=${CyrusSASL_Saslpasswd_EXECUTABLE}" |
| 239 |
COMMAND ${Python_EXECUTABLE} ${python_coverage_options} -- "${py_tests}/proton-test") |
| 240 |
set_tests_properties(python-test PROPERTIES PASS_REGULAR_EXPRESSION "Totals: .* 0 failed") |
| 241 |
|
| 242 |
set(PYTHON_TEST_COMMAND "-m" "unittest") |
| 243 |
pn_add_test( |
| 244 |
INTERPRETED |
| 245 |
NAME python-integration-test |
| 246 |
PREPEND_ENVIRONMENT |
| 247 |
"PATH=${py_path}" |
| 248 |
"PYTHONPATH=${py_pythonpath}" |
| 249 |
"SASLPASSWD=${CyrusSASL_Saslpasswd_EXECUTABLE}" |
| 250 |
COMMAND |
| 251 |
${Python_EXECUTABLE} |
| 252 |
${python_coverage_options} |
| 253 |
${PYTHON_TEST_COMMAND} discover -v -s "${py_tests}/integration") |
| 254 |
|
| 255 |
check_python_module("tox" TOX_MODULE_FOUND) |
| 256 |
if (NOT TOX_MODULE_FOUND) |
| 257 |
message(STATUS "The tox tool is not available; skipping the python-tox-tests") |
| 258 |
else () |
| 259 |
option(ENABLE_TOX_TEST "Enable multi-version python testing with TOX" ON) |
| 260 |
|
| 261 |
set(TOX_ENVLIST "" CACHE STRING "List of python environments for TOX tests" ) |
| 262 |
mark_as_advanced(TOX_ENVLIST) |
| 263 |
|
| 264 |
if (ENABLE_TOX_TEST) |
| 265 |
if (CMAKE_BUILD_TYPE MATCHES "Coverage") |
| 266 |
message(STATUS "Building for coverage analysis; skipping the python-tox-tests") |
| 267 |
else () |
| 268 |
add_custom_command(TARGET py_src_dist |
| 269 |
COMMAND ${CMAKE_COMMAND} -E copy |
| 270 |
"${CMAKE_CURRENT_SOURCE_DIR}/tox.ini" |
| 271 |
"${CMAKE_CURRENT_BINARY_DIR}/tox.ini") |
| 272 |
pn_add_test( |
| 273 |
INTERPRETED |
| 274 |
NAME python-tox-test |
| 275 |
PREPEND_ENVIRONMENT |
| 276 |
"PATH=${py_path}" |
| 277 |
"SASLPASSWD=${CyrusSASL_Saslpasswd_EXECUTABLE}" |
| 278 |
"SWIG=${SWIG_EXECUTABLE}" |
| 279 |
"TOXENV=${TOX_ENVLIST}" |
| 280 |
"PY_TEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/tests" |
| 281 |
COMMAND ${Python_EXECUTABLE} -m tox) |
| 282 |
set_tests_properties(python-tox-test |
| 283 |
PROPERTIES |
| 284 |
PASS_REGULAR_EXPRESSION "Totals: .* ignored, 0 failed" |
| 285 |
FAIL_REGULAR_EXPRESSION "ERROR:.*commands failed") |
| 286 |
endif () |
| 287 |
endif (ENABLE_TOX_TEST) |
| 288 |
endif (NOT TOX_MODULE_FOUND) |