]> git.proxmox.com Git - ceph.git/blob - ceph/cmake/modules/Distutils.cmake
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / cmake / modules / Distutils.cmake
1 include(CMakeParseArguments)
2
3 function(distutils_install_module name)
4 set(py_srcs setup.py README.rst requirements.txt test-requirements.txt bin ${name})
5 foreach(src ${py_srcs})
6 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${src})
7 list(APPEND py_clone ${CMAKE_CURRENT_BINARY_DIR}/${src})
8 add_custom_command(
9 OUTPUT ${src}
10 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${src}
11 COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${src})
12 endif()
13 endforeach()
14 add_custom_target(${name}-clone ALL
15 DEPENDS ${py_clone})
16 cmake_parse_arguments(DU "" INSTALL_SCRIPT "" ${ARGN})
17 install(CODE "
18 set(options --prefix=${CMAKE_INSTALL_PREFIX})
19 if(DEFINED ENV{DESTDIR})
20 if(EXISTS /etc/debian_version)
21 list(APPEND options --install-layout=deb)
22 endif()
23 list(APPEND options
24 --root=\$ENV{DESTDIR}
25 --single-version-externally-managed)
26 if(NOT \"${DU_INSTALL_SCRIPT}\" STREQUAL \"\")
27 list(APPEND options --install-script=${DU_INSTALL_SCRIPT})
28 endif()
29 endif()
30 execute_process(
31 COMMAND ${PYTHON${PYTHON_VERSION}_EXECUTABLE}
32 setup.py install \${options}
33 WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}\")")
34 endfunction(distutils_install_module)
35
36 function(distutils_add_cython_module name src)
37 get_property(compiler_launcher GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
38 get_property(link_launcher GLOBAL PROPERTY RULE_LAUNCH_LINK)
39 # When using ccache, CMAKE_C_COMPILER is ccache executable absolute path
40 # and the actual C compiler is CMAKE_C_COMPILER_ARG1.
41 # However with a naive
42 # set(PY_CC ${compiler_launcher} ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1})
43 # distutils tries to execve something like "/usr/bin/cmake gcc" and fails.
44 # Removing the leading whitespace from CMAKE_C_COMPILER_ARG1 helps to avoid
45 # the failure.
46 string(STRIP "${CMAKE_C_COMPILER_ARG1}" c_compiler_arg1)
47 string(STRIP "${CMAKE_CXX_COMPILER_ARG1}" cxx_compiler_arg1)
48 # Note: no quotes, otherwise distutils will execute "/usr/bin/ccache gcc"
49 # CMake's implicit conversion between strings and lists is wonderful, isn't it?
50 string(REPLACE " " ";" cflags ${CMAKE_C_FLAGS})
51 list(APPEND cflags -iquote${CMAKE_SOURCE_DIR}/src/include -w)
52 # This little bit of magic wipes out __Pyx_check_single_interpreter()
53 # Note: this is reproduced in distutils_install_cython_module
54 list(APPEND cflags -D'void0=dead_function\(void\)')
55 list(APPEND cflags -D'__Pyx_check_single_interpreter\(ARG\)=ARG \#\# 0')
56 set(PY_CC ${compiler_launcher} ${CMAKE_C_COMPILER} ${c_compiler_arg1} ${cflags})
57 set(PY_CXX ${compiler_launcher} ${CMAKE_CXX_COMPILER} ${cxx_compiler_arg1})
58 set(PY_LDSHARED ${link_launcher} ${CMAKE_C_COMPILER} ${c_compiler_arg1} "-shared")
59 add_custom_target(${name} ALL
60 COMMAND
61 env
62 CC="${PY_CC}"
63 CXX="${PY_CXX}"
64 LDSHARED="${PY_LDSHARED}"
65 OPT=\"-DNDEBUG -g -fwrapv -O2 -w\"
66 LDFLAGS=-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
67 CYTHON_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}
68 CEPH_LIBDIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
69 ${PYTHON${PYTHON_VERSION}_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py
70 build --verbose --build-base ${CYTHON_MODULE_DIR}
71 --build-platlib ${CYTHON_MODULE_DIR}/lib.${PYTHON${PYTHON_VERSION}_VERSION_MAJOR}
72 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
73 DEPENDS ${src})
74 endfunction(distutils_add_cython_module)
75
76 function(distutils_install_cython_module name)
77 get_property(compiler_launcher GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
78 get_property(link_launcher GLOBAL PROPERTY RULE_LAUNCH_LINK)
79 set(PY_CC "${compiler_launcher} ${CMAKE_C_COMPILER}")
80 set(PY_LDSHARED "${link_launcher} ${CMAKE_C_COMPILER} -shared")
81 install(CODE "
82 set(ENV{CC} \"${PY_CC}\")
83 set(ENV{LDSHARED} \"${PY_LDSHARED}\")
84 set(ENV{CPPFLAGS} \"-iquote${CMAKE_SOURCE_DIR}/src/include
85 -D'void0=dead_function\(void\)' \
86 -D'__Pyx_check_single_interpreter\(ARG\)=ARG \#\# 0'\")
87 set(ENV{LDFLAGS} \"-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")
88 set(ENV{CYTHON_BUILD_DIR} \"${CMAKE_CURRENT_BINARY_DIR}\")
89 set(ENV{CEPH_LIBDIR} \"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")
90
91 set(options --prefix=${CMAKE_INSTALL_PREFIX})
92 if(DEFINED ENV{DESTDIR})
93 if(EXISTS /etc/debian_version)
94 list(APPEND options --install-layout=deb)
95 endif()
96 list(APPEND options --root=\$ENV{DESTDIR})
97 else()
98 list(APPEND options --root=/)
99 endif()
100 execute_process(
101 COMMAND
102 ${PYTHON${PYTHON_VERSION}_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py
103 build --verbose --build-base ${CYTHON_MODULE_DIR}
104 --build-platlib ${CYTHON_MODULE_DIR}/lib.${PYTHON${PYTHON_VERSION}_VERSION_MAJOR}
105 build_ext --cython-c-in-temp --build-temp ${CMAKE_CURRENT_BINARY_DIR} --cython-include-dirs ${PROJECT_SOURCE_DIR}/src/pybind/rados
106 install \${options} --single-version-externally-managed --record /dev/null
107 egg_info --egg-base ${CMAKE_CURRENT_BINARY_DIR}
108 --verbose
109 WORKING_DIRECTORY \"${CMAKE_CURRENT_SOURCE_DIR}\"
110 RESULT_VARIABLE install_res)
111 if(NOT \"\${install_res}\" STREQUAL 0)
112 message(FATAL_ERROR \"Failed to build and install ${name} python module\")
113 endif()
114 ")
115 endfunction(distutils_install_cython_module)