remove redundant includes
[liba.git] / cmake / UseCCache.cmake
blob52fc561ef5b1dbfc6073f02e794fef464f07e36d
1 include(${CMAKE_CURRENT_LIST_DIR}/FindCCache.cmake)
2 if(CCACHE_FOUND)
3   set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_EXECUTABLE}")
4   set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY RULE_LAUNCH_LINK "${CCACHE_EXECUTABLE}")
5 endif()
6 if(CCACHE_FOUND AND CMAKE_GENERATOR STREQUAL "Xcode")
7   set(CMAKE_XCODE_ATTRIBUTE_CC ${CMAKE_CURRENT_BINARY_DIR}/cc)
8   set(CMAKE_XCODE_ATTRIBUTE_CXX ${CMAKE_CURRENT_BINARY_DIR}/cxx)
9   include(${CMAKE_CURRENT_LIST_DIR}/TargetSupportsSymbolicLink.cmake)
10   if(NOT TARGET_SUPPORTS_SYMBOLIC_LINK)
11     include(${CMAKE_CURRENT_LIST_DIR}/TemporaryDirectory.cmake)
12     if(EXISTS "${TEMPORARY_DIRECTORY}")
13       string(MD5 hash "${CMAKE_CURRENT_BINARY_DIR}")
14       set(CMAKE_XCODE_ATTRIBUTE_CC ${TEMPORARY_DIRECTORY}/cmake-${hash}/cc)
15       set(CMAKE_XCODE_ATTRIBUTE_CXX ${TEMPORARY_DIRECTORY}/cmake-${hash}/cxx)
16       set(hash)
17     endif()
18   endif()
19   set(CMAKE_XCODE_ATTRIBUTE_LD ${CMAKE_XCODE_ATTRIBUTE_CC})
20   file(WRITE ${CMAKE_XCODE_ATTRIBUTE_CC}
21     "#!/usr/bin/env sh\n\n"
22     "# Xcode generator doesn't include the compiler as the\n"
23     "# first argument, Ninja and Makefiles do. Handle both cases.\n"
24     "if [ \"$1\" = \"${CMAKE_C_COMPILER}\" ] ; then\n"
25     "    shift\n"
26     "fi\n\n"
27     "export CCACHE_CPP2=true\n"
28     "exec \"${CCACHE_EXECUTABLE}\" \"${CMAKE_C_COMPILER}\" \"$@\"\n"
29   )
30   execute_process(COMMAND chmod a+rx ${CMAKE_XCODE_ATTRIBUTE_CC})
31   set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS ${CMAKE_XCODE_ATTRIBUTE_CXX})
32   file(WRITE ${CMAKE_XCODE_ATTRIBUTE_CXX}
33     "#!/usr/bin/env sh\n\n"
34     "# Xcode generator doesn't include the compiler as the\n"
35     "# first argument, Ninja and Makefiles do. Handle both cases.\n"
36     "if [ \"$1\" = \"${CMAKE_CXX_COMPILER}\" ] ; then\n"
37     "    shift\n"
38     "fi\n\n"
39     "export CCACHE_CPP2=true\n"
40     "exec \"${CCACHE_EXECUTABLE}\" \"${CMAKE_CXX_COMPILER}\" \"$@\"\n"
41   )
42   execute_process(COMMAND chmod a+rx ${CMAKE_XCODE_ATTRIBUTE_CXX})
43 endif()