diff --git a/cmake/Modules/UseCompilerCache.cmake b/cmake/Modules/UseCompilerCache.cmake index 4c2b0743b86..0c21d296c0a 100644 --- a/cmake/Modules/UseCompilerCache.cmake +++ b/cmake/Modules/UseCompilerCache.cmake @@ -18,7 +18,7 @@ function(pcl_ccache_compat_file_gen FILE_NAME CCACHE_PROGRAM COMPILER) message(STATUS "${FILE_NAME} for ${CCACHE_PROGRAM} with ${COMPILER}") file(WRITE "${CMAKE_BINARY_DIR}/${FILE_NAME}" "" - "#!/bin/sh\n" + "#! /usr/bin/env sh\n" "\n" "# Xcode generator doesn't include the compiler as the\n" "# first argument, Ninja and Makefiles do. Handle both cases.\n" @@ -90,9 +90,10 @@ function(UseCompilerCache) # Indirect wrapper is needed for CCache < 3.3 or XCode if(NOT (${xcode_compat} OR ${ccache_compat})) # Support Unix Makefiles and Ninja - set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") - set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") - set(CMAKE_CUDA_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") + message(STATUS "Compiler cache via cmake launcher prefix") + set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" PARENT_SCOPE) + set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" PARENT_SCOPE) + set(CMAKE_CUDA_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" PARENT_SCOPE) return() endif() @@ -105,7 +106,11 @@ function(UseCompilerCache) "${CMAKE_BINARY_DIR}/launch-cxx") # Cuda support only added in CMake 3.10 + set(cuda_supported FALSE) if (NOT (CMAKE_VERSION VERSION_LESS 3.10) AND CMAKE_CUDA_COMPILER) + set(cuda_supported TRUE) + endif() + if(${cuda_supported}) pcl_ccache_compat_file_gen("launch-cuda" ${CCACHE_PROGRAM} ${CMAKE_CUDA_COMPILER}) execute_process(COMMAND chmod a+rx "${CMAKE_BINARY_DIR}/launch-cuda") @@ -113,14 +118,17 @@ function(UseCompilerCache) if(${xcode_compat}) # Set Xcode project attributes to route compilation and linking properly - set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/launch-c") - set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/launch-cxx") - set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/launch-c") - set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/launch-cxx") + message(STATUS "Compiler cache via launch files to support XCode") + set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/launch-c" PARENT_SCOPE) + set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/launch-cxx" PARENT_SCOPE) + set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/launch-c" PARENT_SCOPE) + set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/launch-cxx" PARENT_SCOPE) else() - # Support Unix Makefiles and Ninja - set(CMAKE_C_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/launch-c") - set(CMAKE_CXX_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/launch-cxx") - set(CMAKE_CUDA_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/launch-cuda") + message(STATUS "Compiler cache via launch files to support Unix Makefiles and Ninja") + set(CMAKE_C_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/launch-c" PARENT_SCOPE) + set(CMAKE_CXX_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/launch-cxx" PARENT_SCOPE) + if (${cuda_supported}) + set(CMAKE_CUDA_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/launch-cuda" PARENT_SCOPE) + endif() endif() endfunction()