]> git.donarmstrong.com Git - debhelper.git/blob - Debian/Debhelper/Buildsystem/cmake.pm
releasing version 9.20120419
[debhelper.git] / Debian / Debhelper / Buildsystem / cmake.pm
1 # A debhelper build system class for handling CMake based projects.
2 # It prefers out of source tree building.
3 #
4 # Copyright: © 2008-2009 Modestas Vainius
5 # License: GPL-2+
6
7 package Debian::Debhelper::Buildsystem::cmake;
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib qw(compat);
11 use base 'Debian::Debhelper::Buildsystem::makefile';
12
13 sub DESCRIPTION {
14         "CMake (CMakeLists.txt)"
15 }
16
17 sub check_auto_buildable {
18         my $this=shift;
19         my ($step)=@_;
20         if (-e $this->get_sourcepath("CMakeLists.txt")) {
21                 my $ret = ($step eq "configure" && 1) ||
22                           $this->SUPER::check_auto_buildable(@_);
23                 # Existence of CMakeCache.txt indicates cmake has already
24                 # been used by a prior build step, so should be used
25                 # instead of the parent makefile class.
26                 $ret++ if ($ret && -e $this->get_buildpath("CMakeCache.txt"));
27                 return $ret;
28         }
29         return 0;
30 }
31
32 sub new {
33         my $class=shift;
34         my $this=$class->SUPER::new(@_);
35         $this->prefer_out_of_source_building(@_);
36         return $this;
37 }
38
39 sub configure {
40         my $this=shift;
41         my @flags;
42
43         # Standard set of cmake flags
44         push @flags, "-DCMAKE_INSTALL_PREFIX=/usr";
45         push @flags, "-DCMAKE_VERBOSE_MAKEFILE=ON";
46
47         # CMake doesn't respect CPPFLAGS, see #653916.
48         if ($ENV{CPPFLAGS} && ! compat(8)) {
49                 $ENV{CFLAGS}   .= ' ' . $ENV{CPPFLAGS};
50                 $ENV{CXXFLAGS} .= ' ' . $ENV{CPPFLAGS};
51         }
52
53         $this->mkdir_builddir();
54         eval { 
55                 $this->doit_in_builddir("cmake", $this->get_source_rel2builddir(), @flags, @_);
56         };
57         if ($@) {
58                 if (-e $this->get_buildpath("CMakeCache.txt")) {
59                         $this->doit_in_builddir("tail -v -n +0 CMakeCache.txt");
60                 }
61                 die $@;
62         }
63 }
64
65 sub test {
66         my $this=shift;
67
68         # Unlike make, CTest does not have "unlimited parallel" setting (-j implies
69         # -j1). So in order to simulate unlimited parallel, allow to fork a huge
70         # number of threads instead.
71         my $parallel = ($this->get_parallel() > 0) ? $this->get_parallel() : 999;
72         $ENV{CTEST_OUTPUT_ON_FAILURE} = 1;
73         return $this->SUPER::test(@_, "ARGS+=-j$parallel");
74 }
75
76 1