Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Martin <s.martin49@gmail.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v4 03/11] pkg-cmake.mk: enable ccache for cmake packages
Date: Sun,  1 Jun 2014 11:24:25 +0200	[thread overview]
Message-ID: <1401614673-3703-4-git-send-email-s.martin49@gmail.com> (raw)
In-Reply-To: <1401614673-3703-1-git-send-email-s.martin49@gmail.com>

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>

---
changes v3 -> v4 (Samuel):
- rebase
- make sure ccache built by Buildroot can be found when
  toolchainfile.cmakeis used outside Buildroot (Arnout)

changes v2 -> v3 (Samuel):
- rebase
- inline the -DUSE_CCACHE=... in the configure commands.
- always set the compiler variables, even when called for outside
  Buildroot.
- update commit message

changes v1 -> v2 (Luca):
- totally reimplemented based on Samuel's suggestion;
- added dependency on host-ccache for cmake packages if ccache is
  enabled.
---
 package/pkg-cmake.mk                |  2 ++
 support/misc/toolchainfile.cmake.in | 33 +++++++++++++++++++++++++++++++--
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/package/pkg-cmake.mk b/package/pkg-cmake.mk
index 2d4a264..1de1d4a 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 df79acd..8cf28e9 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()
-- 
1.9.2

  parent reply	other threads:[~2014-06-01  9:24 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-01  9:24 [Buildroot] [PATCH v4 00/11] CMake infrastructure refactoring Samuel Martin
2014-06-01  9:24 ` [Buildroot] [PATCH v4 01/11] pkg-cmake.mk: refactor the toolchainfile.cmake generation Samuel Martin
2014-06-01 10:54   ` Thomas Petazzoni
2014-06-01 20:12   ` Peter Korsgaard
2014-06-01  9:24 ` [Buildroot] [PATCH v4 02/11] pkg-cmake.mk: do not hardcode absolute path in toolchainfile.cmake Samuel Martin
2014-06-01 10:57   ` Thomas Petazzoni
2014-06-01 20:16   ` Peter Korsgaard
2014-06-01  9:24 ` Samuel Martin [this message]
2014-06-01 10:57   ` [Buildroot] [PATCH v4 03/11] pkg-cmake.mk: enable ccache for cmake packages Thomas Petazzoni
2014-06-01 20:17   ` Peter Korsgaard
2014-06-01  9:24 ` [Buildroot] [PATCH v4 04/11] rpi-userland: cleanup *_CONF_OPT Samuel Martin
2014-06-01 11:04   ` Thomas Petazzoni
2014-06-01  9:24 ` [Buildroot] [PATCH v4 05/11] xbmc: fix missing libraries from rpi-userland Samuel Martin
2014-06-01  9:24 ` [Buildroot] [PATCH v4 06/11] pkg-cmake.mk: globally disable BUILD_TESTING flag Samuel Martin
2014-06-01 11:05   ` Thomas Petazzoni
2014-06-01 20:18   ` Peter Korsgaard
2014-06-01  9:24 ` [Buildroot] [PATCH v4 07/11] pkg-cmake.mk: globally drive the CMAKE_BUILD_TYPE flag using BR2_ENABLE_DEBUG Samuel Martin
2014-06-01 11:06   ` Thomas Petazzoni
2014-06-01 20:18   ` Peter Korsgaard
2014-06-01  9:24 ` [Buildroot] [PATCH v4 08/11] openpowerlink: do not override CMAKE_BUILD_TYPE Samuel Martin
2014-06-01 11:07   ` Thomas Petazzoni
2014-06-01 20:19   ` Peter Korsgaard
2014-06-01  9:24 ` [Buildroot] [PATCH v4 09/11] opencv: " Samuel Martin
2014-06-01 11:07   ` Thomas Petazzoni
2014-06-01 20:20   ` Peter Korsgaard
2014-06-01  9:24 ` [Buildroot] [PATCH v4 10/11] flann: " Samuel Martin
2014-06-01 11:07   ` Thomas Petazzoni
2014-06-01 20:20   ` Peter Korsgaard
2014-06-01  9:24 ` [Buildroot] [PATCH v4 11/11] qhull: " Samuel Martin
2014-06-01 11:07   ` Thomas Petazzoni
2014-06-01 20:20   ` Peter Korsgaard
2014-06-01 11:08 ` [Buildroot] [PATCH v4 00/11] CMake infrastructure refactoring Thomas Petazzoni
2014-06-01 20:20   ` Peter Korsgaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1401614673-3703-4-git-send-email-s.martin49@gmail.com \
    --to=s.martin49@gmail.com \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox