• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright 2020 NXP
3# SPDX-License-Identifier: MIT
4#
5set(SETUP_PY_IN         "${CMAKE_CURRENT_SOURCE_DIR}/setup.py")
6set(SETUP_PY            "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
7set(SWIG_GENERATE_IN    "${CMAKE_CURRENT_SOURCE_DIR}/swig_generate.py")
8set(SWIG_GENERATE       "${CMAKE_CURRENT_BINARY_DIR}/swig_generate.py")
9set(OUT_WRAP            "${CMAKE_CURRENT_BINARY_DIR}/pyarmnn.wrap.timestamp")
10
11configure_file(${SETUP_PY_IN} ${SETUP_PY} COPYONLY)
12configure_file(${SWIG_GENERATE_IN} ${SWIG_GENERATE} COPYONLY)
13
14# local env variables passed down to the python scripts
15# scripts can thus be used standalone
16set(ARMNN_ENV ARMNN_INCLUDE="${PROJECT_SOURCE_DIR}/profiling:${PROJECT_SOURCE_DIR}/profiling/common/include:${PROJECT_SOURCE_DIR}/profiling/client/include:${PROJECT_SOURCE_DIR}/include"
17              ARMNN_LIB=${PROJECT_BINARY_DIR}
18              SWIG_EXECUTABLE=${SWIG_EXECUTABLE})
19
20# common step - generates swig wrappers and builds the lib
21add_custom_command(OUTPUT ${OUT_WRAP}
22                   COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_CURRENT_BINARY_DIR}
23                   COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE ${CMAKE_CURRENT_BINARY_DIR}
24                   COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src
25                   COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/test ${CMAKE_CURRENT_BINARY_DIR}/test
26                   COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "Clearing Python build ..."
27                   COMMAND ${Python3_EXECUTABLE} ${SETUP_PY} --quiet clean --all
28                   COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "Generating SWIG wrappers ..."
29                   COMMAND ${CMAKE_COMMAND} -E env ${ARMNN_ENV} ${Python3_EXECUTABLE} ${SWIG_GENERATE}
30                   COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "Building Python extensions ..."
31                   COMMAND ${CMAKE_COMMAND} -E env ${ARMNN_ENV} ${Python3_EXECUTABLE} ${SETUP_PY} --quiet build_ext --inplace
32                   COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src/pyarmnn/_generated ${CMAKE_CURRENT_BINARY_DIR}/src/pyarmnn/_generated
33                   COMMAND ${CMAKE_COMMAND} -E touch ${OUT_WRAP}
34                   DEPENDS armnn)
35
36# source package
37if(BUILD_PYTHON_SRC)
38    set(OUT_SRC "${CMAKE_CURRENT_BINARY_DIR}/pyarmnn.src.timestamp")
39    add_custom_command(OUTPUT  ${OUT_SRC}
40                       COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "Building Python source package ..."
41                       COMMAND ${CMAKE_COMMAND} -E env ${ARMNN_ENV} ${Python3_EXECUTABLE} ${SETUP_PY} --quiet sdist
42                       COMMAND ${CMAKE_COMMAND} -E touch ${OUT_SRC}
43                       DEPENDS ${OUT_WRAP})
44endif()
45# wheel package
46if(BUILD_PYTHON_WHL)
47    set(OUT_WHL "${CMAKE_CURRENT_BINARY_DIR}/pyarmnn.whl.timestamp")
48    add_custom_command(OUTPUT  ${OUT_WHL}
49                       COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "Building Python binary package ..."
50                       COMMAND ${CMAKE_COMMAND} -E env ${ARMNN_ENV} ${Python3_EXECUTABLE} ${SETUP_PY} --quiet bdist_wheel
51                       COMMAND ${CMAKE_COMMAND} -E touch ${OUT_WHL}
52                       DEPENDS ${OUT_WRAP})
53endif()
54add_custom_target(pyarmnn ALL DEPENDS ${OUT_WRAP} ${OUT_SRC} ${OUT_WHL})
55