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:
| File | Purpose |
|---|---|
SpecsNDK-Toolchain-Clang.cmake | Clang: use this for new projects |
SpecsNDK-Toolchain-common.cmake | Shared sysroot, paths, and flags (included by SpecsNDK-Toolchain-Clang.cmake) |
SpecsNDK-Toolchain-Simulator-macOS.cmake | macOS 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 Variable | Value |
|---|---|
CMAKE_SYSTEM_NAME | Linux |
CMAKE_SYSTEM_PROCESSOR | aarch64 |
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 |
SPECSNDK | ON. Use this in if(SPECSNDK) guards |
CMAKE_FIND_ROOT_PATH | Host tools sysroot (used by CMake's find_program) |
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM | BOTH |
CMAKE_FIND_ROOT_PATH_MODE_LIBRARY | ONLY |
CMAKE_FIND_ROOT_PATH_MODE_INCLUDE | ONLY |
Clang-specific variables set by SpecsNDK-Toolchain-Clang.cmake
| CMake Variable | Value |
|---|---|
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_TARGET | aarch64-snap-linux |
CMAKE_CXX_COMPILER_TARGET | aarch64-snap-linux |
SPECSNDK_TRIPLE | aarch64-snap-linux |
Clang flags added automatically
| Flag | Applies to | Purpose |
|---|---|---|
-march=armv8-a | C, C++, ASM | Target ARMv8-A baseline ISA |
-stdlib=libc++ | C++ only | Use LLVM libc++ (not libstdc++) |
-fuse-ld=lld | Linker | Use LLVM LLD linker |
--gcc-install-dir=<sysroot>/usr/lib/aarch64-snap-linux/13.4.0 | C, C++, ASM, linker | Windows 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-argument | C++ only | Windows 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).
| Configuration | Flags |
|---|---|
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.
| Compiler | macOS version & path (under sysroots/x86_64-specsndk-darwin21/usr/bin/) | Windows version & path (under sysroots/x86_64-w64-mingw32/) |
|---|---|---|
| Clang | 18.1.8: clang | 22: usr/lib/llvm-mingw/bin/clang.exe (upstream llvm-mingw) |
| Clang++ | 18.1.8: clang++ | 22: usr/lib/llvm-mingw/bin/clang++.exe |
| LLD | 18.1.8: ld.lld | 22: 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.