-
Notifications
You must be signed in to change notification settings - Fork 537
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
130 lines (109 loc) · 4.96 KB
/
CMakeLists.txt
File metadata and controls
130 lines (109 loc) · 4.96 KB
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
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2020-2021 Xilinx, Inc. All rights reserved.
#
if( NOT WIN32)
# find_package(PythonLibs is depracted as of cmake 3.12.
if (CMAKE_VERSION VERSION_LESS "3.12")
find_package(PythonLibs 3.4.0 REQUIRED)
if (PythonLibs_FOUND)
message("-- Python libs version: ${PYTHONLIBS_VERSION_STRING}")
message("-- PYTHON_INCLUDE_PATH ${PYTHON_INCLUDE_PATH}")
string(REPLACE "." ";" PYTHONLIBS_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
list(GET PYTHONLIBS_VERSION_LIST 0 PYTHONLIBS_VERSION_MAJOR)
list(GET PYTHONLIBS_VERSION_LIST 1 PYTHONLIBS_VERSION_MINOR)
endif(PythonLibs_FOUND)
set(HAS_PYTHON ${PythonLibs_FOUND})
else()
if (DEFINED ENV{VIRTUAL_ENV})
# Virtual environment detected, use its Python
set(Python3_EXECUTABLE $ENV{VIRTUAL_ENV}/bin/python3)
message(STATUS "Virtual environment detected, using Python3: ${Python3_EXECUTABLE}")
else()
# No virtual environment, use system Python3
# In alma 8.10 python3.11 comes as a dependency but still pybind11 is installed to default python3.
set(Python3_EXECUTABLE /usr/bin/python3)
endif()
find_package(Python3 COMPONENTS Development Interpreter)
if (Python3_FOUND)
message("-- Python libs version: ${Python3_VERSION}")
message("-- PYTHON_INCLUDE_PATH ${Python3_INCLUDE_DIRS}")
message("-- Python3_SITEARCH ${Python3_SITEARCH}")
set(PYTHONLIBS_VERSION_MAJOR ${Python3_VERSION_MAJOR})
set(PYTHONLIBS_VERSION_MINOR ${Python3_VERSION_MINOR})
endif(Python3_FOUND)
set(HAS_PYTHON ${Python3_FOUND})
endif(CMAKE_VERSION VERSION_LESS "3.12")
if (HAS_PYTHON)
if (${LINUX_FLAVOR} MATCHES "^(ubuntu|debian)")
SET(PKGDIR "dist-packages")
elseif (${LINUX_FLAVOR} MATCHES "^(rhel|centos|amzn|fedora|sles|almalinux|rocky)")
SET(PKGDIR "site-packages")
endif(${LINUX_FLAVOR} MATCHES "^(ubuntu|debian)")
find_package(pybind11 2.6.0 REQUIRED PATHS "$ENV{VIRTUAL_ENV}/lib/python${PYTHONLIBS_VERSION_MAJOR}.${PYTHONLIBS_VERSION_MINOR}/${PKGDIR}/pybind11" "/usr/local/lib/python${PYTHONLIBS_VERSION_MAJOR}.${PYTHONLIBS_VERSION_MINOR}/${PKGDIR}/pybind11" "/usr/lib/python${PYTHONLIBS_VERSION_MAJOR}.${PYTHONLIBS_VERSION_MINOR}/${PKGDIR}/pybind11")
endif(HAS_PYTHON)
if (pybind11_FOUND)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
pybind11_add_module(pyxrt src/pyxrt.cpp)
target_link_libraries(pyxrt PRIVATE xrt_coreutil uuid pthread)
if (CMAKE_INSTALL_PREFIX STREQUAL "/usr"
OR CMAKE_INSTALL_PREFIX STREQUAL "/usr/local")
set (XRT_INSTALL_PYTHON_DIR ${Python3_SITEARCH})
endif()
install(TARGETS pyxrt
EXPORT xrt-targets
LIBRARY DESTINATION ${XRT_INSTALL_PYTHON_DIR} COMPONENT ${XRT_BASE_COMPONENT}
)
# Install type stub file for IDE autocompletion and type checking
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pyxrt.pyi
DESTINATION ${XRT_INSTALL_PYTHON_DIR} COMPONENT ${XRT_BASE_COMPONENT}
)
else(pybind11_FOUND)
message(WARNING "-- pybind11 or python3 libs not found, pybind11 support disabled")
endif(pybind11_FOUND)
else()
# = WINDOWS ===================================================================
find_package(Python3 COMPONENTS Development Interpreter)
if (Python3_FOUND)
message("-- Python libs version: ${Python3_VERSION}")
message("-- PYTHON_INCLUDE_PATH ${Python3_INCLUDE_DIRS}")
set(PYTHON_INCLUDE_PATH ${Python3_INCLUDE_DIRS})
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import sys, pathlib; print((pathlib.Path(sys.base_prefix)/'libs').as_posix())"
OUTPUT_VARIABLE PYTHON_LIBDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(PYTHONLIBS_VERSION_MAJOR ${Python3_VERSION_MAJOR})
set(PYTHONLIBS_VERSION_MINOR ${Python3_VERSION_MINOR})
endif(Python3_FOUND)
set(HAS_PYTHON ${Python3_FOUND})
if (HAS_PYTHON)
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import os, pathlib, pybind11; print(pathlib.Path(os.path.dirname(pybind11.__file__)).as_posix())"
RESULT_VARIABLE pybind_found
OUTPUT_VARIABLE PKGDIR
ERROR_VARIABLE pybind_error
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(pybind_found EQUAL 0)
message("-- pybind11 location: ${PKGDIR}")
find_package(pybind11 2.10.4 REQUIRED PATHS "${PKGDIR}")
else()
message(WARNING "-- Failed to import pybind11. Error: ${pybind_error}")
endif()
endif(HAS_PYTHON)
if (pybind11_FOUND)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
pybind11_add_module(pyxrt src/pyxrt.cpp)
target_link_libraries(pyxrt PRIVATE xrt_coreutil uuid)
target_link_directories(pyxrt PRIVATE "${PYTHON_LIBDIR}")
set_target_properties(pyxrt PROPERTIES SUFFIX ".pyd")
install(TARGETS pyxrt
EXPORT xrt-targets
LIBRARY DESTINATION ${XRT_INSTALL_PYTHON_DIR} COMPONENT ${XRT_BASE_COMPONENT}
)
# Install type stub file for IDE autocompletion and type checking
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pyxrt.pyi
DESTINATION ${XRT_INSTALL_PYTHON_DIR} COMPONENT ${XRT_BASE_COMPONENT}
)
else(pybind11_FOUND)
message(WARNING "-- pybind11 or python3 libs not found, pybind11 support disabled")
endif(pybind11_FOUND)
endif()