summaryrefslogtreecommitdiff
path: root/lib/Debian/Debhelper/Buildsystem/cmake.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Debian/Debhelper/Buildsystem/cmake.pm')
-rw-r--r--lib/Debian/Debhelper/Buildsystem/cmake.pm61
1 files changed, 45 insertions, 16 deletions
diff --git a/lib/Debian/Debhelper/Buildsystem/cmake.pm b/lib/Debian/Debhelper/Buildsystem/cmake.pm
index 5e3ce082..c732ba41 100644
--- a/lib/Debian/Debhelper/Buildsystem/cmake.pm
+++ b/lib/Debian/Debhelper/Buildsystem/cmake.pm
@@ -9,7 +9,7 @@ package Debian::Debhelper::Buildsystem::cmake;
use strict;
use warnings;
use Debian::Debhelper::Dh_Lib qw(compat dpkg_architecture_value error is_cross_compiling);
-use parent qw(Debian::Debhelper::Buildsystem::makefile);
+use parent qw(Debian::Debhelper::Buildsystem);
my @STANDARD_CMAKE_FLAGS = qw(
-DCMAKE_INSTALL_PREFIX=/usr
@@ -27,16 +27,35 @@ my %DEB_HOST2CMAKE_SYSTEM = (
'hurd' => 'GNU',
);
+my %TARGET_BUILD_SYSTEM2CMAKE_GENERATOR = (
+ 'makefile' => 'Unix Makefiles',
+ 'ninja' => 'Ninja',
+);
+
sub DESCRIPTION {
"CMake (CMakeLists.txt)"
}
+sub IS_GENERATOR_BUILD_SYSTEM {
+ return 1;
+}
+
+sub SUPPORTED_TARGET_BUILD_SYSTEMS {
+ return qw(makefile ninja);
+}
+
sub check_auto_buildable {
my $this=shift;
my ($step)=@_;
if (-e $this->get_sourcepath("CMakeLists.txt")) {
my $ret = ($step eq "configure" && 1) ||
- $this->SUPER::check_auto_buildable(@_);
+ $this->get_targetbuildsystem->check_auto_buildable(@_);
+ if ($this->check_auto_buildable_clean_oos_buildir(@_)) {
+ # Assume that the package can be cleaned (i.e. the build directory can
+ # be removed) as long as it is built out-of-source tree and can be
+ # configured.
+ $ret++ if not $ret;
+ }
# Existence of CMakeCache.txt indicates cmake has already
# been used by a prior build step, so should be used
# instead of the parent makefile class.
@@ -57,11 +76,22 @@ sub configure {
my $this=shift;
# Standard set of cmake flags
my @flags = @STANDARD_CMAKE_FLAGS;
+ my $backend = $this->get_targetbuildsystem->NAME;
if (not compat(10)) {
push(@flags, '-DCMAKE_INSTALL_RUNSTATEDIR=/run');
}
+ if (exists($TARGET_BUILD_SYSTEM2CMAKE_GENERATOR{$backend})) {
+ my $generator = $TARGET_BUILD_SYSTEM2CMAKE_GENERATOR{$backend};
+ push(@flags, "-G${generator}");
+ }
+ if ($ENV{CC}) {
+ push @flags, "-DCMAKE_C_COMPILER=" . $ENV{CC};
+ }
+ if ($ENV{CXX}) {
+ push @flags, "-DCMAKE_CXX_COMPILER=" . $ENV{CXX};
+ }
if (is_cross_compiling()) {
my $deb_host = dpkg_architecture_value("DEB_HOST_ARCH_OS");
if (my $cmake_system = $DEB_HOST2CMAKE_SYSTEM{$deb_host}) {
@@ -70,20 +100,16 @@ sub configure {
error("Cannot cross-compile - CMAKE_SYSTEM_NAME not known for ${deb_host}");
}
push @flags, "-DCMAKE_SYSTEM_PROCESSOR=" . dpkg_architecture_value("DEB_HOST_GNU_CPU");
- if ($ENV{CC}) {
- push @flags, "-DCMAKE_C_COMPILER=" . $ENV{CC};
- } else {
+ if (not $ENV{CC}) {
push @flags, "-DCMAKE_C_COMPILER=" . dpkg_architecture_value("DEB_HOST_GNU_TYPE") . "-gcc";
}
- if ($ENV{CXX}) {
- push @flags, "-DCMAKE_CXX_COMPILER=" . $ENV{CXX};
- } else {
+ if (not $ENV{CXX}) {
push @flags, "-DCMAKE_CXX_COMPILER=" . dpkg_architecture_value("DEB_HOST_GNU_TYPE") . "-g++";
}
push(@flags, "-DPKG_CONFIG_EXECUTABLE=/usr/bin/" . dpkg_architecture_value("DEB_HOST_GNU_TYPE") . "-pkg-config");
push(@flags, "-DPKGCONFIG_EXECUTABLE=/usr/bin/" . dpkg_architecture_value("DEB_HOST_GNU_TYPE") . "-pkg-config");
- push(@flags, "-DCMAKE_INSTALL_LIBDIR=lib/" . dpkg_architecture_value("DEB_HOST_MULTIARCH"));
}
+ push(@flags, "-DCMAKE_INSTALL_LIBDIR=lib/" . dpkg_architecture_value("DEB_HOST_MULTIARCH"));
# CMake doesn't respect CPPFLAGS, see #653916.
if ($ENV{CPPFLAGS} && ! compat(8)) {
@@ -93,7 +119,7 @@ sub configure {
$this->mkdir_builddir();
eval {
- $this->doit_in_builddir("cmake", $this->get_source_rel2builddir(), @flags, @_);
+ $this->doit_in_builddir("cmake", @flags, @_, $this->get_source_rel2builddir());
};
if (my $err = $@) {
if (-e $this->get_buildpath("CMakeCache.txt")) {
@@ -111,13 +137,16 @@ sub configure {
sub test {
my $this=shift;
-
- # Unlike make, CTest does not have "unlimited parallel" setting (-j implies
- # -j1). So in order to simulate unlimited parallel, allow to fork a huge
- # number of threads instead.
- my $parallel = ($this->get_parallel() > 0) ? $this->get_parallel() : 999;
+ my $target = $this->get_targetbuildsystem;
$ENV{CTEST_OUTPUT_ON_FAILURE} = 1;
- return $this->SUPER::test(@_, "ARGS+=-j$parallel");
+ if ($target->NAME eq 'makefile') {
+ # Unlike make, CTest does not have "unlimited parallel" setting (-j implies
+ # -j1). So in order to simulate unlimited parallel, allow to fork a huge
+ # number of threads instead.
+ my $parallel = ($this->get_parallel() > 0) ? $this->get_parallel() : 999;
+ push(@_, "ARGS+=-j$parallel")
+ }
+ return $this->SUPER::test(@_);
}
1