Skip to content

Instantly share code, notes, and snippets.

@cristianadam
Last active August 7, 2025 20:38
Show Gist options
  • Save cristianadam/ede782b99f33671ff978e24d44b9e9e6 to your computer and use it in GitHub Desktop.
Save cristianadam/ede782b99f33671ff978e24d44b9e9e6 to your computer and use it in GitHub Desktop.
gpt-oss-20b CMake knowledge

On a MacBook Pro with Apple Silicon I have done the following:

% brew install llama.cpp
% llama-server -hf unsloth/gpt-oss-20b-GGUF:UD-Q4_K_XL --jinja 

I have used here the default context value -c 4096.

Then opened a webbrowser at localhost:8080 and asked the following question:

given this CMake code delimited by triple backticks:

qt_internal_extend_target(Core CONDITION MSVC AND CLANG
    LIBRARIES
        clang_rt.builtins-x86_64
)

and this CMake code delimited by triple backticks:

if(MSVC AND CLANG)
    if(CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64")
        qt_internal_extend_target(Core
            LIBRARIES
                clang_rt.builtins-aarch64
        )
    else()
        qt_internal_extend_target(Core
            LIBRARIES
                clang_rt.builtins-x86_64
        )
    endif()
endif()

can you refactor the latter CMake code to use a CMake generator expression for the LIBRARIES part and not use a if() statement?

The answer I recevied is below:

<|channel|>analysisHere’s a one‑liner that does exactly what the second block does, but without any if() calls – it uses a generator expression to pick the right library at configure‑time.

# ---------------------------------------------------------
#  Add the appropriate Clang builtin library for MSVC/Clang
#  targets.  The library name is chosen with a generator
#  expression that checks the CPU architecture.
# ---------------------------------------------------------
qt_internal_extend_target(Core
    LIBRARIES $<$<AND:$<BOOL:${MSVC}>,$<BOOL:${CLANG}>>:
        clang_rt.builtins-$<IF:$<STREQUAL:$<CMAKE_SYSTEM_PROCESSOR>,ARM64>,aarch64,x86_64>
    >
)

How it works

Piece What it does
$<AND:$<BOOL:${MSVC}>,${CLANG}> True only when we’re building with MSVC and Clang.
$<STREQUAL:$<CMAKE_SYSTEM_PROCESSOR>,ARM64> True if the target system processor is “ARM64”.
$<IF:condition,then,else> Picks the “aarch64” string when ARM64, otherwise “x86_64”.
clang_rt.builtins-$<...> Builds the full library name (clang_rt.builtins-aarch64 or clang_rt.builtins-x86_64).

Because the whole LIBRARIES argument is wrapped in a generator expression, it is evaluated only when the target is actually used, and the correct library name is inserted automatically. No if() blocks are needed.

The CMake documentation is at cmake-generator-expressions(7)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment