class ActionTargetType(TargetType): """ Custom action script. *Action* targets execute arbitrary commands. They can be used to do various tasks that don't fit the model of compiling or creating files, such as packaging files, installing, uploading, running tests and so on. Actions are currently only supported by makefile-based toolsets. See the ``pre-build-commands`` and ``post-build-commands`` properties for another alternative that is supported by Visual Studio projects. If the optional ``outputs`` property is specified, the action is supposed to generate the files listed in this property. This means that other targets depending on this action will depend on these files in the generated makefile, instead of depending on the phony target for an action without outputs and also that these files will be cleaned up by the ``clean`` target of the generated makefile. .. code-block:: bkl action osx-bundle { deps = test; commands = "mkdir -p Test.app/Contents/MacOS" "cp -f test Test.app/Contents/MacOS/test" ; } """ name = "action" properties = [ Property("commands", type=ListType(StringType()), default=[], inheritable=False, doc="List of commands to run."), Property("outputs", type=ListType(PathType()), default=expr.NullExpr(), inheritable=False, doc="Output files created by this action, if any."), ] def get_build_subgraph(self, toolset, target): # prefix each line with @ so that make doesn't output the commands: cmds_var = target["commands"] cmds = add_prefix("@", cmds_var) node = BuildNode(commands=list(cmds), name=target["id"], outputs=target["outputs"], source_pos=cmds_var.pos) return BuildSubgraph(node)
def properties_target(cls): yield Property("%s.projectfile" % cls.name, type=PathType(), default=update_wrapper(partial(_project_name_from_solution, cls), _project_name_from_solution), inheritable=False, doc="File name of the project for the target.") yield Property("%s.guid" % cls.name, # TODO: use custom GUID type, so that user-provided GUIDs can be validated (and upper-cased) # TODO: make this vs.guid and share among VS toolsets type=StringType(), default=_default_guid_for_project, inheritable=False, doc="GUID of the project.")
class LoadableModuleType(NativeLinkedType): """ Runtime-loaded dynamic module (plugin). """ name = "loadable-module" properties = [ Property("basename", type=StringType(), default="$(id)", inheritable=False, doc=""" Base name of the loadable module. This is not full filename or even path, it's only its base part, to which platform-specific prefix and/or extension are added. By default, it's the same as target's ID, but it can be changed e.g. if the filename should contain version number, which would be impractical to use as target identifier in the bakefile. .. code-block:: bkl loadable-module myplugin { basename = myplugin-v1; } """), Property("extension", type=StringType(), default=NullExpr(), inheritable=False, doc=""" File extension of the module, including the leading dot. By default, native extension for shared libraries (e.g. ".dll" on Windows) is used. .. code-block:: bkl loadable-module excel_plugin { extension = .xll; } """), ] def get_build_subgraph(self, toolset, target): return get_compilation_subgraph( toolset, target, ft_to=NativeLoadableModuleFileType.get(), outfile=self.target_file(toolset, target))
def properties_module(cls): yield Property("%s.solutionfile" % cls.name, type=PathType(), default=_default_solution_name, inheritable=False, doc="File name of the solution file for the module.") yield Property("%s.generate-solution" % cls.name, type=BoolType(), default=True, inheritable=False, doc=""" Whether to generate solution file for the module. Set to ``false`` if you want to omit the solution, e.g. for some submodules with only a single target. """)
class LibraryType(NativeCompiledType): """ Static library. """ name = "library" properties = [ Property("basename", type=StringType(), default="$(id)", inheritable=False, doc=""" Library name. This is not full filename or even path, it's only its base part, to which platform-specific prefix (if applicable) and extension are added. By default, it's the same as target's ID, but it can be changed e.g. if the filename should contain version number, which would be impractical to use as target identifier in the bakefile. .. code-block:: bkl library foo { // use e.g. libfoo24.a on Unix and foo24.lib basename = foo$(vermajor)$(verminor); } """), ] def get_build_subgraph(self, toolset, target): return get_compilation_subgraph(toolset, target, ft_to=NativeLibFileType.get(), outfile=self.target_file( toolset, target))
class ExternalTargetType(TargetType): """ External build system. This target type is used to invoke makefiles or project files not implemented in Bakefile, for example to build 3rd party libraries. Currently, only Visual Studio projects (vcproj, vcxproj, csproj) are supported and only when using a Visual Studio toolset. """ name = "external" properties = [ Property("file", type=PathType(), inheritable=False, doc="File name of the external makefile or project."), ] def get_build_subgraph(self, toolset, target): return self.get_handler(target).get_build_subgraph(toolset, target) def vs_project(self, toolset, target): return self.get_handler(target).vs_project(toolset, target) def get_handler(self, target): with error_context(target["file"]): return ExternalBuildHandler.get_for_file(target["file"].as_native_path_for_output(target))
class ProgramType(NativeLinkedType): """ Executable program. """ name = "program" properties = [ Property("basename", type=StringType(), default="$(id)", inheritable=False, doc=""" Base name of the executable. This is not full filename or even path, it's only its base part, to which platform-specific extension is added. By default, it's the same as target's ID, but it can be changed e.g. if the filename should contain version number, which would be impractical to use as target identifier in the bakefile. .. code-block:: bkl program mytool { // use mytool2.exe or /usr/bin/mytool2 basename = $(id)$(vermajor); } """), Property("win32-subsystem", type=EnumType("subsystem", ["console", "windows"]), default="console", inheritable=True, doc=""" Windows subsystem the executable runs in. Must be set to ``windows`` for console-less applications. """), ] use_pic_by_default = False def get_build_subgraph(self, toolset, target): return get_compilation_subgraph(toolset, target, ft_to=NativeProgramFileType.get(), outfile=self.target_file( toolset, target))
class SharedLibraryType(NativeLinkedType): """ Dynamically loaded library. """ name = "shared-library" properties = [ Property("basename", type=StringType(), default="$(id)", inheritable=False, doc=""" Base name of the library. This is not full filename or even path, it's only its base part, to which platform-specific prefix and/or extension are added. By default, it's the same as target's ID, but it can be changed e.g. if the filename should contain version number, which would be impractical to use as target identifier in the bakefile. .. code-block:: bkl shared-library utils { // use myapp_utils.lib, myapp_utils.dll, libmyapp_utils.so basename = myapp_utils; } """), # TODO: add "libname" for the name of the import lib itself, when it differs from # DLL name # TODO: add libtool-style sonames support ] def get_build_subgraph(self, toolset, target): return get_compilation_subgraph( toolset, target, ft_to=NativeSharedLibraryFileType.get(), outfile=self.target_file(toolset, target))
class NativeCompiledType(TargetType): """Base class for natively-compiled targets.""" properties = [ Property("sources", type=ListType(PathType()), default=[], inheritable=False, doc="Source files."), Property("headers", type=ListType(PathType()), default=[], inheritable=False, doc="Header files."), Property("defines", type=ListType(StringType()), default=[], inheritable=True, doc="List of preprocessor macros to define."), Property("includedirs", type=ListType(PathType()), default=[], inheritable=True, doc="Directories where to look for header files."), Property("warnings", type=EnumType("warnings", ["no", "minimal", "default", "all", "max"]), default="default", inheritable=True, doc=""" Warning level for the compiler. Use ``no`` to completely disable warning, ``minimal`` to show only the most important warning messages, ``all`` to enable all warnings that usually don't result in false positives and ``max`` to enable absolutely all warnings. """), Property("compiler-options", type=ListType(StringType()), default=[], inheritable=True, doc=""" Additional compiler options common to all C-like compilers (C, C++, Objective-C, Objective-C++). Note that the options are compiler-specific and so this property should only be set conditionally for particular compilers that recognize the options. """), Property("c-compiler-options", type=ListType(StringType()), default=[], inheritable=True, doc=""" Additional options for C compiler. Note that the options are compiler-specific and so this property should only be set conditionally for particular compilers that recognize the options. """), Property("cxx-compiler-options", type=ListType(StringType()), default=[], inheritable=True, doc=""" Additional options for C++ compiler. Note that the options are compiler-specific and so this property should only be set conditionally for particular compilers that recognize the options. """), Property("libs", type=ListType(StringType()), default=[], inheritable=True, doc=""" Additional libraries to link with. Do not use this property to link with libraries built as part of your project; use `deps` for that. When this list is non-empty on a :ref:`ref_target_library`, it will be used when linking executables that use the library. """), Property("libdirs", type=ListType(PathType()), default=[], inheritable=True, doc=""" Additional directories where to look for libraries. When this list is non-empty on a :ref:`ref_target_library`, it will be used when linking executables that use the library. """), Property("link-options", type=ListType(StringType()), default=[], inheritable=True, doc=""" Additional linker options. Note that the options are compiler/linker-specific and so this property should only be set conditionally for particular compilers that recognize the options. When this list is non-empty on a :ref:`ref_target_library`, it will be used when linking executables that use the library. """), Property("archs", type=ListType(EnumType("architecture", ["x86", "x86_64"])), default=NullExpr(), inheritable=True, doc=""" Architectures to compile for. Adds support for building binaries for specified architectures, if supported by the toolset. Support may take the form of either multi-arch binaries (OS X) or additional build configurations (Visual Studio). The default empty value means to do whatever the default behavior of the toolset is. Currently only supported on OS X and in Visual Studio. """), Property("win32-crt-linkage", type=EnumType("linkage", ["static", "dll"]), default="dll", inheritable=True, doc=""" How to link against the C Runtime Library. If ``dll`` (the default), the executable may depend on some DLLs provided by the compiler. If ``static`` then a static version of the CRT is linked directly into the executable. """), Property("win32-unicode", type=BoolType(), default=True, inheritable=True, doc="Compile win32 code in Unicode mode? If enabled, " "``_UNICODE`` symbol is defined and the wide character " "entry point (``WinMain``, ...) is used."), Property("outputdir", type=PathType(), default=PathExpr([], anchor=ANCHOR_BUILDDIR), inheritable=True, doc=""" Directory where final binaries are put. Note that this is not the directory for intermediate files such as object files -- these are put in ``@builddir``. By default, output location is the same, ``@builddir``, but can be overwritten to for example put all executables into ``bin/`` subdirectory. """), Property("pic", type=BoolType(), default=lambda target: target.type.use_pic_by_default, inheritable=True, doc=""" Compile position-independent code. By default, libraries (both shared and static, because the latter could be linked into a shared lib too) are linked with -fPIC and executables are not. """), Property("multithreading", type=BoolType(), default=True, inheritable=True, doc=""" Enable support for multithreading. MT support is enabled by default, but can be disabled when not needed. On Unix, this option causes the use of pthreads library. Visual Studio always uses MT-safe CRT, even if this setting is disabled. """), ] use_pic_by_default = True def target_file(self, toolset, target): """ Returns main filename of the target. """ return self._get_filename(toolset, target, "basename", self.name) def _get_filename(self, toolset, target, propname, fileclass): """ Returns expression with filename of the target using given property (typically, "basename") for use with given toolset. """ fileclass = fileclass.replace("-", "_") tdir = dir(toolset) prefix = "%s_prefix" % fileclass ext = "%s_extension" % fileclass parts = [] if prefix in tdir: parts.append(getattr(toolset, prefix)) parts.append(target[propname]) if not target.is_variable_null("extension"): parts.append(target["extension"]) elif ext in tdir: parts.append("." + getattr(toolset, ext)) outdir = target["outputdir"] return PathExpr(outdir.components + [concat(*parts)], outdir.anchor, outdir.anchor_file) def target_file_extension(self, toolset, target): """ Returns expression with extension of the target's filename (as returned by :meth:`target_file()`), including the leading dot. """ if not target.is_variable_null("extension"): return target["extension"] else: try: fileclass = self.name.replace("-", "_") ext = "%s_extension" % fileclass return LiteralExpr(".%s" % getattr(toolset, ext)) except AttributeError: return NullExpr()
def properties_module(cls): yield Property("%s.makefile" % cls.name, type=PathType(), default=cls.default_makefile, inheritable=False, doc="Name of output file for module's makefile.")