Target#

C#

C targets support C, C++, Obj-C and Obj-C++ sources, depending on the selected language.

C::Library(name:, description:, homepage:, version:, license:, language:, sources:, cflags:, headers:, linker_flags:, artifacts:, dependencies:, settings:)#

Define a C library in the current project.

Parameters:
  • name – The name of the library. Used to identify the target in the project and for the name(s) of the output artifact(s). (required)

  • description – A description of the library. Used in pkg-config generation.

  • homepage – A link to the library’s homepage

  • version – The version of the library. Used in pkg-config generation. Can be a string, int or float.

  • license – The license of the library. e.g. “MIT”.

  • language – The language of the library. Can be C, C++, Obj-C, Obj-C++. Default is C.

  • sources – The source files to compile for this library. Supports glob patterns. (required)

  • cflags –

    The cflags to compile the source files with.

    Valid forms are
    • a string ("-DFLAG")

    • an array (["-fsanitize=address", "-fno-omit-frame-pointer"])

    • a hash ({ public: "-DHAVE_X", private: "-D_HAVE_Y" }).

    When using a hash, public flags are passed to targets using the library, while private flags are not. A string or an array are public flags by default.

  • headers –

    The path(s) to the directories containing the header files. These are passed to targets having this library as a dependency. They are also passed as cflags when compiling this library as -Ipath.

    This can be
    • a string ("include")

    • an array (["include", "include2"])

    • a hash ({ public: "include/lib", private: ["include/private", "include/internal"] }).

    When using a string or array, the include flags are automatically passed to dependants of the library. With a hash, you can set internal include flags.

    alias: include

  • linker_flags –

    Can be passed as a string ("-lz"), or an array (["-lz", "-lcairo"]). Linker flags are automatically passed to dependants of the library.

    alias: ldflags, lflags

  • artifacts –

    The artifacts to create.

    The following artifacts can be created:
    • dynlib

    • staticlib: When compiling for WebAssembly, this is a wasm file.

    • pkgconfig

    • framework

    • xcframework

    • jslib: Only when compiling for wasm, this creates a JavaScript file that binds the wasm file created.

  • dependencies –

    An array of libraries this library requires.

    • "library": By default, dependencies are looked for in the current project.

    • "project:library": When a dependency of another project is required, this syntax can be used.

    See Dependency for more functions to create dependencies.

  • settings –

    An array of settings.

    The following settings can be added:
    • "ARC": Enables Obj-C ARC.

    • "std=XX": Set the minimum C/C++ language standard for this library and its dependants.

C::Executable(name:, description:, homepage:, version:, license:, language:, sources:, cflags:, headers:, linker_flags:, artifacts:, dependencies:, settings:)#

Define a C executable in the current project.

Parameters:
  • name – The name of the executable. Used to identify the target in the project and for the name(s) of the output artifact(s). (required)

  • description – A description of the executable.

  • homepage – A link to the executable’s homepage.

  • version – The version of the executable. Can be a string, int or float.

  • license – The license of the executable.

  • language – The language of the executable. Can be C, C++, Obj-C, Obj-C++. Default is C.

  • sources – The source files to compile for this executable. Supports glob patterns. (required)

  • cflags – The cflags to compile the source files with.

  • headers – The path(s) to the directories containing the header files. They are passed as cflags when compiling this executable as -Ipath.

  • linker_flags – Can be passed as a string ("-lz"), or an array (["-lz", "-lcairo"]).

  • artifacts –

    The artifacts to create.

    The following artifacts can be created:
    • "exe": A standard executable.

    • "App": A macOS app.

  • dependencies –

    An array of libraries this executable requires.

    • "library": By default, dependencies are looked for in the current project.

    • "project:library": When a dependency of another project is required, this syntax can be used.

    See Dependency for more functions to create dependencies.

  • settings –

    An array of settings.

    The following settings can be added:
    • "ARC": Enables Obj-C ARC.

    • "std=XX": Set the minimum C/C++ language standard for this library and its dependants.

Custom#

Custom targets can be used to use arbitrary build commands (like libraries using make) to build Beaver-compatible libraries and executables.

Custom::Library(name:, description:, homepage:, version:, license:, language:, sources:, cflags:, headers:, linker_flags:, artifacts:, dependencies:, build:)#

Define a custom library.

Parameters:
  • name – The name of the library.

  • description – The description of the library.

  • homepage – A link to the homepage of the library.

  • version – The version of the library. Can be a string, int or float.

  • license – The license of the library.

  • language – The source language of the library.

  • cflags – The C flags of this library. Passed to dependants of this library.

  • linker_flags –

    The linker flags of this library. Passed to descendants of this library.

    alias: linker_flags, ldflags, lflags

  • artifacts –

    Paths to the artifacts the build command generates.

    Example

    {
      "staticlib": "/path/to/lib.a",
      "dynlib": "/path/to/lib.so"
    }
    

  • dependencies –

    The libraries this library depends on.

    • "library": By default, dependencies are looked for in the current project.

    • "project:library": When a dependency of another project is required, this syntax can be used.

    See Dependency for more functions to create dependencies.

  • build –

    The build command.

    Example

    Custom::Library(
      name: "mylib",
      language: :c,
      artifacts: {
        staticlib: "build/libmylib.a"
      },
      build: proc {
        sh "clang -c lib.c -o build/lib.o"
        sh "ar -rcs build/libmylib.a build/lib.o"
      }
    )