Skip to contentSkip to conversation

package/pkg-cmake: Use CMAKE_<LANG>_COMPILER_LAUNCHER for ccache

PATCH Superseded Daniel Black 4 participants 7 messages Mar 9, 2017 – Mar 14, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/pkg-cmake: Use CMAKE_<LANG>_COMPILER_LAUNCHER for ccache

Since cmake version 3.4.3 CMAKE_<LANG>_COMPILER_LAUNCHER is used as the way to invoke things like ccache. We set this to ccache for the host and for cross compilers in toolchain.cmake.in. This leaves CMAKE_<C,CXX>_COMPILER pointing at the real compiler and still uses ccache.

ref: https://cmake.org/cmake/help/v3.4/variable/CMAKE_LANG_COMPILER_LAUNCHER.html

---
 package/pkg-cmake.mk                | 22 ++++++----------------
 support/misc/toolchainfile.cmake.in |  2 ++
 2 files changed, 8 insertions(+), 16 deletions(-)
package/pkg-cmake.mk +6 -16
index 5d0a455..e2590b7 100644
@@ -20,17 +20,6 @@
 #
 ################################################################################
 
-# Set compiler variables.
-ifeq ($(BR2_CCACHE),y)
-CMAKE_HOST_C_COMPILER = $(HOST_DIR)/usr/bin/ccache
-CMAKE_HOST_CXX_COMPILER = $(HOST_DIR)/usr/bin/ccache
-CMAKE_HOST_C_COMPILER_ARG1 = $(HOSTCC_NOCCACHE)
-CMAKE_HOST_CXX_COMPILER_ARG1 = $(HOSTCXX_NOCCACHE)
-else
-CMAKE_HOST_C_COMPILER = $(HOSTCC)
-CMAKE_HOST_CXX_COMPILER = $(HOSTCXX)
-endif
-
 ifneq ($(QUIET),)
 CMAKE_QUIET = -DCMAKE_RULE_MESSAGES=OFF -DCMAKE_INSTALL_MESSAGE=NEVER
 endif
@@ -120,11 +109,11 @@ define $(2)_CONFIGURE_CMDS
 		-DCMAKE_CXX_FLAGS="$$(HOST_CXXFLAGS)" \
 		-DCMAKE_EXE_LINKER_FLAGS="$$(HOST_LDFLAGS)" \
 		-DCMAKE_ASM_COMPILER="$$(HOSTAS)" \
-		-DCMAKE_C_COMPILER="$$(CMAKE_HOST_C_COMPILER)" \
-		-DCMAKE_CXX_COMPILER="$$(CMAKE_HOST_CXX_COMPILER)" \
-		$(if $$(CMAKE_HOST_C_COMPILER_ARG1),\
-			-DCMAKE_C_COMPILER_ARG1="$$(CMAKE_HOST_C_COMPILER_ARG1)" \
-			-DCMAKE_CXX_COMPILER_ARG1="$$(CMAKE_HOST_CXX_COMPILER_ARG1)" \
+		-DCMAKE_C_COMPILER="$$(HOSTCC_NOCCACHE)" \
+		-DCMAKE_CXX_COMPILER="$$(HOSTCXX_NOCCACHE)" \
+		$(if $(BR2_CCACHE),\
+			-DCMAKE_CXX_COMPILER_LAUNCHER="$$(HOST_DIR)/usr/bin/ccache" \
+			-DCMAKE_C_COMPILER_LAUNCHER="$$(HOST_DIR)/usr/bin/ccache" \
 		) \
 		-DCMAKE_COLOR_MAKEFILE=OFF \
 		-DBUILD_DOC=OFF \
@@ -247,6 +236,7 @@ $(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake:
 		-e 's#@@CMAKE_SYSTEM_PROCESSOR@@#$(call qstrip,$(CMAKE_SYSTEM_PROCESSOR))#' \
 		-e 's#@@TOOLCHAIN_HAS_FORTRAN@@#$(if $(BR2_TOOLCHAIN_HAS_FORTRAN),1,0)#' \
 		-e 's#@@CMAKE_BUILD_TYPE@@#$(if $(BR2_ENABLE_DEBUG),Debug,Release)#' \
+		-e 's#\([^@]*\)@@CCACHE@@#$(if $(BR2_CCACHE),\1/usr/bin/ccache,\#\1)#g' \
 		$(TOPDIR)/support/misc/toolchainfile.cmake.in \
 		> $@
 
support/misc/toolchainfile.cmake.in +2 -0
index c38800e..c4086ab 100644
@@ -60,6 +60,8 @@ set(ENV{PKG_CONFIG_SYSROOT_DIR} "${RELOCATED_HOST_DIR}/@@STAGING_SUBDIR@@")
 # This toolchain file can be used both inside and outside Buildroot.
 set(CMAKE_C_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CC@@")
 set(CMAKE_CXX_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CXX@@")
+set(CMAKE_C_COMPILER_LAUNCHER "${RELOCATED_HOST_DIR}/@@CCACHE@@")
+set(CMAKE_CXX_COMPILER_LAUNCHER "${RELOCATED_HOST_DIR}/@@CCACHE@@")
 if(@@TOOLCHAIN_HAS_FORTRAN@@)
   set(CMAKE_Fortran_FLAGS_DEBUG "" CACHE STRING "Debug Fortran FLAGS")
   set(CMAKE_Fortran_FLAGS_RELEASE " -DNDEBUG" CACHE STRING "Release Fortran FLAGS")
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 package/pkg-cmake: Use CMAKE_<LANG>_COMPILER_LAUNCHER for ccache

Hi Daniel,

Quoted 7 lines · Daniel Black

Since cmake version 3.4.3 CMAKE_<LANG>_COMPILER_LAUNCHER is used as the way to invoke things like ccache. We set this to ccache for the host and for cross compilers in toolchain.cmake.in. This leaves CMAKE_<C,CXX>_COMPILER pointing at the real compiler and still uses ccache.

ref: https://cmake.org/cmake/help/v3.4/variable/CMAKE_LANG_COMPILER_LAUNCHER.html

Currently the oldest version of host installed cmake version that Buildroot supports is 3.1. If the dependency checker finds cmake 3.1 and newer installed on the host, Buildroot will use it. For your patch to work, you need to bump the minimum to 3.4.3. See support/dependencies/check-host-cmake.mk.

baruch

Signature · 3 lines
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
#2 lore raw

PATCH v2 1/1 package/pkg-cmake: Use CMAKE_<LANG>_COMPILER_LAUNCHER for ccache

Since cmake version 3.4.0 CMAKE_<LANG>_COMPILER_LAUNCHER is used as the way to invoke things like ccache. We set this to ccache for the host and for cross compilers in toolchain.cmake.in. This leaves CMAKE_<C,CXX>_COMPILER pointing at the real compiler and still uses ccache.

Update minimium dependency version in check-host-cmake.mk accordingly.

ref: https://cmake.org/cmake/help/v3.4/variable/CMAKE_LANG_COMPILER_LAUNCHER.html

---
 package/pkg-cmake.mk                     | 22 ++++++----------------
 support/dependencies/check-host-cmake.mk |  2 +-
 support/misc/toolchainfile.cmake.in      |  2 ++
 3 files changed, 9 insertions(+), 17 deletions(-)
package/pkg-cmake.mk +6 -16
index 5d0a455..e2590b7 100644
@@ -20,17 +20,6 @@
 #
 ################################################################################
 
-# Set compiler variables.
-ifeq ($(BR2_CCACHE),y)
-CMAKE_HOST_C_COMPILER = $(HOST_DIR)/usr/bin/ccache
-CMAKE_HOST_CXX_COMPILER = $(HOST_DIR)/usr/bin/ccache
-CMAKE_HOST_C_COMPILER_ARG1 = $(HOSTCC_NOCCACHE)
-CMAKE_HOST_CXX_COMPILER_ARG1 = $(HOSTCXX_NOCCACHE)
-else
-CMAKE_HOST_C_COMPILER = $(HOSTCC)
-CMAKE_HOST_CXX_COMPILER = $(HOSTCXX)
-endif
-
 ifneq ($(QUIET),)
 CMAKE_QUIET = -DCMAKE_RULE_MESSAGES=OFF -DCMAKE_INSTALL_MESSAGE=NEVER
 endif
@@ -120,11 +109,11 @@ define $(2)_CONFIGURE_CMDS
 		-DCMAKE_CXX_FLAGS="$$(HOST_CXXFLAGS)" \
 		-DCMAKE_EXE_LINKER_FLAGS="$$(HOST_LDFLAGS)" \
 		-DCMAKE_ASM_COMPILER="$$(HOSTAS)" \
-		-DCMAKE_C_COMPILER="$$(CMAKE_HOST_C_COMPILER)" \
-		-DCMAKE_CXX_COMPILER="$$(CMAKE_HOST_CXX_COMPILER)" \
-		$(if $$(CMAKE_HOST_C_COMPILER_ARG1),\
-			-DCMAKE_C_COMPILER_ARG1="$$(CMAKE_HOST_C_COMPILER_ARG1)" \
-			-DCMAKE_CXX_COMPILER_ARG1="$$(CMAKE_HOST_CXX_COMPILER_ARG1)" \
+		-DCMAKE_C_COMPILER="$$(HOSTCC_NOCCACHE)" \
+		-DCMAKE_CXX_COMPILER="$$(HOSTCXX_NOCCACHE)" \
+		$(if $(BR2_CCACHE),\
+			-DCMAKE_CXX_COMPILER_LAUNCHER="$$(HOST_DIR)/usr/bin/ccache" \
+			-DCMAKE_C_COMPILER_LAUNCHER="$$(HOST_DIR)/usr/bin/ccache" \
 		) \
 		-DCMAKE_COLOR_MAKEFILE=OFF \
 		-DBUILD_DOC=OFF \
@@ -247,6 +236,7 @@ $(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake:
 		-e 's#@@CMAKE_SYSTEM_PROCESSOR@@#$(call qstrip,$(CMAKE_SYSTEM_PROCESSOR))#' \
 		-e 's#@@TOOLCHAIN_HAS_FORTRAN@@#$(if $(BR2_TOOLCHAIN_HAS_FORTRAN),1,0)#' \
 		-e 's#@@CMAKE_BUILD_TYPE@@#$(if $(BR2_ENABLE_DEBUG),Debug,Release)#' \
+		-e 's#\([^@]*\)@@CCACHE@@#$(if $(BR2_CCACHE),\1/usr/bin/ccache,\#\1)#g' \
 		$(TOPDIR)/support/misc/toolchainfile.cmake.in \
 		> $@
 
support/dependencies/check-host-cmake.mk +1 -1
index 8002278..21f5072 100644
@@ -8,7 +8,7 @@
 # package is bumped or a new one added, and it requires a higher
 # version, our cmake infra will catch it and whine.
 #
-BR2_CMAKE_VERSION_MIN = 3.1
+BR2_CMAKE_VERSION_MIN = 3.4
 
 BR2_CMAKE ?= cmake
 ifeq ($(call suitable-host-package,cmake,\
support/misc/toolchainfile.cmake.in +2 -0
index c38800e..c4086ab 100644
@@ -60,6 +60,8 @@ set(ENV{PKG_CONFIG_SYSROOT_DIR} "${RELOCATED_HOST_DIR}/@@STAGING_SUBDIR@@")
 # This toolchain file can be used both inside and outside Buildroot.
 set(CMAKE_C_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CC@@")
 set(CMAKE_CXX_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CXX@@")
+set(CMAKE_C_COMPILER_LAUNCHER "${RELOCATED_HOST_DIR}/@@CCACHE@@")
+set(CMAKE_CXX_COMPILER_LAUNCHER "${RELOCATED_HOST_DIR}/@@CCACHE@@")
 if(@@TOOLCHAIN_HAS_FORTRAN@@)
   set(CMAKE_Fortran_FLAGS_DEBUG "" CACHE STRING "Debug Fortran FLAGS")
   set(CMAKE_Fortran_FLAGS_RELEASE " -DNDEBUG" CACHE STRING "Release Fortran FLAGS")
Signature · 1 line
2.7.4
#3 lore raw

PATCH v2 1/1 package/pkg-cmake: Use CMAKE_<LANG>_COMPILER_LAUNCHER for ccache

Quoted 7 lines · Daniel Black

Since cmake version 3.4.0 CMAKE_<LANG>_COMPILER_LAUNCHER is used as the way to invoke things like ccache. We set this to ccache for the host and for cross compilers in toolchain.cmake.in. This leaves CMAKE_<C,CXX>_COMPILER pointing at the real compiler and still uses ccache.

Update minimium dependency version in check-host-cmake.mk accordingly.

This is very unfortunate, it means a substantial slowdown in the build for
people who have an older system CMake.

Although it is indeed cleaner to handle ccache this way, I don't think it
really fixes anything, does it? In that case, I think we should just stick with the old way of doing things. We can revisit when we need to CMake 3.4 for some other package.

Regards,
Arnout

Quoted 84 lines

ref: https://cmake.org/cmake/help/v3.4/variable/CMAKE_LANG_COMPILER_LAUNCHER.html

---
 package/pkg-cmake.mk                     | 22 ++++++----------------
 support/dependencies/check-host-cmake.mk |  2 +-
 support/misc/toolchainfile.cmake.in      |  2 ++
 3 files changed, 9 insertions(+), 17 deletions(-)
package/pkg-cmake.mk +6 -16
index 5d0a455..e2590b7 100644
@@ -20,17 +20,6 @@
 #
 ################################################################################
 
-# Set compiler variables.
-ifeq ($(BR2_CCACHE),y)
-CMAKE_HOST_C_COMPILER = $(HOST_DIR)/usr/bin/ccache
-CMAKE_HOST_CXX_COMPILER = $(HOST_DIR)/usr/bin/ccache
-CMAKE_HOST_C_COMPILER_ARG1 = $(HOSTCC_NOCCACHE)
-CMAKE_HOST_CXX_COMPILER_ARG1 = $(HOSTCXX_NOCCACHE)
-else
-CMAKE_HOST_C_COMPILER = $(HOSTCC)
-CMAKE_HOST_CXX_COMPILER = $(HOSTCXX)
-endif
-
 ifneq ($(QUIET),)
 CMAKE_QUIET = -DCMAKE_RULE_MESSAGES=OFF -DCMAKE_INSTALL_MESSAGE=NEVER
 endif
@@ -120,11 +109,11 @@ define $(2)_CONFIGURE_CMDS
 		-DCMAKE_CXX_FLAGS="$$(HOST_CXXFLAGS)" \
 		-DCMAKE_EXE_LINKER_FLAGS="$$(HOST_LDFLAGS)" \
 		-DCMAKE_ASM_COMPILER="$$(HOSTAS)" \
-		-DCMAKE_C_COMPILER="$$(CMAKE_HOST_C_COMPILER)" \
-		-DCMAKE_CXX_COMPILER="$$(CMAKE_HOST_CXX_COMPILER)" \
-		$(if $$(CMAKE_HOST_C_COMPILER_ARG1),\
-			-DCMAKE_C_COMPILER_ARG1="$$(CMAKE_HOST_C_COMPILER_ARG1)" \
-			-DCMAKE_CXX_COMPILER_ARG1="$$(CMAKE_HOST_CXX_COMPILER_ARG1)" \
+		-DCMAKE_C_COMPILER="$$(HOSTCC_NOCCACHE)" \
+		-DCMAKE_CXX_COMPILER="$$(HOSTCXX_NOCCACHE)" \
+		$(if $(BR2_CCACHE),\
+			-DCMAKE_CXX_COMPILER_LAUNCHER="$$(HOST_DIR)/usr/bin/ccache" \
+			-DCMAKE_C_COMPILER_LAUNCHER="$$(HOST_DIR)/usr/bin/ccache" \
 		) \
 		-DCMAKE_COLOR_MAKEFILE=OFF \
 		-DBUILD_DOC=OFF \
@@ -247,6 +236,7 @@ $(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake:
 		-e 's#@@CMAKE_SYSTEM_PROCESSOR@@#$(call qstrip,$(CMAKE_SYSTEM_PROCESSOR))#' \
 		-e 's#@@TOOLCHAIN_HAS_FORTRAN@@#$(if $(BR2_TOOLCHAIN_HAS_FORTRAN),1,0)#' \
 		-e 's#@@CMAKE_BUILD_TYPE@@#$(if $(BR2_ENABLE_DEBUG),Debug,Release)#' \
+		-e 's#\([^@]*\)@@CCACHE@@#$(if $(BR2_CCACHE),\1/usr/bin/ccache,\#\1)#g' \
 		$(TOPDIR)/support/misc/toolchainfile.cmake.in \
 		> $@
 
support/dependencies/check-host-cmake.mk +1 -1
index 8002278..21f5072 100644
@@ -8,7 +8,7 @@
 # package is bumped or a new one added, and it requires a higher
 # version, our cmake infra will catch it and whine.
 #
-BR2_CMAKE_VERSION_MIN = 3.1
+BR2_CMAKE_VERSION_MIN = 3.4
 
 BR2_CMAKE ?= cmake
 ifeq ($(call suitable-host-package,cmake,\
support/misc/toolchainfile.cmake.in +2 -0
index c38800e..c4086ab 100644
@@ -60,6 +60,8 @@ set(ENV{PKG_CONFIG_SYSROOT_DIR} "${RELOCATED_HOST_DIR}/@@STAGING_SUBDIR@@")
 # This toolchain file can be used both inside and outside Buildroot.
 set(CMAKE_C_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CC@@")
 set(CMAKE_CXX_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CXX@@")
+set(CMAKE_C_COMPILER_LAUNCHER "${RELOCATED_HOST_DIR}/@@CCACHE@@")
+set(CMAKE_CXX_COMPILER_LAUNCHER "${RELOCATED_HOST_DIR}/@@CCACHE@@")
 if(@@TOOLCHAIN_HAS_FORTRAN@@)
   set(CMAKE_Fortran_FLAGS_DEBUG "" CACHE STRING "Debug Fortran FLAGS")
   set(CMAKE_Fortran_FLAGS_RELEASE " -DNDEBUG" CACHE STRING "Release Fortran FLAGS")
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#4 lore raw

PATCH v2 1/1 package/pkg-cmake: Use CMAKE_<LANG>_COMPILER_LAUNCHER for ccache

Hey Arnout,

Quoted 9 lines · Arnout Vandecappelle
Quoted 6 lines · Daniel Black

Since cmake version 3.4.0 CMAKE_<LANG>_COMPILER_LAUNCHER is used as the way to invoke things like ccache. We set this to ccache for the host and for cross compilers in toolchain.cmake.in. This leaves CMAKE_<C,CXX>_COMPILER pointing at the real compiler and still uses ccache.

Quoted 4 lines
Quoted 1 line

Update minimium dependency version in check-host-cmake.mk accordingly.

This is very unfortunate, it means a substantial slowdown in the build for
people who have an older system CMake.

I didn't think it was that substantial for a one-off host package upgrade. I do realize it is a non-zero imposition for that installed cmake before it was updated to 3.4.0 in 7453c4bf6010b3a8dd794c39e327641abea15503 (Nov 13 2015).

Quoted 2 lines

Although it is indeed cleaner to handle ccache this way, I don't think it
really fixes anything, does it?

Might fix some subtle build errors for packages that do odd things however no, there isn't an definite breakage I can point to.

Quoted 3 lines

In that case, I think we should just stick with
the old way of doing things. We can revisit when we need to CMake 3.4 for some other package.

Works for me.

#5 lore raw

PATCH v2 1/1 package/pkg-cmake: Use CMAKE_<LANG>_COMPILER_LAUNCHER for ccache

Hello,

Quoted 20 lines · Daniel Black
Quoted 11 lines · Daniel Black
Quoted 7 lines

Since cmake version 3.4.0 CMAKE_<LANG>_COMPILER_LAUNCHER is used as the way to invoke things like ccache. We set this to ccache for the host and for cross compilers in toolchain.cmake.in. This leaves CMAKE_<C,CXX>_COMPILER pointing at the real compiler and still uses ccache.

Update minimium dependency version in check-host-cmake.mk accordingly.

This is very unfortunate, it means a substantial slowdown in the build for
people who have an older system CMake.

I didn't think it was that substantial for a one-off host package upgrade. I do realize it is a non-zero imposition for that installed cmake before it was updated to 3.4.0 in 7453c4bf6010b3a8dd794c39e327641abea15503 (Nov 13 2015).

Quoted 2 lines

Although it is indeed cleaner to handle ccache this way, I don't think it
really fixes anything, does it?

Quoted 8 lines

Might fix some subtle build errors for packages that do odd things however no, there isn't an definite breakage I can point to.

Quoted 3 lines

In that case, I think we should just stick with
the old way of doing things. We can revisit when we need to CMake 3.4 for some other package.

Works for me.

Thanks for your feedback, and to Arnout for reviewing the patch. Following your discussion, I've marked the patch as "Rejected" in patchwork.

Best regards,

Thomas Petazzoni

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#6 lore raw

PATCH 1/1 package/pkg-cmake: Use CMAKE_<LANG>_COMPILER_LAUNCHER for ccache

In reply to Baruch Siach
Quoted 9 lines · Baruch Siach

Hi Daniel,

Quoted 6 lines · Daniel Black

Since cmake version 3.4.3 CMAKE_<LANG>_COMPILER_LAUNCHER is used as the way to invoke things like ccache. We set this to ccache for the host and for cross compilers in toolchain.cmake.in. This leaves CMAKE_<C,CXX>_COMPILER pointing at the real compiler and still uses ccache.

Quoted 6 lines
Quoted 1 line

ref: https://cmake.org/cmake/help/v3.4/variable/CMAKE_LANG_COMPILER_LAUNCHER.html

Currently the oldest version of host installed cmake version that Buildroot supports is 3.1. If the dependency checker finds cmake 3.1 and newer installed on the host, Buildroot will use it. For your patch to work, you need to bump the minimum to 3.4.3. See support/dependencies/check-host-cmake.mk.

Thanks Baruch,

Seems that this version can only handle one decimal place however looking closer at cmake it is in the 3.4.0 version and not in the earlier 3.3.1 release.

~/repos/cmake ((v3.3.1))]$ git checkout v3.4.0
Previous HEAD position was 4a6fe02... CMake 3.3.1
HEAD is now at b4a2ada... CMake 3.4.0

~/repos/cmake ((v3.4.0))]$ grep -r _COMPILER_LAUNCHER .
...

./Help/prop_tgt/LANG_COMPILER_LAUNCHER.rst:<LANG>_COMPILER_LAUNCHER
...
./Source/cmMakefileTargetGenerator.cxx: std::string const
clauncher_prop = lang + "_COMPILER_LAUNCHER";
./Source/cmNinjaTargetGenerator.cxx: std::string const clauncher_prop
= lang + "_COMPILER_LAUNCHER";