-# A buildsystem plugin for handling CMake based projects.
-# It enforces outside-source building.
+# A debhelper build system class for handling CMake based projects.
+# It prefers out of source tree building.
#
# Copyright: © 2008-2009 Modestas Vainius
# License: GPL-2+
package Debian::Debhelper::Buildsystem::cmake;
use strict;
-use Debian::Debhelper::Dh_Lib;
use base 'Debian::Debhelper::Buildsystem::makefile';
-sub _add_cmake_flag {
- my ($self, $name, $val) = @_;
- push @{$self->{cmake_flags}}, "-D$name=$val";
-}
-
sub DESCRIPTION {
- "support for building CMake based packages (outside-source tree only)"
+ "CMake (CMakeLists.txt)"
}
-sub is_buildable {
- return -e "CMakeLists.txt";
+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(@_);
+ # 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.
+ $ret++ if ($ret && -e $this->get_buildpath("CMakeCache.txt"));
+ return $ret;
+ }
+ return 0;
}
sub new {
- my $cls=shift;
- my $self=$cls->SUPER::new(@_);
- # Enfore outside-source tree builds.
- $self->enforce_outside_source_building();
- $self->{cmake_flags} = [];
- return $self;
+ my $class=shift;
+ my $this=$class->SUPER::new(@_);
+ $this->prefer_out_of_source_building(@_);
+ return $this;
}
-sub configure_impl {
- my $self=shift;
+sub configure {
+ my $this=shift;
+ my @flags;
# Standard set of cmake flags
- $self->_add_cmake_flag("CMAKE_INSTALL_PREFIX", "/usr");
- $self->_add_cmake_flag("CMAKE_C_FLAGS", $ENV{CFLAGS}) if (exists $ENV{CFLAGS});
- $self->_add_cmake_flag("CMAKE_CXX_FLAGS", $ENV{CXXFLAGS}) if (exists $ENV{CXXFLAGS});
- $self->_add_cmake_flag("CMAKE_SKIP_RPATH", "ON");
- $self->_add_cmake_flag("CMAKE_VERBOSE_MAKEFILE", "ON");
- # TODO: LDFLAGS
-
- doit("cmake", $self->get_topdir(), @{$self->{cmake_flags}}, @_);
+ push @flags, "-DCMAKE_INSTALL_PREFIX=/usr";
+ push @flags, "-DCMAKE_VERBOSE_MAKEFILE=ON";
+
+ $this->mkdir_builddir();
+ $this->doit_in_builddir("cmake", $this->get_source_rel2builddir(), @flags, @_);
+}
+
+sub test {
+ my $this=shift;
+
+ $ENV{CTEST_OUTPUT_ON_FAILURE} = 1;
+ return $this->SUPER::test(@_);
}
-1;
+1