Skip to the content.

Compile Args

Overview

Manages compiler arguments passed to libclang for parsing. Controls language standard, preprocessor defines, include paths, and target configuration.

Why Use This?

libclang requires explicit compiler flags to parse code correctly. This class provides a fluent builder API instead of raw argument string construction, and ensures compatibility across platforms and compilers.

Types

Type Description
compile_args Fluent builder for compiler arguments
language_standard Enum of supported C/C++ standards (c89 through cxx26)
language_mode Enum of language modes (c, cxx, objective_c, objective_cxx)

Functions

compile_args()

Default constructor. Creates empty argument list.

add

Add a raw compiler argument.

Signature: void add(const std::string& arg)

Parameters:

add_many

Add multiple raw compiler arguments.

Signature: void add_many(const std::vector<std::string>& args_to_add)

Parameters:

clear

Remove all arguments.

Signature: void clear()

get_args

Get the current argument list.

Signature: const std::vector<std::string>& get_args() const

Returns: reference to the internal argument vector

set_standard

Set the language standard.

Signature: compile_args& set_standard(language_standard std)

Parameters:

Returns: *this for chaining

set_language

Set the language mode.

Signature: compile_args& set_language(language_mode lang)

Parameters:

Returns: *this for chaining

add_include_path

Add a single include path (-I<path>).

Signature: compile_args& add_include_path(const std::string& path)

Parameters:

Returns: *this for chaining

add_include_paths

Add multiple include paths.

Signature: compile_args& add_include_paths(const std::vector<std::string>& paths)

Parameters:

Returns: *this for chaining

define

Define a preprocessor macro.

Signatures:

Parameters:

Returns: *this for chaining

undefine

Undefine a preprocessor macro (-U<name>).

Signature: compile_args& undefine(const std::string& name)

Parameters:

Returns: *this for chaining

set_target

Set target triple for cross-compilation (--target=<triple>).

Signature: compile_args& set_target(const std::string& triple)

Parameters:

Returns: *this for chaining

Notes: Affects sizeof, predefined macros, and type alignment.

set_pointer_size

Set pointer size for cross-compilation (-m32 or -m64).

Signature: compile_args& set_pointer_size(int bits)

Parameters:

Returns: *this for chaining

modern_cxx (static)

Create a preset configured for modern C++ development.

Signature: static compile_args modern_cxx(language_standard std = language_standard::cxx20)

Parameters:

Returns: configured compile_args instance

modern_c (static)

Create a preset configured for C development.

Signature: static compile_args modern_c(language_standard std = language_standard::c17)

Parameters:

Returns: configured compile_args instance

minimal (static)

Create a preset with no default flags.

Signature: static compile_args minimal()

Returns: empty compile_args instance

Example:

auto args = xccmeta::compile_args::modern_cxx();
args.define("DEBUG", "1")
    .add_include_path("/opt/custom/include")
    .set_target("aarch64-linux-gnu");