]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
fix compilation with distcc and other compiler wrappers 24605/head
authorAlexey Sheplyakov <asheplyakov@mirantis.com>
Thu, 29 Sep 2016 15:25:04 +0000 (18:25 +0300)
committerKefu Chai <kchai@redhat.com>
Tue, 16 Oct 2018 03:33:29 +0000 (11:33 +0800)
When building with ccache, distcc, and other compiler wrappers (such
as STLFilt):

CC='ccache gcc' CXX='ccache g++' cmake /path/to/ceph
make

python modules fail to compile since distutils try to execute the
wrapper itself without specifying the actual compiler.
Although cmake has a special magic switch for compiling with ccache
(cmake -DWITH_CCACHE=ON) other tools (distcc) are not supported, and
specifying the compiler as

CC=/whatever/compiler/is

used to work for decades, and it's a good idea to keep it working

Signed-off-by: Alexey Sheplyakov <asheplyakov@mirantis.com>
Signed-off-by: Kefu Chai <kchai@redhat.com>
cmake/modules/Distutils.cmake

index 672b56385e9c65f252e41e4e207283c62fff8ced..2cd7ff369ae4475c9ca32903155a8fe625b88075 100644 (file)
@@ -34,15 +34,26 @@ 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\")
+  # 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?
+  set(PY_CC ${compiler_launcher} ${CMAKE_C_COMPILER} ${c_compiler_arg1})
+  set(PY_CXX ${compiler_launcher} ${CMAKE_CXX_COMPILER} ${cxx_compiler_arg1})
+  set(PY_LDSHARED ${link_launcher} ${CMAKE_C_COMPILER} ${c_compiler_arg1} "-shared")
   add_custom_target(${name} ALL
     COMMAND
     env
-    CC=${PY_CC}
-    CXX=${PY_CXX}
-    LDSHARED=${PY_LDSHARED}
+    CC="${PY_CC}"
+    CXX="${PY_CXX}"
+    LDSHARED="${PY_LDSHARED}"
     OPT=\"-DNDEBUG -g -fwrapv -O2 -w\"
     LDFLAGS=-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
     CYTHON_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}