
Blend2D
2D Vector Graphics Engine
Blend2D uses CMake to create native platform (or IDE) projects and to build them. Consult cmake-generators page to see which generators are supported on your target platform. You don't have to use CMake if you prefer other tools, but then you would have to set some compile flags and definitions manually, which is covered by Building Without CMake section. At the moment Blend2D only depends on AsmJit library, which is part of Blend2D source releases, but it's not part of Blend2D git repository. Git users have to clone AsmJit library separately.
This page documents the process of building Blend2D. If you are more interested in using Blend2D within your own project the Getting Started page is much easier and provides all the information to use Blend2D in a CMake project.
Operating systems supported:
CPU architectures supported:
C++ compilers supported:
It's strongly advised to use latest compilers to compile Blend2D on all platforms to achieve maximum performance. Many floating point computations that are implemented in C++ can be autovectorized, so a capable compiler can make a significant difference.
Never use unsafe math optimizations like -ffast-math
, -ffinite-math-only
, or /fp:fast
as Blend2D relies on existence of NaN and Infinity. Additionally, C++ compiler should never reorder any floating point expressions as some expressions are very sensitive to such reordering. The only optimization that is allowed is using fused-multiply-add (FMA) instructions if they are available.
By default only dynamically linked blend2d
library is built. The following CMake build options are available:
Option | Default | Description |
---|---|---|
CMAKE_BUILD_TYPE |
(unset) | Highly depends on CMake generator used:
|
ASMJIT_DIR |
(unset) | Where to find AsmJit library for static inclusion. Should be unset to let Blend2D autodetect the location:
|
BLEND2D_TEST |
false | Whether to build tests. |
BLEND2D_EMBED |
false | Whether to embed Blend2D library, which enables:
|
BLEND2D_STATIC |
false | Whether to build Blend2D statically:
|
BLEND2D_SANITIZE |
(unset) | Sanitizers to use to build Blend2D, possible options are address , undefined , thread , etc...
|
BLEND2D_NO_FUTEX |
false | Disables using futexes (this is only useful for testing or as a workaround to disable Futexes in case that there is a bug in Blend2D) |
BLEND2D_NO_INTRINSICS |
false | Disables the use of non-SIMD intrinsics in Blend2D (there is no reason to explicitly turn on this option, it's only useful for testing) |
BLEND2D_NO_INSTALL |
false | If true Blend2D won't install blend2d library and public header files. Useful in cases in which Blend2D is compiles statically as a part of another project, which has install targets, but installing Blend2D is unwanted |
BLEND2D_NO_JIT |
false | Disables JIT compiler and AsmJit dependency (experimental, not suited for production) |
BLEND2D_NO_NATVIS |
false | Disables embedding blend2d.natvis file in Blend2D binary |
BLEND2D_NO_STDCXX |
(unset) | Disables linking to a C++ standard library. This option is autodetected - dynamically linked Blend2D library would not link to a standard C++ library by default |
BLEND2D_NO_TLS |
false | Disables the use of thread-local storage (there is no reason to explicitly turn on this option unless you are having issues with TLS or your target is operating system that has a very limited size of TLS) |
The following steps can be used to clone and build Blend2D directly from git:
The following steps can be used to build Blend2D source release:
The same approach can be used to build sample applications. The following example shows how to clone everything from Blend2D git repositories, but it would work with source as well:
This page documents the process of building Blend2D without any help of CMake build scripts. It can be used as a reference of what CMake scripts are doing and as a recommendation of building Blend2D with other build tools or no build tools at all. Blend2D exports C API, but it's still a library written in C++ and requires at least C++11 capable compiler.
src
directorysrc
directory. If you downloaded a source release of Blend2D then AsmJit will be at 3rdparty/asmjit
directory within Blend2D project-std=c++11
or /std:c++latest
. C++17 is preferred though${ASMJIT_DIR}/src
to your include path through -I...
optionASMJIT_STATIC
to tell asmjit that it will be built staticallyNDEBUG
- should be always defined for release builds (standard C way)BL_BUILD_DEBUG
- force debug build, overrides autodetection based on NDEBUG
(optional).BL_BUILD_RELEASE
- force release build, overrides autodetection based on NDEBUG
(optional)BL_BUILD_OPT_SSE2
- enables SSE2 optimizations (should be always enabled)BL_BUILD_OPT_SSE3
- enables SSE3 optimizationsBL_BUILD_OPT_SSSE3
- enables SSSE3 optimizationsBL_BUILD_OPT_SSE4_1
- enables SSE4.1 optimizationsBL_BUILD_OPT_SSE4_2
- enables SSE4.2 optimizationsBL_BUILD_OPT_AVX
- enables AVX optimizationsBL_BUILD_OPT_AVX2
- enables AVX2 optimizations-fvisibility=hidden
- Blend2D API uses explicit public visibility so everything else should be hidden by default. Alternatively -fvisibility-inlines-hidden
can be specified-fno-exceptions
- Blend2D doesn't use exceptions so you can turn them off-fno-rtti
- Blend2D doesn't use runtime type information or dynamic casts so you can turn this feature off-fno-math-errno
- Blend2D doesn't check errno
after calling math functions, this option may help the C++ compiler to inline some intrinsic functions like sqrt
-fno-semantic-interposition
- Better code generated as the compiler doesn't have to assume semantic interposition, GCC documentation , Clang uses this flag by default-fno-threadsafe-statics
- Blend2D has its own initialization step, which initializes everything required to make the library functional, thus thread-safe statics are not needed to guard initialization of static variables-fmerge-all-constants
- Blend2D doesn't compare pointers of constants so it's perfectly fine to merge constants having the same values-ftree-vectorize
- some compilers need this option to vectorize some constructs that Blend2D uses, however, this option would be probably set automatically at certain optimization levels by the compiler-O2
or -O3
- it should be enough to use -O2
as -O3
often only increases code-size without increasing its performance-msse2
must be used to compile *_sse2.cpp
files if BL_BUILD_OPT_SSE2
was enabled-msse3
must be used to compile *_sse3.cpp
files if BL_BUILD_OPT_SSE3
was enabled-mssse3
must be used to compile *_ssse3.cpp
files if BL_BUILD_OPT_SSSE3
was enabled-msse4.1
must be used to compile *_sse4_1.cpp
files if BL_BUILD_OPT_SSE4_1
was enabled-msse4.2
must be used to compile *_sse4_2.cpp
files if BL_BUILD_OPT_SSE4_2
was enabled-mavx
must be used to compile *_avx.cpp
files if BL_BUILD_OPT_AVX
was enabled-mavx2
must be used to compile *_avx2.cpp
files if BL_BUILD_OPT_AVX2
was enabled-O2
- favor performance over size-arch:SSE2
and -D__SSE2__
must be used to compile *_sse2.cpp
files if BL_BUILD_OPT_SSE2
was enabled-arch:SSE2
and -D__SSE3__
must be used to compile *_sse3.cpp
files if BL_BUILD_OPT_SSE3
was enabled-arch:SSE2
and -D__SSSE3__
must be used to compile *_ssse3.cpp
files if BL_BUILD_OPT_SSSE3
was enabled-arch:SSE2
and -D__SSE4_1__
must be used to compile *_sse4_1.cpp
files if BL_BUILD_OPT_SSE4_1
was enabled-arch:SSE2
and -D__SSE4_2__
must be used to compile *_sse4_2.cpp
files if BL_BUILD_OPT_SSE4_2
was enabled-arch:AVX
must be used to compile *_avx.cpp
files if BL_BUILD_OPT_AVX
was enabled-arch:AVX2
must be used to compile *_avx2.cpp
files if BL_BUILD_OPT_AVX2
was enabledclang-cl
compiler is used instead of stock cl
it's important to explicitly enable SSE3, SSSE3, SSE4.1, and SSE4.2 optimizations together with -arch:SSE2
, otherwise the compilation would fail as Clang is not fully compatible with MS stock compiler:-arch:SSE2
and -msse3
must be used to compile *_sse3.cpp
files if BL_BUILD_OPT_SSE3
was enabled-arch:SSE2
and -mssse3
must be used to compile *_ssse3.cpp
files if BL_BUILD_OPT_SSSE3
was enabled-arch:SSE2
and -msse4.1
must be used to compile *_sse4_1.cpp
files if BL_BUILD_OPT_SSE4_1
was enabled-arch:SSE2
and -msse4.2
must be used to compile *_sse4_2.cpp
files if BL_BUILD_OPT_SSE4_2
was enabledlibc
(standard C library)libm
(if not part of standard C library)libpthread
(required to support multithreading)librt
(Required on Linux by clock_gettime()
function)