Changeset View
Changeset View
Standalone View
Standalone View
build_files/cmake/macros.cmake
| Context not available. | |||||
| endif() | endif() | ||||
| endif() | endif() | ||||
| ENDMACRO() | ENDMACRO() | ||||
| # creates a name.so which can be imported as a python module. | |||||
| macro(blender_add_python_module | |||||
| name | |||||
| local_dir | |||||
| sources | |||||
| ) | |||||
campbellbarton: This should take `SRC, INC, INC_SYS` arguments, since its possible the module has own includes. | |||||
| set(target_name module_${name}) | |||||
campbellbartonUnsubmitted Done Inline Actionsmodule is too generic, suggest cpython_module_ or py_capi_module_ prefix. campbellbarton: `module` is too generic, suggest `cpython_module_` or `py_capi_module_` prefix. | |||||
| set(INC | |||||
| ${PYTHON_INC} | |||||
| ) | |||||
| set(INC_SYS | |||||
| ${PYTHON_INCLUDE_DIRS} | |||||
| ) | |||||
| blender_include_dirs("${INC}") | |||||
| blender_include_dirs_sys("${INC_SYS}") | |||||
| LINK_DIRECTORIES(${LIBDIR}/python/lib) | |||||
campbellbartonUnsubmitted Done Inline ActionsCan't PYTHON_LIBPATH be used here? campbellbarton: Can't `PYTHON_LIBPATH` be used here? | |||||
| add_library(${target_name} MODULE "${sources}") | |||||
| set_target_properties( | |||||
| ${target_name} | |||||
| PROPERTIES | |||||
| PREFIX "" | |||||
| OUTPUT_NAME ${name} | |||||
| DEBUG_POSTFIX _d | |||||
| LINKER_LANGUAGE C | |||||
| COMPILE_OPTIONS "/Z7" #embeds debugging info directly into the generated object files (PDB) | |||||
| ) | |||||
| if(WIN32) | |||||
| # python modules use this | |||||
| set_target_properties( | |||||
| ${target_name} | |||||
| PROPERTIES | |||||
| SUFFIX ".pyd" | |||||
| ) | |||||
| endif() | |||||
| # link | |||||
| string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION}) | |||||
| target_link_libraries(${target_name} optimized python${_PYTHON_VERSION_NO_DOTS}.dll) | |||||
| target_link_libraries(${target_name} debug python${_PYTHON_VERSION_NO_DOTS}_d.dll) | |||||
| # ----------------------------------------------------------------------------- | |||||
| # installation | |||||
| string(REPLACE "${CMAKE_SOURCE_DIR}/release" "${CMAKE_INSTALL_PREFIX}/${BLENDER_VERSION}" PARENT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | |||||
campbellbartonUnsubmitted Done Inline ActionsTypically you dont need to do this kind of manipulation for installation. Check how this is done elsewhere. campbellbarton: Typically you dont need to do this kind of manipulation for installation.
It's also error prone… | |||||
| get_filename_component(PARENT_DIR ${PARENT_DIR} DIRECTORY) | |||||
| install( | |||||
| TARGETS ${target_name} | |||||
| LIBRARY | |||||
| DESTINATION ${PARENT_DIR}/${local_dir} | |||||
| ) | |||||
| string(LENGTH "${PYTHON_MODULE_EXCLUDE}" excludelen) | |||||
campbellbartonUnsubmitted Done Inline ActionsUse if(NOT DEFINED ...) campbellbarton: Use `if(NOT DEFINED ...)` | |||||
| if (${excludelen} GREATER 0) | |||||
| set(PYTHON_MODULE_EXCLUDE "${PYTHON_MODULE_EXCLUDE}|" CACHE INTERNAL "PYTHON_MODULE_EXCLUDE") | |||||
| endif() | |||||
| set(PYTHON_MODULE_EXCLUDE "${PYTHON_MODULE_EXCLUDE}${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "PYTHON_MODULE_EXCLUDE") | |||||
| #message("macro PYTHON EXCLUDE = >${PYTHON_MODULE_EXCLUDE}<") | |||||
| endmacro(blender_add_python_module) | |||||
| Context not available. | |||||
This should take SRC, INC, INC_SYS arguments, since its possible the module has own includes.
The macro can include ${PYTHON_INCLUDE_DIRS}, ${PYTHON_INC} too.