summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Martin <s.martin49@gmail.com>2014-06-01 11:24:25 +0200
committerPeter Korsgaard <peter@korsgaard.com>2014-06-01 22:16:24 +0200
commitc8f2d248f65067979f9b7da25ee2469ae020ec1b (patch)
tree455a4c582f84b4125a7e5ecf59b3110ec1bf0318
parent9033d90118689a50b13b3764a927ec1b202624bf (diff)
downloadbuildroot-c8f2d248f65067979f9b7da25ee2469ae020ec1b.tar.gz
buildroot-c8f2d248f65067979f9b7da25ee2469ae020ec1b.zip
pkg-cmake.mk: enable ccache for cmake packages
This patch updates the generated toolchainfile.cmake to use ccache. When toolchainfile.cmake is used inside Buildroot, using ccache during the build is driven by a CMake knob: USE_CCACHE, automatically set by the cmake-package infrastructure and reflecting the BR2_CCACHE value. Since this toolchainefile.cmake file can be used outside Buildroot, and this file also set a couple of things (among these: the sysroot cflag, some pkg-config environment variables), it is important to set the compiler variables as well to keep the consistency of the cross-compilation configuration. So, when it is used outside Buildroot, using ccache for the build is driven by the ccache program availability. Note that using ccache for the build is achieved by setting the *_ARG1 CMake variables to let CMake use ccache without failing in detecting the compiler. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Samuel Martin <s.martin49@gmail.com> Cc: Luca Ceresoli <luca@lucaceresoli.net> Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be> Reviewed-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
-rw-r--r--package/pkg-cmake.mk2
-rw-r--r--support/misc/toolchainfile.cmake.in33
2 files changed, 33 insertions, 2 deletions
diff --git a/package/pkg-cmake.mk b/package/pkg-cmake.mk
index a84aa0b302..56a93c70ac 100644
--- a/package/pkg-cmake.mk
+++ b/package/pkg-cmake.mk
@@ -66,6 +66,7 @@ define $(2)_CONFIGURE_CMDS
-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
@@ -83,6 +84,7 @@ define $(2)_CONFIGURE_CMDS
-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
diff --git a/support/misc/toolchainfile.cmake.in b/support/misc/toolchainfile.cmake.in
index 27a0af1e8e..46ed9324cd 100644
--- a/support/misc/toolchainfile.cmake.in
+++ b/support/misc/toolchainfile.cmake.in
@@ -23,5 +23,34 @@ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
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()
OpenPOWER on IntegriCloud