mirror of
https://github.com/ceph/ceph
synced 2025-04-11 04:02:04 +00:00
* fix CYTHON_ADD_MODULE() macro. because python_add_module() offered by FindPythonLibs.cmake creates a target with name of ${name}, which conflicts with existing targets like "rbd" or "rados". so we can not reuse the name in ${name}.pyx. and instead, we should specify the target name explicitly. * add distutils_install_cython_module() function to build and install cython modules. * we can split build and install of cython module, but the install phase always tries to build the module. so keep it this way. will look at it later on. * move the variables initializations into the Distutils.cmake module. Signed-off-by: Kefu Chai <kchai@redhat.com>
74 lines
2.8 KiB
CMake
74 lines
2.8 KiB
CMake
function(distutils_install_module name)
|
|
if(DEFINED ENV{DESTDIR})
|
|
get_filename_component(debian_version /etc/debian_version ABSOLUTE)
|
|
if(EXISTS ${debian_version})
|
|
set(options "--install-layout=deb")
|
|
else()
|
|
set(options "--prefix=/usr")
|
|
endif()
|
|
endif()
|
|
|
|
set(py_srcs setup.py README.rst requirements.txt test-requirements.txt ${name})
|
|
foreach(src ${py_srcs})
|
|
list(APPEND py_clone ${CMAKE_CURRENT_BINARY_DIR}/${src})
|
|
add_custom_command(
|
|
OUTPUT ${src}
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${src}
|
|
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${src})
|
|
endforeach()
|
|
add_custom_target(${name}-clone ALL
|
|
DEPENDS ${py_clone})
|
|
install(CODE
|
|
"execute_process(COMMAND ${PYTHON_EXECUTABLE} setup.py install ${options} --root=$DESTDIR
|
|
WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}\")")
|
|
endfunction(distutils_install_module)
|
|
|
|
function(distutils_add_cython_module name src)
|
|
get_property(compiler_launcher GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
|
|
get_property(link_launcher GLOBAL PROPERTY RULE_LAUNCH_LINK)
|
|
set(PY_CC \"${compiler_launcher} ${CMAKE_C_COMPILER}\")
|
|
set(PY_CXX \"${compiler_launcher} ${CMAKE_CXX_COMPILER}\")
|
|
set(PY_LDSHARED \"${link_launcher} ${CMAKE_C_COMPILER} -shared\")
|
|
add_custom_target(${name} ALL
|
|
COMMAND
|
|
env
|
|
CC=${PY_CC}
|
|
CXX=${PY_CXX}
|
|
LDSHARED=${PY_LDSHARED}
|
|
OPT=\"-DNDEBUG -g -fwrapv -O2 -Wall\"
|
|
LDFLAGS=-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
|
|
CYTHON_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}
|
|
CFLAGS=\"-iquote ${CMAKE_SOURCE_DIR}/src/include\"
|
|
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py build --build-base ${CYTHON_MODULE_DIR} --verbose
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
DEPENDS ${src})
|
|
endfunction(distutils_add_cython_module)
|
|
|
|
function(distutils_install_cython_module name)
|
|
install(CODE "
|
|
set(options --prefix=/usr)
|
|
if(DEFINED ENV{DESTDIR})
|
|
if(EXISTS /etc/debian_version)
|
|
set(options --install-layout=deb)
|
|
endif()
|
|
set(root --root=\$ENV{DESTDIR})
|
|
else()
|
|
set(options \"--prefix=${CMAKE_INSTALL_PREFIX}\")
|
|
set(root --root=/)
|
|
endif()
|
|
execute_process(
|
|
COMMAND env
|
|
CYTHON_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}
|
|
CFLAGS=\"-iquote ${CMAKE_SOURCE_DIR}/src/include\"
|
|
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py
|
|
build --build-base ${CYTHON_MODULE_DIR} --verbose
|
|
install \${options} \${root} --verbose
|
|
--single-version-externally-managed --record /dev/null
|
|
WORKING_DIRECTORY \"${CMAKE_CURRENT_SOURCE_DIR}\"
|
|
RESULT_VARIABLE install_res)
|
|
if(NOT \"\${install_res}\" STREQUAL 0)
|
|
message(FATAL_ERROR \"Failed to build and install ${name} python module\")
|
|
endif()
|
|
")
|
|
endfunction(distutils_install_cython_module)
|