microsoft/onnxruntime-extensions

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
9edf572de9b3e5eb261ca06060e6b2e4ab4012df

Branches

Tags

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

Clone

HTTPS

Download ZIP

cmake/ext_python.cmake

53lines · modecode

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