[debhelper-devel] Bug#794396: CMake cross compilation support

Helmut Grohne helmut at subdivi.de
Mon Aug 3 05:14:16 UTC 2015


On Sun, Aug 02, 2015 at 05:27:39PM +0200, Helmut Grohne wrote:
> So I worked from this patch and tried to implement the same approach
> into debhelper itself. The result is the other attached patch. Like the
> autoconf.pm counterpart, it is only active when the build architecture
> and the host architecture differ, so I do note expect any regressions
> for native compilation. Yet, cross compilation never worked with CMake,
> so I think it is safe to change the behaviour of the build system.

Guillem Jover spotted my use of an undefined architecture variable.
Updating the patch.

Helmut
-------------- next part --------------
diff -Nru debhelper-9.20150628/Debian/Debhelper/Buildsystem/cmake.pm debhelper-9.20150628+nmu1/Debian/Debhelper/Buildsystem/cmake.pm
--- debhelper-9.20150628/Debian/Debhelper/Buildsystem/cmake.pm	2015-05-15 18:20:39.000000000 +0200
+++ debhelper-9.20150628+nmu1/Debian/Debhelper/Buildsystem/cmake.pm	2015-08-03 07:11:22.000000000 +0200
@@ -7,7 +7,7 @@
 package Debian::Debhelper::Buildsystem::cmake;
 
 use strict;
-use Debian::Debhelper::Dh_Lib qw(compat);
+use Debian::Debhelper::Dh_Lib qw(compat dpkg_architecture_value);
 use base 'Debian::Debhelper::Buildsystem::makefile';
 
 sub DESCRIPTION {
@@ -45,6 +45,28 @@
 	push @flags, "-DCMAKE_VERBOSE_MAKEFILE=ON";
 	push @flags, "-DCMAKE_BUILD_TYPE=None";
 
+	if (dpkg_architecture_value("DEB_BUILD_GNU_TYPE")
+	    ne dpkg_architecture_value("DEB_HOST_GNU_TYPE")) {
+		if (dpkg_architecture_value("DEB_HOST_ARCH_OS") eq "linux") {
+			push @flags, "-DCMAKE_SYSTEM_NAME=Linux";
+		} elsif (dpkg_architecture_value("DEB_HOST_ARCH_OS") eq "freebsd") {
+			push @flags, "-DCMAKE_SYSTEM_NAME=FreeBSD";
+		} elsif (dpkg_architecture_value("DEB_HOST_ARCH_OS") eq "hurd") {
+			push @flags, "-DCMAKE_SYSTEM_NAME=GNU";
+		}
+		push @flags, "-DCMAKE_SYSTEM_PROCESSOR=" . dpkg_architecture_value("DEB_HOST_GNU_CPU");
+		if ($ENV{CC}) {
+			push @flags, "-DCMAKE_C_COMPILER=" . $ENV{CC};
+		} else {
+			push @flags, "-DCMAKE_C_COMPILER=" . dpkg_architecture_value("DEB_HOST_GNU_TYPE") . "-cc";
+		}
+		if ($ENV{CXX}) {
+			push @flags, "-DCMAKE_CXX_COMPILER=" . $ENV{CXX};
+		} else {
+			push @flags, "-DCMAKE_CXX_COMPILER=" . dpkg_architecture_value("DEB_HOST_GNU_TYPE") . "-c++";
+		}
+	}
+
 	# CMake doesn't respect CPPFLAGS, see #653916.
 	if ($ENV{CPPFLAGS} && ! compat(8)) {
 		$ENV{CFLAGS}   .= ' ' . $ENV{CPPFLAGS};
diff -Nru debhelper-9.20150628/debian/changelog debhelper-9.20150628+nmu1/debian/changelog
--- debhelper-9.20150628/debian/changelog	2015-06-28 13:56:15.000000000 +0200
+++ debhelper-9.20150628+nmu1/debian/changelog	2015-08-02 17:10:43.000000000 +0200
@@ -1,3 +1,10 @@
+debhelper (9.20150628+nmu1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Support cross compilation in CMake buildsystem. (Closes: #-1)
+
+ -- Helmut Grohne <helmut at subdivi.de>  Sun, 02 Aug 2015 17:10:22 +0200
+
 debhelper (9.20150628) unstable; urgency=medium
 
   * Upload to unstable with ddebs support disabled by default.


More information about the debhelper-devel mailing list