xref: /oneTBB/python/CMakeLists.txt (revision 7196bb4f)
1# Copyright (c) 2020-2021 Intel Corporation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15find_package(PythonInterp 3.5 REQUIRED)
16
17set(PYTHON_BUILD_WORK_DIR .)
18
19add_custom_target(
20    python_copy
21    COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/tbb ${PYTHON_BUILD_WORK_DIR}/tbb
22    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/TBB.py ${PYTHON_BUILD_WORK_DIR}
23    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/setup.py ${PYTHON_BUILD_WORK_DIR}
24)
25
26# Python build requires path to TBB headers
27get_target_property(TBB_INCLUDES tbb INTERFACE_INCLUDE_DIRECTORIES)
28foreach(dir ${TBB_INCLUDES})
29    if (${dir} MATCHES "<BUILD_INTERFACE:" OR TBB_FOUND)
30        set(TBB4PY_INCLUDE_STRING "-I${dir} ${TBB4PY_INCLUDE_STRING}")
31    endif()
32endforeach()
33string(STRIP "${TBB4PY_INCLUDE_STRING}" TBB4PY_INCLUDE_STRING)
34
35add_custom_target(
36    python_build
37    ALL
38    DEPENDS tbb python_copy
39    COMMAND
40    ${PYTHON_EXECUTABLE} ${PYTHON_BUILD_WORK_DIR}/setup.py
41        build -b${PYTHON_BUILD_WORK_DIR}
42        build_ext ${TBB4PY_INCLUDE_STRING} -L$<TARGET_FILE_DIR:TBB::tbb>
43        install --prefix ${PYTHON_BUILD_WORK_DIR}/build -f
44    COMMENT "Build and install to work directory the oneTBB Python module"
45)
46
47add_test(NAME python_test
48         COMMAND ${CMAKE_COMMAND}
49                 -DTBB_BINARIES_PATH=$<TARGET_FILE_DIR:TBB::tbb>
50                 -DPYTHON_MODULE_BUILD_PATH=${PYTHON_BUILD_WORK_DIR}/build
51                 -P ${PROJECT_SOURCE_DIR}/cmake/python/test_launcher.cmake)
52
53install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PYTHON_BUILD_WORK_DIR}/build/
54        DESTINATION .
55        COMPONENT tbb4py)
56
57if (UNIX AND NOT APPLE)
58    add_subdirectory(rml)
59    add_dependencies(python_build irml)
60endif()
61