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 aif()
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> > )
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
orclang_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. Noif()
blocks are needed.
The CMake documentation is at cmake-generator-expressions(7)