Kshitij Sisodia | f9efe0d | 2022-09-30 16:42:50 +0100 | [diff] [blame] | 1 | # |
Mikael Olsson | 18cfaf0 | 2023-04-18 12:06:54 +0200 | [diff] [blame] | 2 | # SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates <open-source-office@arm.com> |
Kshitij Sisodia | f9efe0d | 2022-09-30 16:42:50 +0100 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the License); you may |
| 7 | # not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | |
| 19 | find_package(PythonInterp 3.5 REQUIRED) |
| 20 | if(NOT ${PYTHONINTERP_FOUND}) |
| 21 | message(FATAL_ERROR "Python 3.5 or greater is required to build python driver, but was not found") |
| 22 | endif() |
| 23 | |
| 24 | find_package(SWIG 3.0.12 REQUIRED) |
| 25 | if(NOT ${SWIG_FOUND}) |
| 26 | message(FATAL_ERROR "SWIG 3.0.12 or greater is required to build python driver, but was not found") |
| 27 | endif() |
| 28 | |
| 29 | set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py") |
| 30 | set(SWIG_GENERATE "${CMAKE_CURRENT_BINARY_DIR}/swig_generate.py") |
| 31 | set(OUT_WRAP "${CMAKE_CURRENT_BINARY_DIR}/pydriver.wrap.timestamp") |
| 32 | |
| 33 | # local env variables passed down to the python scripts |
| 34 | # scripts can thus be used standalone |
| 35 | set(DRIVER_ENV ETHOS_U_DRIVER_INCLUDE="${PROJECT_SOURCE_DIR}/include" |
Mikael Olsson | e7461c7 | 2023-04-18 12:23:18 +0200 | [diff] [blame^] | 36 | ETHOS_U_DRIVER_LIB="${PROJECT_BINARY_DIR}") |
Kshitij Sisodia | f9efe0d | 2022-09-30 16:42:50 +0100 | [diff] [blame] | 37 | |
| 38 | # common step - generates swig wrappers |
| 39 | add_custom_command(OUTPUT ${OUT_WRAP} |
| 40 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_CURRENT_BINARY_DIR} |
Mikael Olsson | 18cfaf0 | 2023-04-18 12:06:54 +0200 | [diff] [blame] | 41 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../../LICENSE-APACHE-2.0.txt ${CMAKE_CURRENT_BINARY_DIR}/LICENSE |
Kshitij Sisodia | f9efe0d | 2022-09-30 16:42:50 +0100 | [diff] [blame] | 42 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/swig_generate.py ${CMAKE_CURRENT_BINARY_DIR} |
| 43 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/setup.py ${CMAKE_CURRENT_BINARY_DIR} |
| 44 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src |
| 45 | COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "Clearing Python build ..." |
| 46 | COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} --quiet clean --all |
| 47 | COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "Generating SWIG wrappers ..." |
| 48 | COMMAND ${PYTHON_EXECUTABLE} ${SWIG_GENERATE} |
| 49 | DEPENDS ethosu) |
| 50 | |
| 51 | # source package |
| 52 | if(BUILD_PYTHON_SRC) |
| 53 | set(OUT_SRC "${CMAKE_CURRENT_BINARY_DIR}/pydriver.src.timestamp") |
| 54 | add_custom_command(OUTPUT ${OUT_SRC} |
| 55 | COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "Building Python source package ..." |
| 56 | COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} sdist |
| 57 | COMMAND ${CMAKE_COMMAND} -E touch ${OUT_SRC} |
| 58 | DEPENDS ${OUT_WRAP}) |
| 59 | endif() |
| 60 | # wheel package |
| 61 | if(BUILD_PYTHON_WHL) |
| 62 | |
| 63 | find_package(PythonLibs 3.5 REQUIRED) |
| 64 | if(NOT ${PYTHONLIBS_FOUND}) |
| 65 | message(FATAL_ERROR "Python 3.5 or greater development libraries were not found.") |
| 66 | endif() |
| 67 | |
| 68 | set(OUT_WHL "${CMAKE_CURRENT_BINARY_DIR}/pydriver.whl.timestamp") |
| 69 | add_custom_command(OUTPUT ${OUT_WHL} |
| 70 | COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "Building Python binary package ..." |
| 71 | COMMAND ${CMAKE_COMMAND} -E env ${DRIVER_ENV} CXX=${CMAKE_CXX_COMPILER} CC=${CMAKE_C_COMPILER} ${PYTHON_EXECUTABLE} ${SETUP_PY} bdist_wheel |
| 72 | COMMAND ${CMAKE_COMMAND} -E touch ${OUT_WHL} |
| 73 | DEPENDS ${OUT_WRAP}) |
| 74 | endif() |
| 75 | add_custom_target(pydriver ALL DEPENDS ${OUT_WRAP} ${OUT_SRC} ${OUT_WHL}) |