forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
143 lines (123 loc) · 5.14 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
#
# Define proper package name
#
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import wheel.vendored.packaging.tags as tags ; print(f'{tags.interpreter_name()}{tags.interpreter_version()}')"
OUTPUT_VARIABLE PYTHON_TAG OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import wheel.bdist_wheel ; print(f'{wheel.bdist_wheel.get_abi_tag()}')"
OUTPUT_VARIABLE ABI_TAG OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import wheel.vendored.packaging.tags as tags ; print(f'{next(tags.platform_tags())}')"
OUTPUT_VARIABLE PLATFORM_TAG OUTPUT_STRIP_TRAILING_WHITESPACE)
# defines wheel architecture part of `PLATFORM_TAG`
macro(_ov_platform_arch)
if(AARCH64)
if(APPLE)
set(_arch "arm64")
else()
set(_arch "aarch64")
endif()
elseif(UNIVERSAL2)
set(_arch "universal2")
elseif(ARM)
set(_arch "armvl7")
elseif(X86_64)
set(_arch "x86_64")
elseif(X86)
set(_arch "i686")
elseif(RISCV64)
set(_arch "riscv64")
else()
message(FATAL_ERROR "Unknown architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
endmacro()
# For macOS and Linux `PLATFORM_TAG` is not always correctly detected
# So, we need to add our-own post-processing
if(APPLE)
_ov_platform_arch()
if(CMAKE_OSX_DEPLOYMENT_TARGET)
set(_macos_target_version "${CMAKE_OSX_DEPLOYMENT_TARGET}")
if(_macos_target_version MATCHES "^1[0-9]$")
set(_macos_target_version "${CMAKE_OSX_DEPLOYMENT_TARGET}.0")
endif()
string(REPLACE "." "_" _macos_target_version "${_macos_target_version}")
else()
string(REGEX MATCH "1[0-9]_[0-9]+" _macos_target_version ${PLATFORM_TAG})
endif()
# common platform tag looks like macosx_<macos major>_<macos minor>_<arch>
if(_arch AND _macos_target_version)
set(PLATFORM_TAG "macosx_${_macos_target_version}_${_arch}")
endif()
elseif(LINUX)
_ov_platform_arch()
string(REPLACE "." "_" _ov_glibc_version "${OV_GLIBC_VERSION}")
set(manylinux "manylinux_${_ov_glibc_version}")
# convert to well-known formats according to PEP 600
if(manylinux STREQUAL "manylinux_2_5")
set(manylinux "manylinux1")
elseif(manylinux STREQUAL "manylinux_2_12")
set(manylinux "manylinux2010")
elseif(manylinux STREQUAL "manylinux_2_17")
set(manylinux "manylinux2014")
endif()
set(PLATFORM_TAG "${manylinux}_${_arch}")
endif()
set(openvino_wheel_name "openvino-${WHEEL_VERSION}-${WHEEL_BUILD}-${PYTHON_TAG}-${ABI_TAG}-${PLATFORM_TAG}.whl")
set(openvino_wheels_output_dir "${CMAKE_BINARY_DIR}/wheels")
set(openvino_wheel_path "${openvino_wheels_output_dir}/${openvino_wheel_name}")
#
# create target for openvino.wheel
#
execute_process(COMMAND ${Python3_EXECUTABLE} -m pip --version
OUTPUT_VARIABLE pip_version OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "pip[ ]+([\\.0-9]*)" pip_version "${pip_version}")
set(pip_version ${CMAKE_MATCH_1})
if(pip_version VERSION_GREATER_EQUAL 22.0)
set(wheel_build_command
${Python3_EXECUTABLE} -m pip wheel
--no-deps
--wheel-dir ${openvino_wheels_output_dir}
# --verbose
--build-option --build-number=${WHEEL_BUILD}
--build-option --plat-name=${PLATFORM_TAG}
"${CMAKE_CURRENT_SOURCE_DIR}")
else()
set(wheel_build_command
${Python3_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/setup.py"
--quiet
--no-user-cfg
bdist_wheel
--dist-dir ${openvino_wheels_output_dir}
--build-number=${WHEEL_BUILD}
--plat-name=${PLATFORM_TAG})
endif()
add_custom_command(OUTPUT ${openvino_wheel_path}
COMMAND ${setup_py_env}
${wheel_build_command}
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_CURRENT_SOURCE_DIR}/build_${pyversion}"
DEPENDS ${ov_setup_py_deps}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Building Python wheel ${openvino_wheel_name}"
VERBATIM)
set(fdupes_report ${CMAKE_CURRENT_BINARY_DIR}/fdupes_report.txt)
add_custom_command(OUTPUT "${fdupes_report}"
COMMAND ${CMAKE_COMMAND}
-D Python3_EXECUTABLE=${Python3_EXECUTABLE}
-D WORKING_DIRECTORY=${CMAKE_CURRENT_BINARY_DIR}
-D WHEEL_VERSION=${WHEEL_VERSION}
-D PACKAGE_FILE=${openvino_wheel_path}
-D REPORT_FILE=${fdupes_report}
-D CMAKE_SHARED_LIBRARY_SUFFIX=${CMAKE_SHARED_LIBRARY_SUFFIX}
-P "${CMAKE_CURRENT_SOURCE_DIR}/fdupes_check.cmake"
DEPENDS "${openvino_wheel_path}"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "Run 'fdupes' checks for wheel ${openvino_wheel_name}"
VERBATIM)
add_custom_target(ie_wheel ALL DEPENDS ${openvino_wheel_path} ${fdupes_report})
# install
ov_cpack_add_component(${OV_CPACK_COMP_PYTHON_WHEELS} HIDDEN)
install(FILES ${openvino_wheel_path}
DESTINATION ${OV_CPACK_WHEELSDIR}
COMPONENT ${OV_CPACK_COMP_PYTHON_WHEELS}
${OV_CPACK_COMP_PYTHON_WHEELS_EXCLUDE_ALL})