Skip to content

Commit

Permalink
Modifications to save variables in parent scope
Browse files Browse the repository at this point in the history
  • Loading branch information
kunaltyagi committed Oct 8, 2019
1 parent c85aad1 commit a52f969
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions cmake/Modules/UseCompilerCache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()

Expand All @@ -105,22 +106,29 @@ 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")
endif()

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()

0 comments on commit a52f969

Please sign in to comment.