NAME
SPVM::Builder::Config - Configurations of Compile and Link of Native Sources
DESCRIPTION
SPVM::Builder::Config is configuration of c/c++ compile and link.
FIELDS
Fields.
ext
my $ext = $config->ext;
$config->ext($ext);
Get and set the extension of the SPVM native source.
The default is undef
.
Examples:
# Foo/Bar.c
$config->ext('c');
# Foo/Bar.cpp
$config->ext('cpp');
cc
my $cc = $config->cc;
$config->cc($cc);
Get and set a compiler name. The default is the value of cc
of Config module.
Examples:
# gcc
$config->cc('gcc');
# g++ for C++
$config->cc('g++');
# nvcc for CUDA/GUP
$config->cc('nvcc');
# cc that compiled this Perl
use Config;
$config->cc($Config{cc});
cc_each
my $cc_each = $config->cc_each;
$config->cc_each($cc_each);
Get and set a callback that returns the compiler name for each source file. The call back receives SPVM::Bulder::Config object and optional arguments as a hash reference.
Optional Arguments:
source_file
Each source file.
class_name
The class name
If cc_each
is defined, the compiler use the return value of cc_each
as the compiler name instead of cc
.
Examples:
$config->cc_each(sub {
my ($config, $args) = @_;
# Source file
my $source_file = $args->{source_file};
# Class name
my $class_name = $args->{class_name}
my $cc;
# C source file
if ($source_file =~ /\.c$/) {
$cc = 'gcc';
}
# C++ source file
elsif ($source_file =~ /\.cpp$/) {
$cc = 'g++';
}
return $cc;
});
include_dirs
my $include_dirs = $config->include_dirs;
$config->include_dirs($include_dirs);
Get and set header including directories of the compiler. This is same as -I
option of gcc
.
The default value is "SPVM/Builder/include" of one up of directory that SPVM::Buidler::Config.pm is loaded.
At runtime, the "include" directory of the native module is added before include_dirs
.
ccflags
my $ccflags = $config->ccflags;
$config->ccflags($ccflags);
Get and set compiler flags.
Default:
# $Config{cccdlflags} has -fPIC.
['-fPIC']
# Other
[]
ccflags_each
my $ccflags_each = $config->ccflags_each;
$config->ccflags_each($ccflags_each);
Get and set a callback that returns the compiler flags for each source file. The call back receives SPVM::Bulder::Config object and optional arguments as a hash reference.
Optional Arguments:
source_file
Each source file.
class_name
The class name
cc
The compiler name that is the value after the process of the process of cc or cc_each.
If ccflags_each
is defined, the compiler use the return value of ccflags_each
as the compiler flags instead of ccflags
.
Examples:
$config->ccflags_each(sub {
my ($config, $source_file) = @_;
# Source file
my $source_file = $args->{source_file};
# Class name
my $class_name = $args->{class_name}
# The compiler name
my $cc = $args->{cc};
# ccflags
my $config_ccflags = $config->ccflags;
my $ccflags = [];
# C source file
if ($source_file =~ /\.c$/) {
$ccflags = ['-DFoo', @$config_ccflags];
}
# C++ source file
elsif ($source_file =~ /\.cpp$/) {
$ccflags = ['-DBar', @$config_ccflags];
}
return $ccflags;
});
optimize
my $optimize = $config->optimize;
$config->optimize($optimize);
Get and set the option for optimization of the compiler.
The default is -O3
.
Examples:
$config->optimize('-O3');
$config->optimize('-O2');
$config->optimize('-g3 -O0');
optimize_each
my $optimize_each = $config->optimize_each;
$config->optimize_each($optimize_each);
Get and set a callback that returns the value of optimize for each source file. The callback receives SPVM::Bulder::Config object and optional arguments as a hash reference.
Optional Arguments:
source_file
Each source file.
class_name
The class name
cc
The compiler name that is the value after the process of the process of cc or cc_each.
If optimize_each
is defined, the compiler use the return value of optimize_each
as the compiler flags instead of optimize
.
Examples:
$config->optimize_each(sub {
my ($config, $source_file) = @_;
# Source file
my $source_file = $args->{source_file};
# Class name
my $class_name = $args->{class_name}
# The compiler name
my $cc = $args->{cc};
# optimize
my $config_optimize = $config->optimize;
my $optimize = [];
# C source file
if ($source_file =~ /\.c$/) {
$optimize = '-O3';
}
# C++ source file
elsif ($source_file =~ /\.cpp$/) {
$optimize = '-O3';
}
return $optimize;
});
source_files
my $source_files = $config->source_files;
$config->source_files($source_files);
Get and get source files. These sourceraries are linked by the compiler.
Examples:
$config->source_files(['foo.c', 'bar.c']);
ld
my $ld = $config->ld;
$config->ld($ld);
Get and set a linker. Default is ld
of Config module.
lib_dirs
my $lib_dirs = $config->lib_dirs;
$config->lib_dirs($lib_dirs);
Get and set the directories that libraries are searched for by the linker. This is same as -L
option of gcc
.
Default:
Windows
The directory that perlxxx.dll exists
Not Windows
empty list
libs
my $libs = $config->libs;
$config->libs($libs);
Get and set libraries. These libraries are linked by the linker.
If a dynamic link library is found from "lib_dirs", this is linked. Otherwise if a static link library is found from "lib_dirs", this is linked.
Examples:
$config->libs(['gsl', 'png']);
If you want to link only dynamic link library, you can use the following hash reference as the value of the element instead of the library name.
{type => 'dynamic', name => 'gsl'}
If you want to link only static link library, you can use the following hash reference as the value of the element instead of the library name.
{type => 'static', name => 'gsl'}
resources
my $resources = $config->resources;
$config->resources($resources);
Get and get resouce module names.
At runtime, each modules' native "include" directory is added before include_dirs
, and "lib" directory is added before lib_dirs
.
Examples:
$config->resources(['SPVM::Resouce::Zlib::V1_15']);
ldflags
my ldflags = $config->ldflags;
$config->ldflags(ldflags);
Get and set linker flags. The default is emtpy array reference.
Default:
Windows
['-mdll', '-s']
Non-Windows
['-shared']
ld_optimize
my $ld_optimize = $config->ld_optimize;
$config->ld_optimize($ld_optimize);
Get and set the option for optimization of the linker such as -O3
, -O2
, -g3 -O0
.
The default is -O2
.
force
my $force = $config->force;
$config->force($force);
Get and set the flag to force compiles and links without caching.
before_link
my $before_link = $config->before_link;
$config->before_link($before_link);
Get and set the callback that is executed before the link. The callback receives SPVM::Builder::Config object and the SPVM::Builder::LinkInfo object used by the linker.
Examples:
$config->before_link(sub {
my ($config, $link_info) = @_;
my $object_file_infos = $link_info->object_file_infos;
# Do something
});
quiet
my $quiet = $config->quiet;
$config->quiet($quiet);
Get and set the flag if the compiler and the linker output the results.
The default is 1
.
Methods
new
my $config = SPVM::Builder::Config->new;
Create SPVM::Builder::Config object.
new_c
my $config = SPVM::Builder::Config->new_c;
Create default build config with C settings. This is SPVM::Builder::Config object.
If you want to use the specific C version, use set_std
method.
$config->set_std('c99');
new_c99
my $config = SPVM::Builder::Config->new_gnu99;
Create default build config with C99 settings. This is SPVM::Builder::Config object.
new_cpp
my $config = SPVM::Builder::Config->new_cpp;
Create default build config with C++ settings. This is SPVM::Builder::Config object.
If you want to use the specific C++ version, use set_std
method.
$config->set_std('c++11');
new_cpp11
my $config = SPVM::Builder::Config->new_cpp11;
Create default build config with C++11 settings. This is SPVM::Builder::Config object.
set_std
$config->set_std($std);
Add the value that is converted to -std=$std
after the last element of ccflags
field.
Example:
$config->set_std('gnu99');
add_ccflags
$config->add_ccflags(@ccflags);
Add values after the last element of ccflags
field.
add_ldflags
$config->add_ldflags(@ldflags);
Add values after the last element of ldflags
field.
add_include_dirs
$config->add_include_dirs(@include_dirs);
Add values after the last element of include_dirs
field.
add_lib_dirs
$config->add_lib_dirs(@lib_dirs);
Add values after the last element of lib_dirs
field.
add_source_files
$config->add_source_files(@source_files);
Add the values after the last element of source_files
field.
add_libs
$config->add_libs(@libs);
Add the values after the last element of libs
field.
Examples:
$config->add_libs('gsl');
add_static_libs
$config->add_static_libs(@libs);
Add the values that each element is converted to the following hash reference after the last element of libs
field.
{type => 'static', name => $lib}
Examples:
$config->add_static_libs('gsl');
add_dynamic_libs
$config->add_dynamic_libs(@libs);
Add the values that each element is converted to the following hash reference after the last element of libs
field.
{type => 'dynamic', name => $lib}
Examples:
$config->add_dynamic_libs('gsl');
use
$config->use(@resources);
This method is the alias for "add_resources" to improve user experiences.
Examples:
$config->use('SPVM::Resouce::Zlib::V1_15');
add_resources
$config->add_resources(@resources);
Add the values after the last element of resources
field.
Examples:
$config->add_resources('SPVM::Resouce::Zlib::V1_15');
to_hash
my $config = $config->to_hash;
Convert SPVM::Builder::Config to a hash reference.
search_lib_dirs_from_cc_info
my $lib_dirs = $config->search_lib_dirs_from_cc_info;
Get the library searching directories parsing the infomation the compiler has.
search_lib_dirs_from_config_libpth
my $lib_dirs = $config->search_lib_dirs_from_config_libpth;
Get the library searching directories parsing libpth
of Config.
search_include_dirs_from_config_incpth
my $include_dirs = $config->search_include_dirs_from_config_incpth;
Get the header searching directories parsing incpth
of Config.
sub get_include_dir
my $include_dir = $config->get_include_dir(__FILE__);
Get the header include directory from the config file name.
get_src_dir
my $src_dir = $config->get_src_dir(__FILE__);
Get the source directory from the config file name.
get_lib_dir
my $lib_dir = $config->get_lib_dir(__FILE__);
Get the library directory from the config file name.
is_exe
my $is_exe = $config->is_exe;
Check this config is used for creating executalbe file. Always 0.