]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: pass LDSHARED env var to distutils
authorKefu Chai <kchai@redhat.com>
Sat, 11 Nov 2017 17:50:42 +0000 (01:50 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 15 Nov 2017 07:22:07 +0000 (15:22 +0800)
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>
cmake/modules/Distutils.cmake

index 24d1a50654865722fa547e141df6dca5d0b5cd6e..d6e9f3817c3d7a235cb6f15881a97eba318e0728 100644 (file)
@@ -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}