Skip to main content

CMake toolchain

The SPECS NDK CMake toolchain files, the variables and flags they set, build configurations, and bundled compiler versions.

The SPECS NDK ships CMake toolchain files that configure the sysroot, compiler, linker, and flags for cross-compiling to aarch64-snap-linux. This page lists the toolchain files, every variable they set, the flags for each build configuration, and the bundled compiler versions per host.

CMake toolchain files

These files ship in the NDK root:

FilePurpose
SpecsNDK-Toolchain-Clang.cmakeClang: use this for new projects
SpecsNDK-Toolchain-common.cmakeShared sysroot, paths, and flags (included by SpecsNDK-Toolchain-Clang.cmake)
SpecsNDK-Toolchain-Simulator-macOS.cmakemacOS Simulator toolchain (macOS tarball only; see macOS Simulator)

Pass the toolchain file via -DCMAKE_TOOLCHAIN_FILE at configure time. Never pass SpecsNDK-Toolchain-common.cmake directly.

Variables set by the toolchain

Common variables set by SpecsNDK-Toolchain-common.cmake

CMake VariableValue
CMAKE_SYSTEM_NAMELinux
CMAKE_SYSTEM_PROCESSORaarch64
CMAKE_SYSROOT<NDK>/sysroots/armv8a-snap-linux
NATIVE_SYSROOT<NDK>/sysroots/x86_64-specsndk-darwin21 on macOS hosts; <NDK>/sysroots/x86_64-w64-mingw32 on Windows hosts
SPECSNDK_HOST_EXE_SUFFIX"" on macOS, ".exe" on Windows. Appended to all host binary paths so the toolchain works without code changes per host
SPECSNDKON. Use this in if(SPECSNDK) guards
CMAKE_FIND_ROOT_PATHHost tools sysroot (used by CMake's find_program)
CMAKE_FIND_ROOT_PATH_MODE_PROGRAMBOTH
CMAKE_FIND_ROOT_PATH_MODE_LIBRARYONLY
CMAKE_FIND_ROOT_PATH_MODE_INCLUDEONLY

Clang-specific variables set by SpecsNDK-Toolchain-Clang.cmake

CMake VariableValue
CMAKE_C_COMPILER<NATIVE_SYSROOT>/usr/bin/clang (macOS); <NATIVE_SYSROOT>/usr/lib/llvm-mingw/bin/clang.exe (Windows; see Host Setup on Windows for the reason)
CMAKE_CXX_COMPILER<NATIVE_SYSROOT>/usr/bin/clang++ (macOS); <NATIVE_SYSROOT>/usr/lib/llvm-mingw/bin/clang++.exe (Windows)
CMAKE_C_COMPILER_TARGETaarch64-snap-linux
CMAKE_CXX_COMPILER_TARGETaarch64-snap-linux
SPECSNDK_TRIPLEaarch64-snap-linux

Clang flags added automatically

FlagApplies toPurpose
-march=armv8-aC, C++, ASMTarget ARMv8-A baseline ISA
-stdlib=libc++C++ onlyUse LLVM libc++ (not libstdc++)
-fuse-ld=lldLinkerUse LLVM LLD linker
--gcc-install-dir=<sysroot>/usr/lib/aarch64-snap-linux/13.4.0C, C++, ASM, linkerWindows host only. Tells upstream llvm-mingw Clang where Yocto stashes libgcc.a and the CRT objects. Not added on macOS.
-nostdinc++ -cxx-isystem <sysroot>/usr/include/c++/v1 -Wno-unused-command-line-argumentC++ onlyWindows host only. Forces the target sysroot's libc++ 1.0 headers (llvm-mingw ships its own newer libc++ that would otherwise win by default). The -Wno-unused-command-line-argument silences a per-TU warning about -stdlib=libc++; that flag is still needed at link time.

Build configurations

The toolchain pre-configures flags for all standard CMake build types. The SPECSNDK define is always present so you can use it in conditional compilation (see Detecting the SPECS Target in Code).

ConfigurationFlags
Debug-DSPECSNDK -g
Release-DSPECSNDK -O3 -DNDEBUG
MinSizeRel-DSPECSNDK -Os -DNDEBUG
RelWithDebInfo-DSPECSNDK -O2 -g
# Release build (recommended for deployment)
cmake -B build \
-DCMAKE_TOOLCHAIN_FILE=SpecsNDK-Toolchain-Clang.cmake \
-DCMAKE_BUILD_TYPE=Release

# Debug build (for development/lldb debugging)
cmake -B build-debug \
-DCMAKE_TOOLCHAIN_FILE=SpecsNDK-Toolchain-Clang.cmake \
-DCMAKE_BUILD_TYPE=Debug

Compiler version summary

Binary paths in the following table are shown relative to the NDK root. The host-tools directory is x86_64-specsndk-darwin21/ on macOS and x86_64-w64-mingw32/ on Windows.

CompilermacOS version & path (under sysroots/x86_64-specsndk-darwin21/usr/bin/)Windows version & path (under sysroots/x86_64-w64-mingw32/)
Clang18.1.8: clang22: usr/lib/llvm-mingw/bin/clang.exe (upstream llvm-mingw)
Clang++18.1.8: clang++22: usr/lib/llvm-mingw/bin/clang++.exe
LLD18.1.8: ld.lld22: usr/lib/llvm-mingw/bin/ld.lld.exe

The Clang version differs between hosts on purpose: the macOS Clang can't be built to run on Windows, so the Windows tarball bundles upstream llvm-mingw instead. Both Clangs target the same target sysroot and produce ABI-compatible aarch64 binaries. For details, see Host Setup on Windows.