Name
SPVM::Builder::Config - Configurations of Compile and Link of Native Sources
Usage
use SPVM::Builder::Config;
# Create a config
my $config = SPVM::Builder::Config->new(file => __FILE__);
# Create a SPVM::Builder::Config object with "C99"
my $config = SPVM::Builder::Config->new_c99(file => __FILE__);
# Create a SPVM::Builder::Config object with "GNU99"
my $config = SPVM::Builder::Config->new_gnu99(file => __FILE__);
# Create a SPVM::Builder::Config object as "C++"
my $config = SPVM::Builder::Config->new_cpp(file => __FILE__);
# Create a SPVM::Builder::Config object with "C++11" standard of "C++"
my $config = SPVM::Builder::Config->new_cpp11(file => __FILE__);
# Optimize
$config->optimize('-O2');
# Optimize with debug mode
$config->optimize('-O0 -g');
# Adds source files
$config->add_source_file('foo.c', 'bar.c', 'baz/baz.c');
# Uses resource
$config->use_resource('TestCase::Resource::Zlib');
$config->use_resource('TestCase::Resource::Foo1', mode => 'mode1', argv => ['args1', 'args2']);
# Gets resouce information
my $resource = $config->get_resource('TestCase::Resource::Zlib');
Description
SPVM::Builder::Config
is configuration of c/c++ compile and link.
Fields
ext
my $ext = $config->ext;
$config->ext($ext);
Gets and sets 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);
Gets and sets a compiler name. The default is the value of cc
of Config class.
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});
include_dirs
my $include_dirs = $config->include_dirs;
$config->include_dirs($include_dirs);
Gets and sets header including directories of the compiler. This is same as -I
option of gcc
.
This field is an array reference.
spvm_core_include_dir
my $spvm_core_include_dir = $config->spvm_core_include_dir;
$config->spvm_core_include_dir($spvm_core_include_dir);
Gets and sets the header including directory of the SPVM core.
Default:
The header including directory of the SPVM core is created from the class file of the loaded SPVM::Builder::Config class.
The value looks like path/SPVM/Builder/include
.
native_include_dir
my $native_include_dir = $config->native_include_dir;
$config->native_include_dir($native_include_dir);
Gets and sets the path of the header including directory of this native class.
Default:
If the "file" field is defined, the path of the header including directory is created from the "file" field.
The value looks like path/Foo.native/include
.
native_src_dir
my $native_src_dir = $config->native_src_dir;
$config->native_src_dir($native_src_dir);
Gets and sets the path of the source directory of this native class.
Default:
If the "file" field is defined, the path of the source directory is created from the "file" field.
The value looks like path/Foo.native/src
.
ccflags
my $ccflags = $config->ccflags;
$config->ccflags($ccflags);
Gets and sets compiler flags.
Default:
# $Config{cccdlflags} has -fPIC.
['-fPIC']
# Other
[]
optimize
my $optimize = $config->optimize;
$config->optimize($optimize);
Gets and sets the option for optimization of the compiler.
The default is -O3
.
Examples:
$config->optimize('-O3');
$config->optimize('-O2');
$config->optimize('-g3 -O0');
source_files
my $source_files = $config->source_files;
$config->source_files($source_files);
Gets and sets source files. The file name is the relative pass from "native_src_dir".
Examples:
$config->source_files(['foo.c', 'bar.c']);
before_compile_cbs
my $before_compile_cbs = $config->before_compile_cbs;
$config->before_compile_cbs($before_compile_cbs);
Gets and sets the callbacks called before a compilation.
Examples:
$config->before_compile_cbs([sub {
my ($config, $compile_info) = @_;
my $cc = $compile_info->cc;
# Do something
}]);
before_link_cbs
my $before_link_cbs = $config->before_link_cbs;
$config->before_link_cbs($before_link_cbs);
Gets and sets the callbacks called before a link.
Examples:
$config->before_link_cbs([sub {
my ($config, $link_info) = @_;
my $object_files = $link_info->object_files;
# Do something
}]);
ld
my $ld = $config->ld;
$config->ld($ld);
Gets and sets a linker.
Default:
The ld
of Config class.
lib_dirs
my $lib_dirs = $config->lib_dirs;
$config->lib_dirs($lib_dirs);
Gets and sets 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);
Gets and sets library names or SPVM::Builder::LibInfo objects. These libraries are linked by "link" in SPVM::Builder::CC method.
ldflags
my ldflags = $config->ldflags;
$config->ldflags(ldflags);
Gets and sets linker flags. The default value is an emtpy array reference.
dynamic_lib_ldflags
my dynamic_lib_ldflags = $config->dynamic_lib_ldflags;
$config->dynamic_lib_ldflags(dynamic_lib_ldflags);
Gets and sets linker flags for dynamic link.
Default:
Windows
['-mdll', '-s']
Non-Windows
['-shared']
ld_optimize
my $ld_optimize = $config->ld_optimize;
$config->ld_optimize($ld_optimize);
Gets and sets 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);
Gets and sets the flag to force compiles and links without caching. The default is undef.
undef means forcing is not determined by config.
quiet
my $quiet = $config->quiet;
$config->quiet($quiet);
Gets and sets the flag if the compiler and the linker output the results.
The default is undef. undef means quietness is not determined by config.
class_name
my $class_name = $config->class_name;
$config->class_name($class_name);
Gets and sets the name of the class to use this config.
file
my $file = $config->file;
$config->file($file);
Gets and sets the config file path.
The default is 1.
file_optional
my $file_optional = $config->file_optional;
$config->file_optional($file_optional);
Gets and sets the value that indicates file field is needed for new|/"new"
method.
The default is 0.
output_type
my $output_type = $config->output_type;
$config->output_type($type);
Class Methods
new
my $config = SPVM::Builder::Config->new(file => __FILE__);
Create a SPVM::Builder::Config
object.
"file" must be specified except for the case that "file_optional" is set to a true value.
new_c
my $config = SPVM::Builder::Config->new_c(file => __FILE__);
Calls "new". After that, call ext('c').
new_c99
my $config = SPVM::Builder::Config->new_c99(file => __FILE__);
Calls "new_c". After that, call set_std('c99').
new_c11
my $config = SPVM::Builder::Config->new_c11(file => __FILE__);
Calls "new_c". After that, call set_std('c11').
new_gnu99
my $config = SPVM::Builder::Config->new_gnu99(file => __FILE__);
Calls "new_c". After that, call set_std('gnu99').
new_gnu11
my $config = SPVM::Builder::Config->new_gnu11(file => __FILE__);
Calls "new_c". After that, call set_std('gnu11').
new_cpp
my $config = SPVM::Builder::Config->new_cpp(file => __FILE__);
Calls "new". After that, call ext('cpp') and set "cc" to C++
compiler, and set "ld" to C++
linker.
new_cpp11
my $config = SPVM::Builder::Config->new_cpp11(file => __FILE__);
Calls "new_cpp". After that, call set_std('c++11').
new_cpp14
my $config = SPVM::Builder::Config->new_cpp14(file => __FILE__);
Calls "new_cpp". After that, call set_std('c++14').
new_cpp17
my $config = SPVM::Builder::Config->new_cpp17(file => __FILE__);
Calls "new_cpp". After that, call set_std('c++17').
Instance Methods
set_std
$config->set_std($std);
Adds the value that is converted to -std=$std
after the last element of "ccflags" field.
Example:
$config->set_std('gnu99');
add_ccflag
$config->add_ccflag(@ccflags);
Adds values after the last element of "ccflags" field.
add_ldflag
$config->add_ldflag(@ldflags);
Adds values after the last element of "ldflags" field.
add_include_dir
$config->add_include_dir(@include_dirs);
Adds values after the last element of "include_dirs" field.
add_lib_dir
$config->add_lib_dir(@lib_dirs);
Adds values after the last element of lib_dirs
field.
add_source_file
$config->add_source_file(@source_files);
Adds elements after the last element of "source_files" field.
add_before_compile_cb
$config->add_before_compile_cb(@before_compile_cbs);
Adds elements after the last element of "before_compile_cbs" field.
add_before_compile_cb
$config->add_before_link_cb(@before_link_cbs);
Adds elements after the last element of "before_link_cbs" field.
add_lib
$config->add_lib(@libs);
Adds library names or SPVM::Builder::LibInfo objects after the last element of "libs" field.
Examples:
$config->add_lib('gsl');
$config->add_lib('gsl', 'z');
$config->add_lib(
SPVM::Builder::LibInfo->new(name => 'gsl'),
SPVM::Builder::LibInfo->new(name => 'z', abs => 1),
);
add_static_lib
$config->add_static_lib(@libs);
Adds library names or SPVM::Builder::LibInfo objects after the last element of "libs" field.
static
field is set to a true value.
Examples:
$config->add_static_lib('gsl');
$config->add_static_lib('gsl', 'z');
$config->add_static_lib(
SPVM::Builder::LibInfo->new(name => 'gsl'),
SPVM::Builder::LibInfo->new(name => 'z', abs => 1),
);
use_resource
my $resource = $config->use_resource($resource_name);
my $resource = $config->use_resource($resource_name, %options);
Loads a resource by the resource name $resource_name using the SPVM::Builder::Resource method in the SPVM::Builder::Resource class, and returns a SPVM::Builder::Resource object. my $resource = SPVM::Builder::Resource->new(class_name => $resource_name); $config->use_resource($resource);
If the options %options are given, they are used as the options of the SPVM::Builder::Resource method in the SPVM::Builder::Resource class.
my $resource = SPVM::Builder::Resource->new(
class_name => 'Resource::Zlib',
mode => 'production',
argv => ['foo', 'bar'],
);
$config->use_resource($resource);
Examples:
$config->use_resource('Resource::Zlib');
get_resource_names
my $resource_names = $config->get_resource_names;
Gets resource names loaded by the L/"use_resource/"> method.
load_config
my $config = $config->load_config($config_file, @argv);
Loads a config file, and returns a SPVM::Builder::Config object. The argument @argv is set to the @ARGV of the config file.
load_base_config
my $config = $config->load_base_config($config_file, @argv);
Loads a base config file like Foo.config
. This method is the alias for the following method call using "load_mode_config".
my $config = $config->load_mode_config($config_file, undef, @argv);
load_mode_config
my $config = $config->load_mode_config($config_file, $mode, @argv);
Loads a mode config file like Foo.mode.config
.
At first, removes the string matching the regex (\.[^\.]+)?\.config$
from the base name of the config file $config_file.
Next, if the mode $mode is defined, .$mode.config
is added to the $config_file. Otherwise .config
is added.
Last, "load_config" is called with the modified name of the config file.
get_loaded_config_files
Gets the config files loaded by the "load_config" method.
clone
my $clone = $self->clone;
Clones the SPVM::Builder::Config object, and returns it.
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License