microsoft/onnxruntime-extensions

Public

mirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
85ffb9416980acac66a5151e84c891c3aa098b9b

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

cmake/ext_python.cmake

50lines · modecode

1block(PROPAGATE Python3_FOUND)
2 set(Python3_FIND_REGISTRY NEVER)
3 # if we don't set this to NEVER (or possibly LAST) the builds of the wheel for different python versions will fail
4 # as it will find the system python version first and not the correct python version for the wheel.
5 set(Python3_FIND_FRAMEWORK NEVER)
6 find_package(Python3 COMPONENTS Interpreter Development.Module)
7endblock()
8
9if (NOT Python3_FOUND)
10 message(FATAL_ERROR "Python3 not found!")
11endif()
12
13file(GLOB TARGET_SRC_PYOPS "pyop/pyfunc.cc" "pyop/*.h" "shared/*.cc")
14if (OCOS_ENABLE_C_API)
15 list(APPEND TARGET_SRC_PYOPS "pyop/py_c_api.cc")
16endif()
17if (WIN32)
18 list(APPEND TARGET_SRC_PYOPS "pyop/extensions_pydll.def")
19endif()
20
21add_library(extensions_pydll SHARED ${TARGET_SRC_PYOPS} ${shared_TARGET_LIB_SRC})
22standardize_output_folder(extensions_pydll)
23list(APPEND OCOS_COMPILE_DEFINITIONS PYTHON_OP_SUPPORT)
24target_compile_definitions(extensions_pydll PRIVATE ${OCOS_COMPILE_DEFINITIONS})
25
26message(STATUS "Fetch pybind11")
27include(pybind11)
28target_include_directories(extensions_pydll PRIVATE
29 ${pybind11_INCLUDE_DIRS}
30 $<TARGET_PROPERTY:Python3::Module,INTERFACE_INCLUDE_DIRECTORIES>
31 $<TARGET_PROPERTY:ocos_operators,INTERFACE_INCLUDE_DIRECTORIES>)
32
33target_compile_definitions(extensions_pydll PRIVATE
34 $<TARGET_PROPERTY:Python3::Module,INTERFACE_COMPILE_DEFINITIONS>)
35
36target_link_libraries(extensions_pydll PRIVATE Python3::Module ocos_operators)
37
38if(OCOS_PYTHON_MODULE_PATH)
39 get_filename_component(OCOS_PYTHON_MODULE_NAME ${OCOS_PYTHON_MODULE_PATH} NAME)
40 if(NOT WIN32)
41 set_target_properties(extensions_pydll PROPERTIES
42 LIBRARY_OUTPUT_NAME ${OCOS_PYTHON_MODULE_NAME}
43 PREFIX ""
44 SUFFIX "")
45 endif()
46
47 add_custom_command(TARGET extensions_pydll POST_BUILD
48 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:extensions_pydll> ${OCOS_PYTHON_MODULE_PATH}
49 COMMENT "Copying $<TARGET_FILE:extensions_pydll> to ${OCOS_PYTHON_MODULE_PATH}")
50endif()
51