Automatically detect flavor based on .cmake/.meson file extensions

This commit is contained in:
Boris Kolpackov 2021-11-05 08:36:34 +02:00
parent 8e355c01d0
commit a2e1f8a7d9
4 changed files with 32 additions and 12 deletions

View File

@ -92,7 +92,7 @@ cat config.h >>EOO
:
mkdir build;
ln -s ../../bootstrap.build ../../root.build build/;
cat <<EOI >=config.h.in;
cat <<EOI >=config.h.cmake;
#define VERSION "@version@"
#cmakedefine TRUE
@ -115,10 +115,8 @@ cat <<EOI >=config.h.in;
#cmakedefine zzz_TEST_DUMMY2_H
EOI
$* <<EOI &config.h &config.h.d;
./: h{config}: in{config}
./: h{config}: in{config.h.cmake}
{
autoconf.flavor = cmake
TRUE = true
FALSE = [bool] false
ONE = 1

View File

@ -60,8 +60,6 @@ lib{build2-autoconf}: {hxx ixx txx cxx}{* -checks} {hxx cxx}{checks} \
\"\"
EOI
# @@ TODO: add \n once sed supports it.
#
cat $i | sed -n \
-e 's|^// ([^ ]+) *$|},\n\n{\n"\1",\n|p' \
-e 's|^(.*)\\$|"\1\\\\\\n"|p' \

View File

@ -4,6 +4,8 @@
#include <libbuild2/algorithm.hxx>
#include <libbuild2/diagnostics.hxx>
#include <libbuild2/in/target.hxx>
#include <libbuild2/autoconf/checks.hxx>
using namespace std;
@ -34,22 +36,44 @@ namespace build2
recipe rule::
apply (action a, target& t) const
{
recipe r (in::rule::apply (a, t));
// Determine and cache the configuration file flavor.
//
flavor f (flavor::autoconf);
if (const string* s = cast_null<string> (t["autoconf.flavor"]))
{
if (*s == "cmake")
f = flavor::cmake;
else if (*s == "meson")
f = flavor::meson;
if (*s == "cmake") f = flavor::cmake;
else if (*s == "meson") f = flavor::meson;
else if (*s != "autoconf")
fail << "invalid configuration file flavor '" << *s << "'";
}
else
{
// If the in{} file extension is either .cmake or .meson, then
// use that as the flavor.
//
for (const target* pt: t.prerequisite_targets[a])
{
if (pt != nullptr)
{
if (const auto* it = pt->is_a<in::in> ())
{
string e (it->path ().extension ());
if (e == "cmake") f = flavor::cmake;
else if (e == "meson") f = flavor::meson;
break;
}
}
}
}
t.data (match_data {f});
return in::rule::apply (a, t);
return r;
}
void rule::

View File

@ -9,7 +9,7 @@ namespace build2
{
namespace autoconf
{
// Process a config.h.in file.
// Process a config.h.{in,cmake,meson} file.
//
// Note that to be usable as a drop-in replacement we make the default
// substitution symbol '@' and the mode -- lax. The user, however, is