blob: a16c6128b2397e634a2dc4b2b6e9f2d4b9a42549 [file] [log] [blame]
Kshitij Sisodiaf9efe0d2022-09-30 16:42:50 +01001#
Mikael Olsson18cfaf02023-04-18 12:06:54 +02002# SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
Kshitij Sisodiaf9efe0d2022-09-30 16:42:50 +01003#
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
19find_package(PythonInterp 3.5 REQUIRED)
20if(NOT ${PYTHONINTERP_FOUND})
21 message(FATAL_ERROR "Python 3.5 or greater is required to build python driver, but was not found")
22endif()
23
24find_package(SWIG 3.0.12 REQUIRED)
25if(NOT ${SWIG_FOUND})
26 message(FATAL_ERROR "SWIG 3.0.12 or greater is required to build python driver, but was not found")
27endif()
28
29set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
30set(SWIG_GENERATE "${CMAKE_CURRENT_BINARY_DIR}/swig_generate.py")
31set(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
35set(DRIVER_ENV ETHOS_U_DRIVER_INCLUDE="${PROJECT_SOURCE_DIR}/include"
Mikael Olssone7461c72023-04-18 12:23:18 +020036 ETHOS_U_DRIVER_LIB="${PROJECT_BINARY_DIR}")
Kshitij Sisodiaf9efe0d2022-09-30 16:42:50 +010037
38# common step - generates swig wrappers
39add_custom_command(OUTPUT ${OUT_WRAP}
40 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_CURRENT_BINARY_DIR}
Mikael Olsson18cfaf02023-04-18 12:06:54 +020041 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../../LICENSE-APACHE-2.0.txt ${CMAKE_CURRENT_BINARY_DIR}/LICENSE
Kshitij Sisodiaf9efe0d2022-09-30 16:42:50 +010042 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
52if(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})
59endif()
60# wheel package
61if(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})
74endif()
75add_custom_target(pydriver ALL DEPENDS ${OUT_WRAP} ${OUT_SRC} ${OUT_WHL})