@@ -26,6 +26,8 @@ if (NOT MSVC)
26
26
endif ()
27
27
endif ()
28
28
29
+ unset (GGML_EXTRA_LIBS )
30
+
29
31
if (APPLE AND GGML_ACCELERATE )
30
32
find_library (ACCELERATE_FRAMEWORK Accelerate )
31
33
if (ACCELERATE_FRAMEWORK )
@@ -35,7 +37,7 @@ if (APPLE AND GGML_ACCELERATE)
35
37
add_compile_definitions (ACCELERATE_NEW_LAPACK )
36
38
add_compile_definitions (ACCELERATE_LAPACK_ILP64 )
37
39
38
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} ${ACCELERATE_FRAMEWORK} )
40
+ list ( APPEND GGML_EXTRA_LIBS ${ACCELERATE_FRAMEWORK} )
39
41
else ()
40
42
message (WARNING "Accelerate framework not found" )
41
43
endif ()
@@ -87,7 +89,7 @@ if (GGML_METAL)
87
89
COMMENT "Generate assembly for embedded Metal library"
88
90
)
89
91
90
- set ( GGML_SOURCES_METAL ${ GGML_SOURCES_METAL} ${METALLIB_EMBED_ASM} )
92
+ list ( APPEND GGML_SOURCES_METAL ${METALLIB_EMBED_ASM} )
91
93
else ()
92
94
if (GGML_METAL_SHADER_DEBUG )
93
95
# custom command to do the following:
@@ -132,7 +134,7 @@ if (GGML_METAL)
132
134
)
133
135
endif () # GGML_METAL_EMBED_LIBRARY
134
136
135
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS}
137
+ list ( APPEND GGML_EXTRA_LIBS
136
138
${FOUNDATION_LIBRARY}
137
139
${METAL_FRAMEWORK}
138
140
${METALKIT_FRAMEWORK}
@@ -157,11 +159,11 @@ if (GGML_OPENMP)
157
159
158
160
add_compile_definitions (GGML_USE_OPENMP )
159
161
160
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} OpenMP::OpenMP_C OpenMP::OpenMP_CXX )
162
+ list ( APPEND GGML_EXTRA_LIBS OpenMP::OpenMP_C OpenMP::OpenMP_CXX )
161
163
162
164
if (GGML_MUSA )
163
- set ( GGML_EXTRA_INCLUDES ${ GGML_EXTRA_INCLUDES} "/usr/lib/llvm-10/include/openmp" )
164
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} "/usr/lib/llvm-10/lib/libomp.so" )
165
+ list ( APPEND GGML_EXTRA_INCLUDES "/usr/lib/llvm-10/include/openmp" )
166
+ list ( APPEND GGML_EXTRA_LIBS "/usr/lib/llvm-10/lib/libomp.so" )
165
167
endif ()
166
168
else ()
167
169
message (WARNING "OpenMP not found" )
@@ -244,8 +246,8 @@ if (GGML_BLAS)
244
246
set (GGML_HEADERS_BLAS ../include/ggml-blas.h )
245
247
set (GGML_SOURCES_BLAS ggml-blas.cpp )
246
248
247
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} ${BLAS_LIBRARIES} )
248
- set ( GGML_EXTRA_INCLUDES ${ GGML_EXTRA_INCLUDES} ${BLAS_INCLUDE_DIRS} )
249
+ list ( APPEND GGML_EXTRA_LIBS ${BLAS_LIBRARIES} )
250
+ list ( APPEND GGML_EXTRA_INCLUDES ${BLAS_INCLUDE_DIRS} )
249
251
else ()
250
252
message (WARNING "BLAS not found, please refer to "
251
253
"https://cmake.org/cmake/help/latest/module/FindBLAS.html#blas-lapack-vendors"
@@ -368,29 +370,29 @@ if (GGML_CUDA)
368
370
if (GGML_STATIC )
369
371
if (WIN32 )
370
372
# As of 12.3.1 CUDA Toolkit for Windows does not offer a static cublas library
371
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} CUDA::cudart_static CUDA::cublas CUDA::cublasLt )
373
+ list ( APPEND GGML_EXTRA_LIBS CUDA::cudart_static CUDA::cublas CUDA::cublasLt )
372
374
else ()
373
375
if (GGML_MUSA )
374
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} MUSA::musart_static MUSA::mublas_static )
376
+ list ( APPEND GGML_EXTRA_LIBS MUSA::musart_static MUSA::mublas_static )
375
377
else ()
376
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} CUDA::cudart_static CUDA::cublas_static CUDA::cublasLt_static )
378
+ list ( APPEND GGML_EXTRA_LIBS CUDA::cudart_static CUDA::cublas_static CUDA::cublasLt_static )
377
379
endif ()
378
380
endif ()
379
381
else ()
380
382
if (GGML_MUSA )
381
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} MUSA::musart MUSA::mublas )
383
+ list ( APPEND GGML_EXTRA_LIBS MUSA::musart MUSA::mublas )
382
384
else ()
383
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} CUDA::cudart CUDA::cublas CUDA::cublasLt )
385
+ list ( APPEND GGML_EXTRA_LIBS CUDA::cudart CUDA::cublas CUDA::cublasLt )
384
386
endif ()
385
387
endif ()
386
388
387
389
if (GGML_CUDA_NO_VMM )
388
390
# No VMM requested, no need to link directly with the cuda driver lib (libcuda.so)
389
391
else ()
390
392
if (GGML_MUSA )
391
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} MUSA::musa_driver ) # required by muDeviceGetAttribute(), muMemGetAllocationGranularity(...), ...
393
+ list ( APPEND GGML_EXTRA_LIBS MUSA::musa_driver ) # required by muDeviceGetAttribute(), muMemGetAllocationGranularity(...), ...
392
394
else ()
393
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} CUDA::cuda_driver ) # required by cuDeviceGetAttribute(), cuMemGetAllocationGranularity(...), ...
395
+ list ( APPEND GGML_EXTRA_LIBS CUDA::cuda_driver ) # required by cuDeviceGetAttribute(), cuMemGetAllocationGranularity(...), ...
394
396
endif ()
395
397
endif ()
396
398
else ()
@@ -495,7 +497,7 @@ if (GGML_HIPBLAS)
495
497
496
498
if (CXX_IS_HIPCC )
497
499
set_source_files_properties (${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE CXX )
498
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} hip::device )
500
+ list ( APPEND GGML_EXTRA_LIBS hip::device )
499
501
else ()
500
502
set_source_files_properties (${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE HIP )
501
503
endif ()
@@ -504,7 +506,8 @@ if (GGML_HIPBLAS)
504
506
message (FATAL_ERROR "Static linking not supported for HIP/ROCm" )
505
507
endif ()
506
508
507
- set (GGML_EXTRA_LIBS ${GGML_EXTRA_LIBS} PUBLIC hip::host roc::rocblas roc::hipblas )
509
+ # TODO: this "PUBLIC" here seems wrong
510
+ list (APPEND GGML_EXTRA_LIBS PUBLIC hip::host roc::rocblas roc::hipblas )
508
511
endif ()
509
512
510
513
if (GGML_SYCL )
@@ -535,7 +538,7 @@ if (GGML_SYCL)
535
538
add_compile_definitions (GGML_SYCL_FORCE_MMQ )
536
539
endif ()
537
540
538
- set ( CMAKE_CXX_FLAGS " ${ CMAKE_CXX_FLAGS} -Wno-narrowing -fsycl" )
541
+ list ( APPEND CMAKE_CXX_FLAGS -Wno-narrowing -fsycl )
539
542
540
543
if (GGML_SYCL_TARGET STREQUAL "NVIDIA" )
541
544
add_compile_definitions (GGML_SYCL_WARP_SIZE=32 )
@@ -559,13 +562,13 @@ if (GGML_SYCL)
559
562
if (WIN32 )
560
563
find_package (IntelSYCL REQUIRED )
561
564
find_package (MKL REQUIRED )
562
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} IntelSYCL::SYCL_CXX MKL::MKL MKL::MKL_SYCL )
565
+ list ( APPEND GGML_EXTRA_LIBS IntelSYCL::SYCL_CXX MKL::MKL MKL::MKL_SYCL )
563
566
else ()
564
567
if (GGML_SYCL_TARGET STREQUAL "INTEL" )
565
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} -fsycl OpenCL mkl_core pthread m dl mkl_sycl_blas mkl_intel_ilp64 mkl_tbb_thread )
568
+ list ( APPEND GGML_EXTRA_LIBS -fsycl OpenCL mkl_core pthread m dl mkl_sycl_blas mkl_intel_ilp64 mkl_tbb_thread )
566
569
elseif (GGML_SYCL_TARGET STREQUAL "NVIDIA" )
567
- set ( CMAKE_CXX_FLAGS " ${ CMAKE_CXX_FLAGS} -fsycl-targets=nvptx64-nvidia-cuda" )
568
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} -fsycl pthread m dl onemkl )
570
+ list ( APPEND CMAKE_CXX_FLAGS -fsycl-targets=nvptx64-nvidia-cuda )
571
+ list ( APPEND GGML_EXTRA_LIBS -fsycl pthread m dl onemkl )
569
572
endif ()
570
573
endif ()
571
574
if (${DNNL_FOUND} AND GGML_SYCL_TARGET STREQUAL "INTEL" )
@@ -579,7 +582,7 @@ if (GGML_RPC)
579
582
list (APPEND GGML_CDEF_PUBLIC GGML_USE_RPC )
580
583
581
584
if (WIN32 )
582
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} ws2_32 )
585
+ list ( APPEND GGML_EXTRA_LIBS ws2_32 )
583
586
endif ()
584
587
585
588
set (GGML_HEADERS_RPC ../include/ggml-rpc.h )
@@ -657,8 +660,8 @@ if (GGML_VULKAN)
657
660
set (GGML_HEADERS_VULKAN ${CMAKE_CURRENT_SOURCE_DIR} /../include/ggml-vulkan.h ${_ggml_vk_header} )
658
661
set (GGML_SOURCES_VULKAN ggml-vulkan.cpp ${_ggml_vk_source} )
659
662
660
- set ( GGML_EXTRA_LIBS ${GGML_EXTRA_LIBS} Vulkan::Vulkan )
661
- set ( GGML_EXTRA_INCLUDES ${ GGML_EXTRA_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} )
663
+ list ( APPEND GGML_EXTRA_LIBS Vulkan::Vulkan )
664
+ list ( APPEND GGML_EXTRA_INCLUDES ${CMAKE_CURRENT_BINARY_DIR} )
662
665
else ()
663
666
message (WARNING "Vulkan not found" )
664
667
endif ()
@@ -817,8 +820,8 @@ if (GGML_KOMPUTE)
817
820
818
821
list(APPEND GGML_CDEF_PUBLIC GGML_USE_KOMPUTE)
819
822
820
- set(GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} kompute)
821
- set(GGML_EXTRA_INCLUDES ${ GGML_EXTRA_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} )
823
+ list(APPEND GGML_EXTRA_LIBS kompute)
824
+ list(APPEND GGML_EXTRA_INCLUDES ${CMAKE_CURRENT_BINARY_DIR} )
822
825
else()
823
826
message(WARNING " Kompute not found ")
824
827
endif()
@@ -883,9 +886,10 @@ if (GGML_CANN)
883
886
message(STATUS " CANN: CANN_INCLUDE_DIRS = ${CANN_INCLUDE_DIRS} ")
884
887
message(STATUS " CANN: CANN_LIBRARIES = ${CANN_LIBRARIES} ")
885
888
886
- set(GGML_EXTRA_LIBS ${GGML_EXTRA_LIBS} ${CANN_LIBRARIES} )
887
- set(GGML_EXTRA_INCLUDES ${GGML_EXTRA_INCLUDES} ${CANN_INCLUDE_DIRS} )
888
- set(GGML_EXTRA_LIBDIRS ${GGML_EXTRA_LIBDIRS} ${CANN_INSTALL_DIR} /lib64)
889
+ list(APPEND GGML_EXTRA_LIBS ${CANN_LIBRARIES} )
890
+ list(APPEND GGML_EXTRA_INCLUDES ${CANN_INCLUDE_DIRS} )
891
+ list(APPEND GGML_EXTRA_LIBDIRS ${CANN_INSTALL_DIR} /lib64)
892
+
889
893
list(APPEND GGML_CDEF_PUBLIC GGML_USE_CANN)
890
894
endif()
891
895
else()
@@ -1322,12 +1326,14 @@ if (EMSCRIPTEN)
1322
1326
set_target_properties (ggml PROPERTIES COMPILE_FLAGS "-msimd128" )
1323
1327
endif ()
1324
1328
1325
- target_compile_definitions (ggml PUBLIC ${GGML_CDEF_PUBLIC} )
1326
- target_include_directories (ggml PUBLIC ../include )
1329
+ target_compile_definitions (ggml PUBLIC ${GGML_CDEF_PUBLIC} )
1330
+ target_include_directories (ggml PUBLIC ../include )
1327
1331
target_include_directories (ggml PRIVATE . ${GGML_EXTRA_INCLUDES} )
1328
- target_link_directories (ggml PRIVATE ${GGML_EXTRA_LIBDIRS} )
1332
+ target_link_directories (ggml PRIVATE ${GGML_EXTRA_LIBDIRS} )
1329
1333
target_compile_features (ggml PRIVATE c_std_11 ) # don't bump
1330
1334
1335
+ list (REMOVE_DUPLICATES GGML_EXTRA_LIBS )
1336
+
1331
1337
target_link_libraries (ggml PRIVATE Threads::Threads ${GGML_EXTRA_LIBS} )
1332
1338
1333
1339
find_library (MATH_LIBRARY m )
0 commit comments