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