Skip to content

Commit 729c7cc

Browse files
committed
cmake : rework options [no ci]
1 parent ccb46de commit 729c7cc

File tree

2 files changed

+53
-105
lines changed

2 files changed

+53
-105
lines changed

CMakeLists.txt

Lines changed: 49 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.14) # for add_link_options and implicit target
22
project("llama.cpp" C CXX)
33
include(CheckIncludeFileCXX)
44

5+
set(CMAKE_WARN_DEPRECATED YES)
6+
set(CMAKE_WARN_UNUSED_CLI YES)
7+
58
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
69

710
if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
@@ -32,124 +35,70 @@ else()
3235
endif()
3336
endif()
3437

38+
option(BUILD_SHARED_LIBS "build shared libraries" ${BUILD_SHARED_LIBS_DEFAULT})
3539

3640
#
37-
# Option list
41+
# option list
3842
#
3943

40-
if (APPLE)
41-
set(LLAMA_METAL_DEFAULT ON)
42-
set(LLAMA_BLAS_DEFAULT ON)
43-
set(LLAMA_BLAS_VENDOR_DEFAULT "Apple")
44-
else()
45-
set(LLAMA_METAL_DEFAULT OFF)
46-
set(LLAMA_BLAS_DEFAULT OFF)
47-
set(LLAMA_BLAS_VENDOR_DEFAULT "Generic")
48-
endif()
49-
50-
set(LLAMA_LLAMAFILE_DEFAULT ON)
51-
5244
# general
53-
option(BUILD_SHARED_LIBS "build shared libraries" OFF)
54-
option(LLAMA_STATIC "llama: static link libraries" OFF)
55-
option(LLAMA_NATIVE "llama: enable -march=native flag" ON)
56-
option(LLAMA_LTO "llama: enable link time optimization" OFF)
57-
option(LLAMA_CCACHE "llama: use ccache if available" ON)
45+
option(LLAMA_CCACHE "llama: use ccache if available" ON)
5846

5947
# debug
60-
option(LLAMA_ALL_WARNINGS "llama: enable all compiler warnings" ON)
61-
option(LLAMA_ALL_WARNINGS_3RD_PARTY "llama: enable all compiler warnings in 3rd party libs" OFF)
62-
option(LLAMA_GPROF "llama: enable gprof" OFF)
48+
option(LLAMA_ALL_WARNINGS "llama: enable all compiler warnings" ON)
49+
option(LLAMA_ALL_WARNINGS_3RD_PARTY "llama: enable all compiler warnings in 3rd party libs" OFF)
6350

6451
# build
65-
option(LLAMA_FATAL_WARNINGS "llama: enable -Werror flag" OFF)
52+
option(LLAMA_FATAL_WARNINGS "llama: enable -Werror flag" OFF)
6653

6754
# sanitizers
68-
option(LLAMA_SANITIZE_THREAD "llama: enable thread sanitizer" OFF)
69-
option(LLAMA_SANITIZE_ADDRESS "llama: enable address sanitizer" OFF)
70-
option(LLAMA_SANITIZE_UNDEFINED "llama: enable undefined sanitizer" OFF)
71-
72-
# instruction set specific
73-
if (LLAMA_NATIVE)
74-
set(INS_ENB OFF)
75-
else()
76-
set(INS_ENB ON)
77-
endif()
55+
option(LLAMA_SANITIZE_THREAD "llama: enable thread sanitizer" OFF)
56+
option(LLAMA_SANITIZE_ADDRESS "llama: enable address sanitizer" OFF)
57+
option(LLAMA_SANITIZE_UNDEFINED "llama: enable undefined sanitizer" OFF)
7858

79-
option(LLAMA_SVE "llama: enable SVE" OFF)
80-
option(LLAMA_AVX "llama: enable AVX" ${INS_ENB})
81-
option(LLAMA_AVX2 "llama: enable AVX2" ${INS_ENB})
82-
option(LLAMA_AVX512 "llama: enable AVX512" OFF)
83-
option(LLAMA_AVX512_VBMI "llama: enable AVX512-VBMI" OFF)
84-
option(LLAMA_AVX512_VNNI "llama: enable AVX512-VNNI" OFF)
85-
option(LLAMA_AVX512_BF16 "llama: enable AVX512-BF16" OFF)
86-
option(LLAMA_FMA "llama: enable FMA" ${INS_ENB})
87-
# in MSVC F16C is implied with AVX2/AVX512
88-
if (NOT MSVC)
89-
option(LLAMA_F16C "llama: enable F16C" ${INS_ENB})
90-
endif()
91-
92-
if (WIN32)
93-
set(LLAMA_WIN_VER "0x602" CACHE STRING "llama: Windows Version")
94-
endif()
59+
# extra artifacts
60+
option(LLAMA_BUILD_TESTS "llama: build tests" ${LLAMA_STANDALONE})
61+
option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE})
62+
option(LLAMA_BUILD_SERVER "llama: build server example" ${LLAMA_STANDALONE})
9563

9664
# 3rd party libs
97-
option(LLAMA_ACCELERATE "llama: enable Accelerate framework" ON)
98-
option(LLAMA_BLAS "llama: use BLAS" ${LLAMA_BLAS_DEFAULT})
99-
set(LLAMA_BLAS_VENDOR ${LLAMA_BLAS_VENDOR_DEFAULT} CACHE STRING
100-
"llama: BLAS library vendor")
101-
option(LLAMA_LLAMAFILE "llama: use llamafile SGEMM" ${LLAMA_LLAMAFILE_DEFAULT})
102-
option(LLAMA_CUDA "llama: use CUDA" OFF)
103-
option(LLAMA_CUBLAS "llama: use CUDA (deprecated, use LLAMA_CUDA)" OFF)
104-
option(LLAMA_CUDA_FORCE_DMMV "llama: use dmmv instead of mmvq CUDA kernels" OFF)
105-
option(LLAMA_CUDA_FORCE_MMQ "llama: use mmq kernels instead of cuBLAS" OFF)
106-
set(LLAMA_CUDA_DMMV_X "32" CACHE STRING "llama: x stride for dmmv CUDA kernels")
107-
set(LLAMA_CUDA_MMV_Y "1" CACHE STRING "llama: y block size for mmv CUDA kernels")
108-
option(LLAMA_CUDA_F16 "llama: use 16 bit floats for some calculations" OFF)
109-
set(LLAMA_CUDA_KQUANTS_ITER "2" CACHE STRING "llama: iters./thread per block for Q2_K/Q6_K")
110-
set(LLAMA_CUDA_PEER_MAX_BATCH_SIZE "128" CACHE STRING
111-
"llama: max. batch size for using peer access")
112-
option(LLAMA_CUDA_NO_PEER_COPY "llama: do not use peer to peer copies" OFF)
113-
option(LLAMA_CUDA_NO_VMM "llama: do not try to use CUDA VMM" OFF)
114-
option(LLAMA_CUDA_FA_ALL_QUANTS "llama: compile all quants for FlashAttention" OFF)
115-
116-
option(LLAMA_CURL "llama: use libcurl to download model from an URL" OFF)
117-
option(LLAMA_HIPBLAS "llama: use hipBLAS" OFF)
118-
option(LLAMA_HIP_UMA "llama: use HIP unified memory architecture" OFF)
119-
option(LLAMA_VULKAN "llama: use Vulkan" OFF)
120-
option(LLAMA_VULKAN_CHECK_RESULTS "llama: run Vulkan op checks" OFF)
121-
option(LLAMA_VULKAN_DEBUG "llama: enable Vulkan debug output" OFF)
122-
option(LLAMA_VULKAN_MEMORY_DEBUG "llama: enable Vulkan memory debug output" OFF)
123-
option(LLAMA_VULKAN_VALIDATE "llama: enable Vulkan validation" OFF)
124-
option(LLAMA_VULKAN_RUN_TESTS "llama: run Vulkan tests" OFF)
125-
option(LLAMA_METAL "llama: use Metal" ${LLAMA_METAL_DEFAULT})
126-
option(LLAMA_METAL_NDEBUG "llama: disable Metal debugging" OFF)
127-
option(LLAMA_METAL_SHADER_DEBUG "llama: compile Metal with -fno-fast-math" OFF)
128-
option(LLAMA_METAL_EMBED_LIBRARY "llama: embed Metal library" OFF)
129-
set(LLAMA_METAL_MACOSX_VERSION_MIN "" CACHE STRING
130-
"llama: metal minimum macOS version")
131-
set(LLAMA_METAL_STD "" CACHE STRING "llama: metal standard version (-std flag)")
132-
option(LLAMA_KOMPUTE "llama: use Kompute" OFF)
133-
option(LLAMA_RPC "llama: use RPC" OFF)
134-
option(LLAMA_OPENMP "llama: use OpenMP" ON)
135-
option(LLAMA_SYCL "llama: use SYCL" OFF)
136-
option(LLAMA_SYCL_F16 "llama: use 16 bit floats for sycl calculations" OFF)
137-
set(LLAMA_SYCL_TARGET "INTEL" CACHE STRING "llama: sycl target device")
138-
option(LLAMA_CPU_HBM "llama: use memkind for CPU HBM" OFF)
139-
set(LLAMA_SCHED_MAX_COPIES "4" CACHE STRING "llama: max input copies for pipeline parallelism")
140-
141-
option(LLAMA_BUILD_TESTS "llama: build tests" ${LLAMA_STANDALONE})
142-
option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE})
143-
option(LLAMA_BUILD_SERVER "llama: build server example" ON)
144-
option(LLAMA_LASX "llama: enable lasx" ON)
145-
option(LLAMA_LSX "llama: enable lsx" ON)
146-
147-
# add perf arguments
148-
option(LLAMA_PERF "llama: enable perf" OFF)
65+
option(LLAMA_CURL "llama: use libcurl to download model from an URL" OFF)
14966

15067
# Required for relocatable CMake package
15168
include(${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.cmake)
15269

70+
# override ggml options
71+
set(GGML_CCACHE ${LLAMA_CCACHE})
72+
set(GGML_BUILD_SHARED_LIBS ${LLAMA_BUILD_SHARED_LIBS})
73+
set(GGML_SANITIZE_THREAD ${LLAMA_SANITIZE_THREAD})
74+
set(GGML_SANITIZE_ADDRESS ${LLAMA_SANITIZE_ADDRESS})
75+
set(GGML_SANITIZE_UNDEFINED ${LLAMA_SANITIZE_UNDEFINED})
76+
set(GGML_ALL_WARNINGS ${LLAMA_ALL_WARNINGS})
77+
set(GGML_FATAL_WARNINGS ${LLAMA_FATAL_WARNINGS})
78+
79+
# transition helpers
80+
function (llama_option_depr TYPE OLD NEW)
81+
if (${OLD})
82+
message(${TYPE} "${OLD} is deprecated and will be removed in the future.\nUse ${NEW} instead\n")
83+
set(${NEW} ON)
84+
endif()
85+
endfunction()
86+
87+
llama_option_depr(FATAL_ERROR LLAMA_CUBLAS GGML_CUDA)
88+
llama_option_depr(WARNING LLAMA_CUDA GGML_CUDA)
89+
llama_option_depr(WARNING LLAMA_KOMPUTE GGML_KOMPUTE)
90+
llama_option_depr(WARNING LLAMA_METAL GGML_METAL)
91+
llama_option_depr(WARNING LLAMA_METAL_EMBED_LIBRARY GGML_METAL_EMBED_LIBRARY)
92+
llama_option_depr(WARNING LLAMA_NATIVE GGML_NATIVE)
93+
llama_option_depr(WARNING LLAMA_OPENMP GGML_OPENMP)
94+
llama_option_depr(WARNING LLAMA_RPC GGML_RPC)
95+
llama_option_depr(WARNING LLAMA_SYCL GGML_SYCL)
96+
llama_option_depr(WARNING LLAMA_SYCL_F16 GGML_SYCL)
97+
98+
#
99+
# build the library
100+
#
101+
153102
add_subdirectory(ggml)
154103
add_subdirectory(src)
155104

ggml/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ else()
3232
endif()
3333
endif()
3434

35+
option(BUILD_SHARED_LIBS "ggml: build shared libraries" ${BUILD_SHARED_LIBS_DEFAULT})
3536

3637
#
37-
# Option list
38+
# option list
3839
#
3940

4041
# TODO: mark all options as advanced when not GGML_STANDALONE
@@ -51,8 +52,6 @@ endif()
5152

5253
set(GGML_LLAMAFILE_DEFAULT ON)
5354

54-
option(BUILD_SHARED_LIBS "build shared libraries" OFF)
55-
5655
# general
5756
option(GGML_STATIC "ggml: static link libraries" OFF)
5857
option(GGML_NATIVE "ggml: enable -march=native flag" ON)
@@ -65,7 +64,7 @@ option(GGML_ALL_WARNINGS_3RD_PARTY "ggml: enable all compiler warnings in 3rd pa
6564
option(GGML_GPROF "ggml: enable gprof" OFF)
6665

6766
# build
68-
option(GGML_FATAL_WARNINGS "ggml: enable -Werror flag" OFF)
67+
option(GGML_FATAL_WARNINGS "ggml: enable -Werror flag" OFF)
6968

7069
# sanitizers
7170
option(GGML_SANITIZE_THREAD "ggml: enable thread sanitizer" OFF)
@@ -1032,7 +1031,7 @@ if (output MATCHES "dyld-1015\.7")
10321031
add_compile_definitions(HAVE_BUGGY_APPLE_LINKER)
10331032
endif()
10341033

1035-
# Architecture specific
1034+
# architecture specific
10361035
# TODO: probably these flags need to be tweaked on some architectures
10371036
# feel free to update the Makefile for your architecture and send a pull request or issue
10381037
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")

0 commit comments

Comments
 (0)