2016-06-01 17:50:21 +00:00
|
|
|
include(CMakeParseArguments)
|
2016-05-28 07:44:36 +00:00
|
|
|
|
2022-04-16 01:10:20 +00:00
|
|
|
# ensure that we are using the exact python version specified by
|
|
|
|
# 'WITH_PYTHON3', in case some included 3rd party libraries call
|
|
|
|
# 'find_package(Python3 ...) without specifying the exact version number. if
|
|
|
|
# the building host happens to have a higher version of python3, that version
|
|
|
|
# would be picked up instead by find_package(Python3). and that is not want we
|
|
|
|
# expect.
|
2022-04-20 22:31:21 +00:00
|
|
|
find_package(Python3 ${WITH_PYTHON3} EXACT
|
2022-04-16 01:10:20 +00:00
|
|
|
QUIET
|
|
|
|
REQUIRED
|
|
|
|
COMPONENTS Interpreter)
|
|
|
|
|
2016-06-01 17:50:21 +00:00
|
|
|
function(distutils_install_module name)
|
2017-07-20 20:54:37 +00:00
|
|
|
set(py_srcs setup.py README.rst requirements.txt test-requirements.txt bin ${name})
|
2016-05-28 07:44:36 +00:00
|
|
|
foreach(src ${py_srcs})
|
2017-07-20 20:54:37 +00:00
|
|
|
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${src})
|
|
|
|
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})
|
|
|
|
endif()
|
2016-05-28 07:44:36 +00:00
|
|
|
endforeach()
|
2019-07-26 07:35:59 +00:00
|
|
|
if(NOT TARGET ${name}-clone)
|
|
|
|
add_custom_target(${name}-clone ALL
|
|
|
|
DEPENDS ${py_clone})
|
|
|
|
endif()
|
2019-12-18 09:08:21 +00:00
|
|
|
cmake_parse_arguments(DU "" "INSTALL_SCRIPT" "" ${ARGN})
|
2016-06-01 17:50:21 +00:00
|
|
|
install(CODE "
|
2016-07-04 03:10:49 +00:00
|
|
|
set(options --prefix=${CMAKE_INSTALL_PREFIX})
|
2016-06-01 17:50:21 +00:00
|
|
|
if(DEFINED ENV{DESTDIR})
|
|
|
|
if(EXISTS /etc/debian_version)
|
|
|
|
list(APPEND options --install-layout=deb)
|
|
|
|
endif()
|
2018-11-20 14:13:35 +00:00
|
|
|
list(APPEND options
|
|
|
|
--root=\$ENV{DESTDIR}
|
|
|
|
--single-version-externally-managed)
|
2020-12-20 05:16:17 +00:00
|
|
|
endif()
|
|
|
|
if(NOT \"${DU_INSTALL_SCRIPT}\" STREQUAL \"\")
|
|
|
|
list(APPEND options --install-script=${DU_INSTALL_SCRIPT})
|
2016-06-01 17:50:21 +00:00
|
|
|
endif()
|
|
|
|
execute_process(
|
2019-12-18 09:08:21 +00:00
|
|
|
COMMAND ${Python3_EXECUTABLE}
|
2018-11-20 14:13:35 +00:00
|
|
|
setup.py install \${options}
|
2016-06-01 17:50:21 +00:00
|
|
|
WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}\")")
|
2016-05-28 07:44:36 +00:00
|
|
|
endfunction(distutils_install_module)
|
2016-06-01 05:38:05 +00:00
|
|
|
|
2019-12-18 09:08:21 +00:00
|
|
|
function(distutils_add_cython_module target name src)
|
2016-06-01 05:38:05 +00:00
|
|
|
get_property(compiler_launcher GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
|
|
|
|
get_property(link_launcher GLOBAL PROPERTY RULE_LAUNCH_LINK)
|
2016-09-29 15:25:04 +00:00
|
|
|
# When using ccache, CMAKE_C_COMPILER is ccache executable absolute path
|
|
|
|
# and the actual C compiler is CMAKE_C_COMPILER_ARG1.
|
|
|
|
# However with a naive
|
|
|
|
# set(PY_CC ${compiler_launcher} ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1})
|
|
|
|
# distutils tries to execve something like "/usr/bin/cmake gcc" and fails.
|
|
|
|
# Removing the leading whitespace from CMAKE_C_COMPILER_ARG1 helps to avoid
|
|
|
|
# the failure.
|
|
|
|
string(STRIP "${CMAKE_C_COMPILER_ARG1}" c_compiler_arg1)
|
|
|
|
string(STRIP "${CMAKE_CXX_COMPILER_ARG1}" cxx_compiler_arg1)
|
|
|
|
# Note: no quotes, otherwise distutils will execute "/usr/bin/ccache gcc"
|
|
|
|
# CMake's implicit conversion between strings and lists is wonderful, isn't it?
|
2021-05-05 07:16:45 +00:00
|
|
|
set(PY_CFLAGS ${COMPILE_OPTIONS})
|
2021-04-28 15:22:32 +00:00
|
|
|
cmake_parse_arguments(DU "DISABLE_VTA" "" "" ${ARGN})
|
|
|
|
if(DU_DISABLE_VTA AND HAS_VTA)
|
2021-05-05 07:16:45 +00:00
|
|
|
list(APPEND PY_CFLAGS -fno-var-tracking-assignments)
|
2021-04-28 15:22:32 +00:00
|
|
|
endif()
|
2021-05-05 07:16:45 +00:00
|
|
|
list(APPEND PY_CPPFLAGS -iquote${CMAKE_SOURCE_DIR}/src/include -w)
|
|
|
|
# This little bit of magic wipes out __Pyx_check_single_interpreter()
|
|
|
|
# Note: this is reproduced in distutils_install_cython_module
|
|
|
|
list(APPEND PY_CPPFLAGS -D'void0=dead_function\(void\)')
|
2022-08-05 08:40:41 +00:00
|
|
|
list(APPEND PY_CPPFLAGS -D'__Pyx_check_single_interpreter\(ARG\)=ARG\#\#0')
|
2021-05-05 07:16:45 +00:00
|
|
|
set(PY_CC ${compiler_launcher} ${CMAKE_C_COMPILER} ${c_compiler_arg1})
|
2016-09-29 15:25:04 +00:00
|
|
|
set(PY_CXX ${compiler_launcher} ${CMAKE_CXX_COMPILER} ${cxx_compiler_arg1})
|
|
|
|
set(PY_LDSHARED ${link_launcher} ${CMAKE_C_COMPILER} ${c_compiler_arg1} "-shared")
|
2024-03-17 15:40:27 +00:00
|
|
|
string(REPLACE " " ";" PY_LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
|
|
|
|
list(APPEND PY_LDFLAGS -L${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
|
2019-07-08 11:27:37 +00:00
|
|
|
|
2019-12-18 09:08:21 +00:00
|
|
|
execute_process(COMMAND "${Python3_EXECUTABLE}" -c
|
2022-03-25 15:06:46 +00:00
|
|
|
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
|
2019-07-08 11:27:37 +00:00
|
|
|
RESULT_VARIABLE result
|
|
|
|
OUTPUT_VARIABLE ext_suffix
|
|
|
|
ERROR_VARIABLE error
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
if(NOT result EQUAL 0)
|
|
|
|
message(FATAL_ERROR "Unable to tell python extension's suffix: ${error}")
|
|
|
|
endif()
|
2019-12-18 09:12:52 +00:00
|
|
|
set(output_dir "${CYTHON_MODULE_DIR}/lib.3")
|
2019-07-08 12:15:39 +00:00
|
|
|
set(setup_py ${CMAKE_CURRENT_SOURCE_DIR}/setup.py)
|
2021-10-14 06:39:55 +00:00
|
|
|
if(DEFINED ENV{VERBOSE})
|
|
|
|
set(maybe_verbose --verbose)
|
|
|
|
endif()
|
2019-07-08 12:06:06 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${output_dir}/${name}${ext_suffix}
|
2016-06-01 05:38:05 +00:00
|
|
|
COMMAND
|
|
|
|
env
|
2016-09-29 15:25:04 +00:00
|
|
|
CC="${PY_CC}"
|
2021-05-05 07:16:45 +00:00
|
|
|
CFLAGS="${PY_CFLAGS}"
|
|
|
|
CPPFLAGS="${PY_CPPFLAGS}"
|
2016-09-29 15:25:04 +00:00
|
|
|
CXX="${PY_CXX}"
|
|
|
|
LDSHARED="${PY_LDSHARED}"
|
2016-11-08 20:43:26 +00:00
|
|
|
OPT=\"-DNDEBUG -g -fwrapv -O2 -w\"
|
2024-03-17 15:40:27 +00:00
|
|
|
LDFLAGS="${PY_LDFLAGS}"
|
2016-06-01 05:38:05 +00:00
|
|
|
CYTHON_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}
|
2016-06-13 18:17:09 +00:00
|
|
|
CEPH_LIBDIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
|
2019-12-18 09:08:21 +00:00
|
|
|
${Python3_EXECUTABLE} ${setup_py}
|
2021-10-14 06:39:55 +00:00
|
|
|
build ${maybe_verbose} --build-base ${CYTHON_MODULE_DIR}
|
2019-07-08 11:27:37 +00:00
|
|
|
--build-platlib ${output_dir}
|
2019-07-08 12:15:39 +00:00
|
|
|
MAIN_DEPENDENCY ${src}
|
|
|
|
DEPENDS ${setup_py}
|
2019-07-08 12:06:06 +00:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
add_custom_target(${target} ALL
|
|
|
|
DEPENDS ${output_dir}/${name}${ext_suffix})
|
2016-06-01 05:38:05 +00:00
|
|
|
endfunction(distutils_add_cython_module)
|
|
|
|
|
2019-12-18 09:08:21 +00:00
|
|
|
function(distutils_install_cython_module name)
|
cmake: pass LDSHARED env var to distutils
otherwise, the default gcc will be used, and the $CMAKE_C_COMPILER
passed to the outer CMakeLists.txt won't kick in. moreover, if the
building script (ceph.spec for instance) could set the $PATH, and
expect that the CMakeLists.txt will use the toolchain executables
in the $PATH to build Ceph, distutils will continue using the default
$CC for linking the python bindings, on UNIX it will be gcc in the
new shell's $PATH, because we are using `install(CODE "... execute_process(
...))` for installing the python bindings. apparently, this is not
expected. because the new shell's $PATH is very likely different
from the one changed by the building script. to address this, we
should always specify the `$LDSHARED` env var explicitly.
also, pass env vars using `ENV{}` instead of the `env` command to
workaround the issue of https://cmake.org/pipermail/cmake/2015-December/062216.html,
because it's not straightforward to set environment variables with
spaces in the them using cmake. and because one cannot use add_custom_target()
in the script mode of cmake. this leave me only limited options to
fix this issue.
Signed-off-by: Kefu Chai <kchai@redhat.com>
2017-11-11 17:50:42 +00:00
|
|
|
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_LDSHARED "${link_launcher} ${CMAKE_C_COMPILER} -shared")
|
2021-04-28 15:22:32 +00:00
|
|
|
cmake_parse_arguments(DU "DISABLE_VTA" "" "" ${ARGN})
|
|
|
|
if(DU_DISABLE_VTA AND HAS_VTA)
|
|
|
|
set(CFLAG_DISABLE_VTA -fno-var-tracking-assignments)
|
|
|
|
endif()
|
2021-10-14 06:39:55 +00:00
|
|
|
if(DEFINED ENV{VERBOSE})
|
|
|
|
set(maybe_verbose --verbose)
|
|
|
|
endif()
|
2016-06-01 05:38:05 +00:00
|
|
|
install(CODE "
|
cmake: pass LDSHARED env var to distutils
otherwise, the default gcc will be used, and the $CMAKE_C_COMPILER
passed to the outer CMakeLists.txt won't kick in. moreover, if the
building script (ceph.spec for instance) could set the $PATH, and
expect that the CMakeLists.txt will use the toolchain executables
in the $PATH to build Ceph, distutils will continue using the default
$CC for linking the python bindings, on UNIX it will be gcc in the
new shell's $PATH, because we are using `install(CODE "... execute_process(
...))` for installing the python bindings. apparently, this is not
expected. because the new shell's $PATH is very likely different
from the one changed by the building script. to address this, we
should always specify the `$LDSHARED` env var explicitly.
also, pass env vars using `ENV{}` instead of the `env` command to
workaround the issue of https://cmake.org/pipermail/cmake/2015-December/062216.html,
because it's not straightforward to set environment variables with
spaces in the them using cmake. and because one cannot use add_custom_target()
in the script mode of cmake. this leave me only limited options to
fix this issue.
Signed-off-by: Kefu Chai <kchai@redhat.com>
2017-11-11 17:50:42 +00:00
|
|
|
set(ENV{CC} \"${PY_CC}\")
|
|
|
|
set(ENV{LDSHARED} \"${PY_LDSHARED}\")
|
2019-03-20 07:52:14 +00:00
|
|
|
set(ENV{CPPFLAGS} \"-iquote${CMAKE_SOURCE_DIR}/src/include
|
|
|
|
-D'void0=dead_function\(void\)' \
|
2022-08-05 08:40:41 +00:00
|
|
|
-D'__Pyx_check_single_interpreter\(ARG\)=ARG\#\#0' \
|
2021-04-28 15:22:32 +00:00
|
|
|
${CFLAG_DISABLE_VTA}\")
|
2024-03-17 15:40:27 +00:00
|
|
|
set(ENV{LDFLAGS} \"${PY_LDFLAGS}\")
|
cmake: pass LDSHARED env var to distutils
otherwise, the default gcc will be used, and the $CMAKE_C_COMPILER
passed to the outer CMakeLists.txt won't kick in. moreover, if the
building script (ceph.spec for instance) could set the $PATH, and
expect that the CMakeLists.txt will use the toolchain executables
in the $PATH to build Ceph, distutils will continue using the default
$CC for linking the python bindings, on UNIX it will be gcc in the
new shell's $PATH, because we are using `install(CODE "... execute_process(
...))` for installing the python bindings. apparently, this is not
expected. because the new shell's $PATH is very likely different
from the one changed by the building script. to address this, we
should always specify the `$LDSHARED` env var explicitly.
also, pass env vars using `ENV{}` instead of the `env` command to
workaround the issue of https://cmake.org/pipermail/cmake/2015-December/062216.html,
because it's not straightforward to set environment variables with
spaces in the them using cmake. and because one cannot use add_custom_target()
in the script mode of cmake. this leave me only limited options to
fix this issue.
Signed-off-by: Kefu Chai <kchai@redhat.com>
2017-11-11 17:50:42 +00:00
|
|
|
set(ENV{CYTHON_BUILD_DIR} \"${CMAKE_CURRENT_BINARY_DIR}\")
|
|
|
|
set(ENV{CEPH_LIBDIR} \"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")
|
|
|
|
|
2016-07-04 03:26:28 +00:00
|
|
|
set(options --prefix=${CMAKE_INSTALL_PREFIX})
|
2016-06-01 05:38:05 +00:00
|
|
|
if(DEFINED ENV{DESTDIR})
|
|
|
|
if(EXISTS /etc/debian_version)
|
2016-07-04 03:26:28 +00:00
|
|
|
list(APPEND options --install-layout=deb)
|
2016-06-01 05:38:05 +00:00
|
|
|
endif()
|
2016-07-04 03:26:28 +00:00
|
|
|
list(APPEND options --root=\$ENV{DESTDIR})
|
2016-06-01 05:38:05 +00:00
|
|
|
else()
|
2016-07-04 03:26:28 +00:00
|
|
|
list(APPEND options --root=/)
|
2016-06-01 05:38:05 +00:00
|
|
|
endif()
|
|
|
|
execute_process(
|
cmake: pass LDSHARED env var to distutils
otherwise, the default gcc will be used, and the $CMAKE_C_COMPILER
passed to the outer CMakeLists.txt won't kick in. moreover, if the
building script (ceph.spec for instance) could set the $PATH, and
expect that the CMakeLists.txt will use the toolchain executables
in the $PATH to build Ceph, distutils will continue using the default
$CC for linking the python bindings, on UNIX it will be gcc in the
new shell's $PATH, because we are using `install(CODE "... execute_process(
...))` for installing the python bindings. apparently, this is not
expected. because the new shell's $PATH is very likely different
from the one changed by the building script. to address this, we
should always specify the `$LDSHARED` env var explicitly.
also, pass env vars using `ENV{}` instead of the `env` command to
workaround the issue of https://cmake.org/pipermail/cmake/2015-December/062216.html,
because it's not straightforward to set environment variables with
spaces in the them using cmake. and because one cannot use add_custom_target()
in the script mode of cmake. this leave me only limited options to
fix this issue.
Signed-off-by: Kefu Chai <kchai@redhat.com>
2017-11-11 17:50:42 +00:00
|
|
|
COMMAND
|
2019-12-18 09:08:21 +00:00
|
|
|
${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py
|
2021-10-14 06:39:55 +00:00
|
|
|
build ${maybe_verbose} --build-base ${CYTHON_MODULE_DIR}
|
2019-12-18 09:12:52 +00:00
|
|
|
--build-platlib ${CYTHON_MODULE_DIR}/lib.3
|
2016-07-09 04:58:33 +00:00
|
|
|
build_ext --cython-c-in-temp --build-temp ${CMAKE_CURRENT_BINARY_DIR} --cython-include-dirs ${PROJECT_SOURCE_DIR}/src/pybind/rados
|
2016-07-08 06:57:41 +00:00
|
|
|
install \${options} --single-version-externally-managed --record /dev/null
|
|
|
|
egg_info --egg-base ${CMAKE_CURRENT_BINARY_DIR}
|
2021-10-14 06:39:55 +00:00
|
|
|
${maybe_verbose}
|
2016-06-01 05:38:05 +00:00
|
|
|
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)
|