remove gcc for MacOS in conan.yml
[liba.git] / cmake / UseCCache.cmake
blob06617bacdc83c50ea71a978c4c3173f8b8689f3d
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     endif()
17   endif()
18   set(CMAKE_XCODE_ATTRIBUTE_LD ${CMAKE_XCODE_ATTRIBUTE_CC})
19   file(WRITE ${CMAKE_XCODE_ATTRIBUTE_CC}
20     "# Xcode generator doesn't include the compiler as the\n"
21     "# first argument, Ninja and Makefiles do. Handle both cases.\n"
22     "if [ \"$1\" = \"${CMAKE_C_COMPILER}\" ]; then\n"
23     "    shift\n"
24     "fi\n\n"
25     "export CCACHE_CPP2=true\n"
26     "exec \"${CCACHE_EXECUTABLE}\" \"${CMAKE_C_COMPILER}\" \"$@\""
27   )
28   execute_process(COMMAND chmod a+rx ${CMAKE_XCODE_ATTRIBUTE_CC})
29   set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS ${CMAKE_XCODE_ATTRIBUTE_CXX})
30   file(WRITE ${CMAKE_XCODE_ATTRIBUTE_CXX}
31     "# Xcode generator doesn't include the compiler as the\n"
32     "# first argument, Ninja and Makefiles do. Handle both cases.\n"
33     "if [ \"$1\" = \"${CMAKE_CXX_COMPILER}\" ]; then\n"
34     "    shift\n"
35     "fi\n\n"
36     "export CCACHE_CPP2=true\n"
37     "exec \"${CCACHE_EXECUTABLE}\" \"${CMAKE_CXX_COMPILER}\" \"$@\""
38   )
39   execute_process(COMMAND chmod a+rx ${CMAKE_XCODE_ATTRIBUTE_CXX})
40 endif()