microsoft/onnxruntime-extensions
Publicmirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable
cmake/ext_python.cmake
50lines · modecode
| 1 | block(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) |
| 7 | endblock() |
| 8 | |
| 9 | if (NOT Python3_FOUND) |
| 10 | message(FATAL_ERROR "Python3 not found!") |
| 11 | endif() |
| 12 | |
| 13 | file(GLOB TARGET_SRC_PYOPS "pyop/pyfunc.cc" "pyop/*.h" "shared/*.cc") |
| 14 | if (OCOS_ENABLE_C_API) |
| 15 | list(APPEND TARGET_SRC_PYOPS "pyop/py_c_api.cc") |
| 16 | endif() |
| 17 | if (WIN32) |
| 18 | list(APPEND TARGET_SRC_PYOPS "pyop/extensions_pydll.def") |
| 19 | endif() |
| 20 | |
| 21 | add_library(extensions_pydll SHARED ${TARGET_SRC_PYOPS} ${shared_TARGET_LIB_SRC}) |
| 22 | standardize_output_folder(extensions_pydll) |
| 23 | list(APPEND OCOS_COMPILE_DEFINITIONS PYTHON_OP_SUPPORT) |
| 24 | target_compile_definitions(extensions_pydll PRIVATE ${OCOS_COMPILE_DEFINITIONS}) |
| 25 | |
| 26 | message(STATUS "Fetch pybind11") |
| 27 | include(pybind11) |
| 28 | target_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 | |
| 33 | target_compile_definitions(extensions_pydll PRIVATE |
| 34 | $<TARGET_PROPERTY:Python3::Module,INTERFACE_COMPILE_DEFINITIONS>) |
| 35 | |
| 36 | target_link_libraries(extensions_pydll PRIVATE Python3::Module ocos_operators) |
| 37 | |
| 38 | if(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}") |
| 50 | endif() |
| 51 | |