Skip to content

Instantly share code, notes, and snippets.

@cristianadam
Last active August 6, 2025 16:09
Show Gist options
  • Save cristianadam/7e67efd036899c5491a25f1b57f75046 to your computer and use it in GitHub Desktop.
Save cristianadam/7e67efd036899c5491a25f1b57f75046 to your computer and use it in GitHub Desktop.
Devstrall Small 2505 CMake knowledge

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

% brew install llama.cpp
% llama-server -hf unsloth/Devstral-Small-2505-GGUF:UD-Q4_K_XL --jinja 

I have used here the default context value -c 4096. Devstral can do 128K but I ran out of memory on this MacBook Pro M3 with 36GB, that is when using -c 0.

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:

Yes, you can use CMake generator expressions to conditionally set the LIBRARIES parameter in the qt_internal_extend_target function. Here's how you can refactor the code:

qt_internal_extend_target(Core CONDITION MSVC AND CLANG
    LIBRARIES
        "$<IF:$<AND:$<MATCHES:$<CMAKE_SYSTEM_PROCESSOR>,"ARM64">>,clang_rt.builtins-aarch64,clang_rt.builtins-x86_64>>"
)

This code uses CMake generator expressions to conditionally select the library based on the system processor architecture. The $<IF:condition,then,else> expression is used to check if the CMAKE_SYSTEM_PROCESSOR matches "ARM64". If it does, it selects clang_rt.builtins-aarch64; otherwise, it selects clang_rt.builtins-x86_64.

I followed up with:

according to CMake documentation there is no $<MATCHES, but $<STREQUAL does exist. Can you fix the expression?

which resulted in:

You're right, there is no $<MATCHES> generator expression in CMake. Instead, we can use a combination of $<STREQUAL> and $<OR> to achieve the same functionality. Here's the updated code:

qt_internal_extend_target(Core CONDITION MSVC AND CLANG
    LIBRARIES
        "$<IF:$<STREQUAL:$<CMAKE_SYSTEM_PROCESSOR>,"ARM64">,clang_rt.builtins-aarch64,clang_rt.builtins-x86_64>>"
)

In this expression, $<STREQUAL:$<CMAKE_SYSTEM_PROCESSOR>,"ARM64"> checks if the system processor is exactly "ARM64". If true, it selects clang_rt.builtins-aarch64; otherwise, it selects clang_rt.builtins-x86_64.

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