-DCMAKE_INSTALL_PREFIX="/usr" \
-DCMAKE_COLOR_MAKEFILE=OFF \
-DBUILD_SHARED_LIBS=$(if $(BR2_PREFER_STATIC_LIB),OFF,ON) \
+ -DUSE_CCACHE=$(if $(BR2_CCACHE),ON,OFF) \
$$($$(PKG)_CONF_OPT) \
)
endef
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY="BOTH" \
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE="BOTH" \
-DCMAKE_INSTALL_PREFIX="$$(HOST_DIR)/usr" \
+ -DUSE_CCACHE=$(if $(BR2_CCACHE),ON,OFF) \
$$($$(PKG)_CONF_OPT) \
)
endef
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(ENV{PKG_CONFIG_SYSROOT_DIR} "${RELOCATED_HOST_DIR}/@@STAGING_SUBDIR@@")
-set(CMAKE_C_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CC_NOCCACHE@@")
-set(CMAKE_CXX_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CXX_NOCCACHE@@")
+# This toolchain file can be used both inside and outside Buildroot.
+# * When used inside Buildroot, ccache support is explicitly driven using the
+# USE_CCACHE variable.
+# * When used outside Buildroot (i.e. when USE_CCACHE is not defined), ccache
+# support is automatically enabled if the ccache program is available.
+if(DEFINED USE_CCACHE)
+ if(USE_CCACHE)
+ set(CMAKE_ASM_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CC_NOCCACHE@@")
+ set(CMAKE_C_COMPILER "${RELOCATED_HOST_DIR}/usr/bin/ccache")
+ set(CMAKE_CXX_COMPILER "${RELOCATED_HOST_DIR}/usr/bin/ccache")
+ set(CMAKE_C_COMPILER_ARG1 "${RELOCATED_HOST_DIR}/@@TARGET_CC_NOCCACHE@@")
+ set(CMAKE_CXX_COMPILER_ARG1 "${RELOCATED_HOST_DIR}/@@TARGET_CXX_NOCCACHE@@")
+ else()
+ set(CMAKE_C_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CC_NOCCACHE@@")
+ set(CMAKE_CXX_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CXX_NOCCACHE@@")
+ endif()
+else()
+ find_program(CCACHE ccache HINTS "${RELOCATED_HOST_DIR}/usr/bin")
+ if(CCACHE)
+ set(CMAKE_ASM_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CC_NOCCACHE@@")
+ set(CMAKE_C_COMPILER "${CCACHE}")
+ set(CMAKE_CXX_COMPILER "${CCACHE}")
+ set(CMAKE_C_COMPILER_ARG1 "${RELOCATED_HOST_DIR}/@@TARGET_CC_NOCCACHE@@")
+ set(CMAKE_CXX_COMPILER_ARG1 "${RELOCATED_HOST_DIR}/@@TARGET_CXX_NOCCACHE@@")
+ message(STATUS "ccache program has been found and will be used for the build.")
+ message(STATUS " To disable ccache, add -DUSE_CCACHE=OFF on the cmake command line.")
+ else()
+ set(CMAKE_C_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CC_NOCCACHE@@")
+ set(CMAKE_CXX_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CXX_NOCCACHE@@")
+ endif()
+endif()