forked from intel/ad-rss-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython-binding.cmake
92 lines (79 loc) · 3.5 KB
/
python-binding.cmake
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
# ----------------- BEGIN LICENSE BLOCK ---------------------------------
#
# Copyright (C) 2020 Intel Corporation
#
# ----------------- END LICENSE BLOCK -----------------------------------
include(CMakeDependentOption)
option(BUILD_PYTHON_BINDING "Build python binding" OFF)
list(APPEND TARGET_COMPILE_OPTIONS $<$<BOOL:${BUILD_PYTHON_BINDING}>:-Wno-sign-conversion -Wno-conversion>)
set(PYTHON_WRAPPER_HELPER_DIR ${CMAKE_CURRENT_LIST_DIR}/python)
function(generate_python_binding_source_code WORKING_DIR)
message(STATUS "Generating python binding source code at ${WORKING_DIR}" )
configure_file(${PYTHON_WRAPPER_HELPER_DIR}/python_wrapper_helper.py.in python_wrapper_helper.py @ONLY)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} generate_python_lib.py
WORKING_DIRECTORY ${WORKING_DIR}
RESULT_VARIABLE GENERATE_PYTHON_RESULT
OUTPUT_VARIABLE GENERATE_PYTHON_STDOUT_STDERR
ERROR_VARIABLE GENERATE_PYTHON_STDOUT_STDERR
)
set(message_level STATUS)
if ( ${GENERATE_PYTHON_RESULT} )
set(message_level WARNING)
endif()
message(${message_level} "Generator call: ${PYTHON_EXECUTABLE} generate_python_lib.py")
message(${message_level} "Generating result: ${GENERATE_PYTHON_RESULT}")
message(${message_level} "Generator output: ${GENERATE_PYTHON_STDOUT_STDERR}")
endfunction()
function(find_python_binding_packages)
if ("${PYTHON_BINDING_VERSION}" STREQUAL "")
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
else()
find_package(PythonInterp EXACT "${PYTHON_BINDING_VERSION}" REQUIRED)
find_package(PythonLibs EXACT "${PYTHON_BINDING_VERSION}" REQUIRED)
endif()
find_package(Boost REQUIRED)
if(${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION} VERSION_GREATER 1.66)
set(BOOST_PYTHON_COMPONENT python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR})
else()
set(BOOST_PYTHON_COMPONENT python-py${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR})
endif()
find_package(Boost COMPONENTS REQUIRED ${BOOST_PYTHON_COMPONENT})
set(PYTHON_BINDING_NAME
"python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}"
PARENT_SCOPE)
set(PYTHON_BINDING_FOLDER_NAME
"python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}"
PARENT_SCOPE)
set(PYTHON_BINDING_PACKAGE_INCLUDE_DIRS
${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
PARENT_SCOPE)
set(PYTHON_BINDING_PACKAGE_LIBRARIES
Boost::${BOOST_PYTHON_COMPONENT}
${PYTHON_LIBRARIES}
PARENT_SCOPE)
endfunction()
function(get_python_test_environment)
set(TEST_LD_LIBRARY_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
set(TEST_PYTHONPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${PYTHON_BINDING_FOLDER_NAME}/site-packages")
foreach(dep ${ARGN})
get_target_property(dep_configurations ${dep} IMPORTED_CONFIGURATIONS)
set(TEST_${dep}_LOCATION False)
foreach(dep_config ${dep_configurations})
get_target_property(dep_location ${dep} IMPORTED_LOCATION_${dep_config})
if(dep_location)
get_filename_component(TEST_${dep}_LOCATION ${dep_location} PATH)
break()
endif()
endforeach()
if(TEST_${dep}_LOCATION)
set(TEST_LD_LIBRARY_PATH "${LD_LIBRARY_PATH}:${TEST_${dep}_LOCATION}")
set(TEST_PYTHONPATH "${TEST_PYTHONPATH}:${TEST_${dep}_LOCATION}/${PYTHON_BINDING_FOLDER_NAME}/site-packages")
else()
message(WARNING "Failed to query mandatory location of dependency ${dep}")
endif()
endforeach()
set(PYTHON_TEST_ENVIRONMENT "PYTHONPATH=${TEST_PYTHONPATH}; LD_LIBRARY_PATH=${TEST_LD_LIBRARY_PATH}" PARENT_SCOPE)
endfunction()