Compile Options
vix.app supports common compile-related settings for C++ projects.
The main fields are:
standard = c++20defines = [
MYAPP_VERSION="1.0.0",
]2
3
compile_options = [
-Wall,
-Wextra,
]2
3
4
compile_features = [
cxx_std_20,
]2
3
Use these fields to control the C++ standard, preprocessor definitions, compiler warnings, and CMake compile features.
C++ standard
The standard field defines the C++ standard used by the target.
Example:
name = hello
type = executable
standard = c++20
sources = [
src/main.cpp,
]2
3
4
5
6
7
Supported values include:
standard = c++17standard = c++20standard = c++23Default:
standard = c++20Example with C++20
vix.app:
name = hello
type = executable
standard = c++20
sources = [
src/main.cpp,
]2
3
4
5
6
7
src/main.cpp:
#include <vix.hpp>
#include <span>
#include <vector>
int main()
{
std::vector<int> values{1, 2, 3};
std::span<int> view(values);
vix::print("size:", view.size());
return 0;
}2
3
4
5
6
7
8
9
10
11
12
13
Build and run:
vix build
vix run2
Example with C++23
vix.app:
name = modern_app
type = executable
standard = c++23
sources = [
src/main.cpp,
]2
3
4
5
6
7
Use c++23 when your compiler and standard library support the features you need.
defines
The defines field adds preprocessor definitions to the target.
Example:
defines = [
MYAPP_VERSION="1.0.0",
MYAPP_ENABLE_LOGGING=1,
]2
3
4
Complete manifest:
name = config_app
type = executable
standard = c++20
sources = [
src/main.cpp,
]
defines = [
MYAPP_VERSION="1.0.0",
MYAPP_ENABLE_LOGGING=1,
]2
3
4
5
6
7
8
9
10
11
12
C++ usage:
#include <vix.hpp>
#ifndef MYAPP_VERSION
#define MYAPP_VERSION "unknown"
#endif
int main()
{
vix::print("version:", MYAPP_VERSION);
#ifdef MYAPP_ENABLE_LOGGING
vix::print("logging enabled");
#endif
return 0;
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Define values
Definitions can be simple flags:
defines = [
MYAPP_DEBUG,
]2
3
or key-value pairs:
defines = [
MYAPP_VERSION="1.0.0",
MYAPP_LEVEL=2,
]2
3
4
Quoting string defines
When a definition contains a string value, include the quotes as part of the value:
defines = [
MYAPP_VERSION="1.0.0",
]2
3
Then use it in C++:
vix::print(MYAPP_VERSION);compile_options
The compile_options field adds compiler flags to the target.
Example:
compile_options = [
-Wall,
-Wextra,
-Wpedantic,
]2
3
4
5
Complete manifest:
name = warnings_app
type = executable
standard = c++20
sources = [
src/main.cpp,
]
compile_options = [
-Wall,
-Wextra,
-Wpedantic,
]2
3
4
5
6
7
8
9
10
11
12
13
Common GCC and Clang warnings
For GCC or Clang, a useful starting point is:
compile_options = [
-Wall,
-Wextra,
-Wpedantic,
]2
3
4
5
For stricter builds:
compile_options = [
-Wall,
-Wextra,
-Wpedantic,
-Wconversion,
-Wshadow,
]2
3
4
5
6
7
Use strict warnings carefully. Some flags can be noisy depending on your project.
Optimization flags
You can pass optimization flags:
compile_options = [
-O2,
]2
3
or for debugging:
compile_options = [
-g,
]2
3
However, prefer Vix presets for normal debug and release workflows:
vix buildvix build --preset releaseUse compile_options when you need target-specific flags.
Platform-specific options
Compiler flags are not always portable.
For example:
compile_options = [
-Wall,
-Wextra,
]2
3
4
works well with GCC and Clang, but not necessarily with MSVC.
For portable projects, avoid compiler-specific flags unless you control the build environment.
link_options
Although this page focuses on compile options, linker options are related.
Use link_options for linker flags:
link_options = [
"-Wl,--as-needed",
]2
3
Do not put linker flags in compile_options.
Correct:
link_options = [
"-Wl,--as-needed",
]2
3
Incorrect:
compile_options = [
"-Wl,--as-needed",
]2
3
compile_features
The compile_features field adds CMake compile features to the generated target.
Example:
compile_features = [
cxx_std_20,
]2
3
Complete manifest:
name = feature_app
type = executable
standard = c++20
sources = [
src/main.cpp,
]
compile_features = [
cxx_std_20,
]2
3
4
5
6
7
8
9
10
11
Common values:
cxx_std_17
cxx_std_20
cxx_std_232
3
standard vs compile_features
For most projects, use:
standard = c++20This is enough.
Use compile_features when you specifically need CMake-style feature declarations.
Example:
standard = c++20
compile_features = [
cxx_std_20,
]2
3
4
5
This is explicit, but often redundant.
Recommended simple setup
For most Vix projects:
name = myapp
type = executable
standard = c++20
sources = [
src/main.cpp,
src/app.cpp,
]
include_dirs = [
include,
]
compile_options = [
-Wall,
-Wextra,
]2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
This gives a clean development setup without making the manifest too complex.
Debug-style setup
For local development:
name = debug_app
type = executable
standard = c++20
sources = [
src/main.cpp,
]
defines = [
DEBUG=1,
]
compile_options = [
-Wall,
-Wextra,
-g,
]2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Build:
vix buildRelease-style setup
For release builds, prefer:
vix build --preset releaseYou can still add target-specific optimization options:
compile_options = [
-O2,
]2
3
But avoid hardcoding release-only flags in the manifest if you want the same vix.app to work well for both debug and release.
Sanitizers
For simple script mode, Vix has sanitizer flags such as:
vix run main.cpp --sanFor vix.app projects, sanitizer integration should usually be handled through build configuration or CMake arguments.
Example:
vix build -- -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined"For advanced sanitizer workflows, use a normal CMakeLists.txt.
Warnings as errors
You can enable warnings as errors:
compile_options = [
-Wall,
-Wextra,
-Werror,
]2
3
4
5
Use this carefully.
It can be useful in CI, but it can make local development harder when compilers produce different warnings.
Per-project flags
compile_options applies to the generated target.
Example:
name = server
type = executable
standard = c++20
sources = [
src/main.cpp,
src/server.cpp,
]
compile_options = [
-Wall,
-Wextra,
]2
3
4
5
6
7
8
9
10
11
12
13
This is target-specific, not global to every CMake project on your machine.
Inline syntax
For small projects, inline syntax is supported:
compile_options = [-Wall, -Wextra]
defines = [DEBUG=1]
compile_features = [cxx_std_20]2
3
For larger projects, prefer multi-line syntax:
compile_options = [
-Wall,
-Wextra,
]
defines = [
DEBUG=1,
]
compile_features = [
cxx_std_20,
]2
3
4
5
6
7
8
9
10
11
12
Multi-line syntax is easier to read and review.
Complete example
name = myapp
type = executable
standard = c++23
sources = [
src/main.cpp,
src/app.cpp,
]
include_dirs = [
include,
]
defines = [
MYAPP_VERSION="1.2.3",
MYAPP_ENABLE_LOGGING=1,
]
compile_options = [
-Wall,
-Wextra,
-Wpedantic,
]
compile_features = [
cxx_std_23,
]2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Common mistakes
Using unsupported standard values
Incorrect:
standard = cpp20Correct:
standard = c++20Putting linker flags in compile_options
Incorrect:
compile_options = [
"-Wl,--as-needed",
]2
3
Correct:
link_options = [
"-Wl,--as-needed",
]2
3
Forgetting quotes for string defines
Incorrect:
defines = [
MYAPP_VERSION=1.0.0,
]2
3
This may not behave like a C++ string.
Correct:
defines = [
MYAPP_VERSION="1.0.0",
]2
3
Using compiler-specific flags everywhere
This may work on GCC or Clang:
compile_options = [
-Wall,
-Wextra,
]2
3
4
But it may not work on every compiler.
For portable projects, keep flags minimal.
Recommended patterns
Simple app
name = hello
type = executable
standard = c++20
sources = [
src/main.cpp,
]2
3
4
5
6
7
App with warnings
name = hello
type = executable
standard = c++20
sources = [
src/main.cpp,
]
compile_options = [
-Wall,
-Wextra,
]2
3
4
5
6
7
8
9
10
11
12
App with defines
name = hello
type = executable
standard = c++20
sources = [
src/main.cpp,
]
defines = [
HELLO_VERSION="1.0.0",
]2
3
4
5
6
7
8
9
10
11
App with explicit CMake feature
name = hello
type = executable
standard = c++20
sources = [
src/main.cpp,
]
compile_features = [
cxx_std_20,
]2
3
4
5
6
7
8
9
10
11
Summary
Use:
standard = c++20to select the C++ standard.
Use:
defines = [
NAME=value,
]2
3
for preprocessor definitions.
Use:
compile_options = [
-Wall,
]2
3
for compiler flags.
Use:
compile_features = [
cxx_std_20,
]2
3
only when you need explicit CMake compile features.
Next steps
Continue with: