@@ -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 )
@@ -513,7 +516,8 @@ if (GGML_SYCL)
513
516
endif ()
514
517
515
518
check_cxx_compiler_flag ("-fsycl" SUPPORTS_SYCL )
516
- if ( DEFINED ENV{ONEAPI_ROOT} )
519
+
520
+ if (DEFINED ENV{ONEAPI_ROOT} )
517
521
message (STATUS "Using oneAPI Release SYCL compiler (icpx)." )
518
522
elseif (SUPPORTS_SYCL )
519
523
message (WARNING "Using open-source SYCL compiler (clang++). Didn't detect ENV {ONEAPI_ROOT}.
@@ -551,21 +555,27 @@ if (GGML_SYCL)
551
555
552
556
find_package (DNNL )
553
557
message ("-- DNNL found:" ${DNNL_FOUND} )
558
+
554
559
if (GGML_SYCL_TARGET STREQUAL "INTEL" )
555
560
add_compile_definitions (GGML_SYCL_DNNL=${DNNL_FOUND} )
556
561
else ()
557
562
add_compile_definitions (GGML_SYCL_DNNL=0 )
558
563
endif ()
564
+
565
+ if (${DNNL_FOUND} AND GGML_SYCL_TARGET STREQUAL "INTEL" )
566
+ list (APPEND GGML_EXTRA_LIBS DNNL::dnnl )
567
+ endif ()
568
+
559
569
if (WIN32 )
560
570
find_package (IntelSYCL REQUIRED )
561
571
find_package (MKL REQUIRED )
562
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} IntelSYCL::SYCL_CXX MKL::MKL MKL::MKL_SYCL )
572
+ list ( APPEND GGML_EXTRA_LIBS IntelSYCL::SYCL_CXX MKL::MKL MKL::MKL_SYCL )
563
573
else ()
564
574
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 )
575
+ list ( APPEND GGML_EXTRA_LIBS OpenCL mkl_core pthread m dl mkl_sycl_blas mkl_intel_ilp64 mkl_tbb_thread )
566
576
elseif (GGML_SYCL_TARGET STREQUAL "NVIDIA" )
567
577
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 )
578
+ list ( APPEND GGML_EXTRA_LIBS pthread m dl onemkl )
569
579
endif ()
570
580
endif ()
571
581
if (${DNNL_FOUND} AND GGML_SYCL_TARGET STREQUAL "INTEL" )
@@ -579,7 +589,7 @@ if (GGML_RPC)
579
589
list (APPEND GGML_CDEF_PUBLIC GGML_USE_RPC )
580
590
581
591
if (WIN32 )
582
- set ( GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} ws2_32 )
592
+ list ( APPEND GGML_EXTRA_LIBS ws2_32 )
583
593
endif ()
584
594
585
595
set (GGML_HEADERS_RPC ../include/ggml-rpc.h )
@@ -657,8 +667,8 @@ if (GGML_VULKAN)
657
667
set (GGML_HEADERS_VULKAN ${CMAKE_CURRENT_SOURCE_DIR} /../include/ggml-vulkan.h ${_ggml_vk_header} )
658
668
set (GGML_SOURCES_VULKAN ggml-vulkan.cpp ${_ggml_vk_source} )
659
669
660
- set ( GGML_EXTRA_LIBS ${GGML_EXTRA_LIBS} Vulkan::Vulkan )
661
- set ( GGML_EXTRA_INCLUDES ${ GGML_EXTRA_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} )
670
+ list ( APPEND GGML_EXTRA_LIBS Vulkan::Vulkan )
671
+ list ( APPEND GGML_EXTRA_INCLUDES ${CMAKE_CURRENT_BINARY_DIR} )
662
672
else ()
663
673
message (WARNING "Vulkan not found" )
664
674
endif ()
@@ -817,8 +827,8 @@ if (GGML_KOMPUTE)
817
827
818
828
list(APPEND GGML_CDEF_PUBLIC GGML_USE_KOMPUTE)
819
829
820
- set(GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} kompute)
821
- set(GGML_EXTRA_INCLUDES ${ GGML_EXTRA_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} )
830
+ list(APPEND GGML_EXTRA_LIBS kompute)
831
+ list(APPEND GGML_EXTRA_INCLUDES ${CMAKE_CURRENT_BINARY_DIR} )
822
832
else()
823
833
message(WARNING " Kompute not found ")
824
834
endif()
@@ -883,9 +893,10 @@ if (GGML_CANN)
883
893
message(STATUS " CANN: CANN_INCLUDE_DIRS = ${CANN_INCLUDE_DIRS} ")
884
894
message(STATUS " CANN: CANN_LIBRARIES = ${CANN_LIBRARIES} ")
885
895
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)
896
+ list(APPEND GGML_EXTRA_LIBS ${CANN_LIBRARIES} )
897
+ list(APPEND GGML_EXTRA_INCLUDES ${CANN_INCLUDE_DIRS} )
898
+ list(APPEND GGML_EXTRA_LIBDIRS ${CANN_INSTALL_DIR} /lib64)
899
+
889
900
list(APPEND GGML_CDEF_PUBLIC GGML_USE_CANN)
890
901
endif()
891
902
else()
@@ -1322,12 +1333,14 @@ if (EMSCRIPTEN)
1322
1333
set_target_properties (ggml PROPERTIES COMPILE_FLAGS "-msimd128" )
1323
1334
endif ()
1324
1335
1325
- target_compile_definitions (ggml PUBLIC ${GGML_CDEF_PUBLIC} )
1326
- target_include_directories (ggml PUBLIC ../include )
1336
+ target_compile_definitions (ggml PUBLIC ${GGML_CDEF_PUBLIC} )
1337
+ target_include_directories (ggml PUBLIC ../include )
1327
1338
target_include_directories (ggml PRIVATE . ${GGML_EXTRA_INCLUDES} )
1328
- target_link_directories (ggml PRIVATE ${GGML_EXTRA_LIBDIRS} )
1339
+ target_link_directories (ggml PRIVATE ${GGML_EXTRA_LIBDIRS} )
1329
1340
target_compile_features (ggml PRIVATE c_std_11 ) # don't bump
1330
1341
1342
+ list (REMOVE_DUPLICATES GGML_EXTRA_LIBS )
1343
+
1331
1344
target_link_libraries (ggml PRIVATE Threads::Threads ${GGML_EXTRA_LIBS} )
1332
1345
1333
1346
find_library (MATH_LIBRARY m )
0 commit comments