Build Details

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 tools or no tools at all. Blend2D exports C API, but it's still a library written in C++ and requires at least C++11 capable compiler.

Compiler Independent Setup:

  • Add the following source files to your target:
    • All source files in Blend2D src directory.
    • All source files in AsmJit src directory. If you downloaded a source release of Blend2D then AsmJit will be at 3rdparty/asmjit directory within Blend2D project.
  • Setup the C++ compiler in the following way:
    • Enable at least C++11 through -std=c++11 or /std:c++latest. C++17 is preferred though.
    • Add ${ASMJIT_DIR}/src to your include path through -I... or /I... option.
    • Define ASMJIT_BUILD_EMBED to tell asmjit that it will be embedded.
  • Define the following compile-time definitions to select a build type:
    • NDEBUG - should be always defined for release builds (standard C way).
    • BL_BUILD_DEBUG - force debug build, overrides autodetection based on NDEBUG.
    • BL_BUILD_RELEASE - force release build, overrides autodetection based on NDEBUG.
  • Define the following compile-time definitions to enable architecture-specific optimizations:
    • BL_BUILD_OPT_SSE2 - enables SSE2 optimizations (should be always enabled).
    • BL_BUILD_OPT_SSE3 - enables SSE3 optimizations.
    • BL_BUILD_OPT_SSSE3 - enables SSSE3 optimizations.
    • BL_BUILD_OPT_SSE4_1 - enables SSE4.1 optimizations.
    • BL_BUILD_OPT_SSE4_2 - enables SSE4.2 optimizations.
    • BL_BUILD_OPT_AVX - enables AVX optimizations.
    • BL_BUILD_OPT_AVX2 - enables AVX2 optimizations.

Compiler Specific Setup [GCC & Clang]:

  • Use the following [optional] compiler flags to make the resulting binaries better:
    • -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.
    • -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.
  • Each file with a certain suffix requires to be compiled with extra flags that enable architecture specific optimizations:
    • -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.

Compiler Specific Setup [MSVC]:

  • Use the following [optional] compiler flags to make the resulting binaries better:
    • /Ox - enables global optimizations.
    • /D_UNICODE - probably not needed, but defined anyway by official CMakeLists.txt.
  • Each file with a certain suffix requires to be compiled with extra flags that enable architecture specific optimizations:
    • /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 enabled.

Linker Options:

  • The following libraries are required on Windows:
    • (to be documented)
  • The following libraries are required on Linux, BSDs, and others:
    • libm (if not part of standard C library).
    • libpthread (required to support multithreading).
    • librt (required by clock_gettime() function).