From: Kefu Chai Date: Sat, 11 Nov 2017 17:50:42 +0000 (+0800) Subject: cmake: pass LDSHARED env var to distutils X-Git-Tag: v13.0.1~79^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=571a786afcaba6e07f6a70313ce78a2dd66b712a;p=ceph.git 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 --- diff --git a/cmake/modules/Distutils.cmake b/cmake/modules/Distutils.cmake index 24d1a5065486..d6e9f3817c3d 100644 --- a/cmake/modules/Distutils.cmake +++ b/cmake/modules/Distutils.cmake @@ -56,7 +56,18 @@ function(distutils_add_cython_module name src) endfunction(distutils_add_cython_module) function(distutils_install_cython_module name) + 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") install(CODE " + set(ENV{CC} \"${PY_CC}\") + set(ENV{LDSHARED} \"${PY_LDSHARED}\") + set(ENV{CPPFLAGS} \"-iquote${CMAKE_SOURCE_DIR}/src/include\") + set(ENV{LDFLAGS} \"-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\") + set(ENV{CYTHON_BUILD_DIR} \"${CMAKE_CURRENT_BINARY_DIR}\") + set(ENV{CEPH_LIBDIR} \"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\") + set(options --prefix=${CMAKE_INSTALL_PREFIX}) if(DEFINED ENV{DESTDIR}) if(EXISTS /etc/debian_version) @@ -67,12 +78,7 @@ function(distutils_install_cython_module name) list(APPEND options --root=/) endif() execute_process( - COMMAND env - CYTHON_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR} - CEPH_LIBDIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} - CC=${CMAKE_C_COMPILER} - CPPFLAGS=\"-iquote${CMAKE_SOURCE_DIR}/src/include\" - LDFLAGS=\"-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\" + COMMAND ${PYTHON${PYTHON_VERSION}_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py build --verbose --build-base ${CYTHON_MODULE_DIR} --build-platlib ${CYTHON_MODULE_DIR}/lib.${PYTHON${PYTHON_VERSION}_VERSION_MAJOR}