I have been fiddling for a while with a Perl project that uses MySQL's C++ code as a library. It uses a Perl library called MakeMaker to generate a G++ compatible Makefile which is dependent on the MySQL source.
The following code is the Perl code that is used to generate a Makefile (source file on Github) :
use ExtUtils::MakeMaker;
use strict;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
if ($ARGV[0] eq '') {
print "Usage: perl Makefile.PL \"<MySQL source path>\"\n";
exit 1;
}
my $mysql_path = $ARGV[0].'/';
my $check_file = $mysql_path."libmysqld/libmysqld.a";
if (! -e $check_file) {
print "File $check_file does not exist: $!. Please try again.\n";
exit 1;
}
my $makefile_path = $mysql_path.'/libmysql/Makefile';
my $libmysqld_path = $mysql_path.'/libmysqld/libmysqld.a';
if (! -e $libmysqld_path) {
print "$libmysqld_path does not exist. Did you run ./configure --with-embedded-server && make ? \n";
exit 1;
}
#
# CCFLAGS must be taken from the flags used to compile libmysqld. The reason for that is that if the flags are not
# identical, the THD class behaves differently in libmysqld than it does in my_parse_cc.cc, namely, the thd->command
# member is located in a different place in memory. No attempt was made to determine which compile flag causes this behavoir.
#
# Also, if we compile our stuff with DDEBUG and libmysqld.so is not compiled with DDEBUG, crap will result.
my $ccflags = `grep "^CXXFLAGS =" $makefile_path`;
$ccflags =~ s{^CXXFLAGS = }{}sio;
$ccflags =~ s{[\r\n\t]}{}sio;
$ccflags .= " -DNO_EMBEDDED_ACCESS_CHECKS ";
print "CCFLAGS = $ccflags\n";
my $libs = '-L'.$mysql_path.'/libmysql -L'.$mysql_path.'/libmysqld -lmysqld -lz -lpthread -lcrypt -lnsl -lm -lpthread -lc -lnss_files -lnss_dns -lresolv -lc -lnss_files -lnss_dns -lresolv -lrt';
print "LIBS = $libs\n";
WriteMakefile(
NAME => 'DBIx::MyParse',
VERSION_FROM => 'lib/DBIx/MyParse.pm', # finds $VERSION
ABSTRACT_FROM => 'lib/DBIx/MyParse.pm',
AUTHOR => 'Philip Stoev <philip@stoev.org>',
LIBS => qq{-L$mysql_path/libmysqld -L$mysql_path/libmysql -lmysqld -lz }.$libs,
'INC' => qq{-I. -I$mysql_path -I$mysql_path/sql -I$mysql_path/include -I$mysql_path/regex},
CCFLAGS => '-DEMBEDDED_LIBRARY -DMYSQL_SERVER -Wall '.$ccflags,
OBJECT => 'my_enum.o my_define.o my_parse_c.o my_parse_cc.o MyParse.o',
LD => 'g++',
CC => 'g++',
depend => {
'my_parse_cc.cc' => 'my_parse.h',
'my_parse_cc.cc' => 'my_define.h',
'my_parse_cc.cc' => 'my_enum.h',
'my_enum.o' => 'my_enum.c',
'my_enum.o' => 'my_enum.h',
'my_enum.0' => ' my_parse.h',
'my_define.o' => 'my_define.h',
'my_define.o' => 'my_define.c',
'my_define.o' => 'my_parse.h',
'my_enum.h' => "parse_enum.pl
perl parse_enum.pl $mysql_path
",
'my_enum_priv.h' => "parse_enum.pl
perl parse_enum.pl $mysql_path
",
'my_define.h' => "parse_define.pl
perl parse_define.pl $mysql_path
",
'my_define.c' => "parse_define.pl
perl parse_define.pl $mysql_path
",
'my_enum.c' => "parse_define.pl
perl parse_enum.pl $mysql_path
"},
clean =>
{FILES => "my_enum_priv.h my_enum.h my_define.h my_define.c my_enum.c"}
);
I would now like to make this project evolve and use MariaDB instead of MySQL. However MariaDB is compiled using cmake, not g++. As a result I cannot use MakeMaker anymore for MariaDB. I would like to know if there is a similar tool for a source compiled using cmake. Another option would be, if such thing exists, to link the Perl project to the MySQL source in another way.
Edit : So far I haven't tried anything as I don't know whether such a tool exists in Perl (I haven't found any trace of it on the Web but I may not have the right keywords). If it doesn't, how could I achieve my original goal which is to use the MariaDB source in a Perl or C++ code, like it was done with MySQL with the previous code ?