@@ -26,6 +26,8 @@ if (NOT MSVC)
2626 endif ()
2727endif ()
2828
29+ unset (GGML_EXTRA_LIBS)
30+
2931if (APPLE AND GGML_ACCELERATE)
3032 find_library (ACCELERATE_FRAMEWORK Accelerate)
3133 if (ACCELERATE_FRAMEWORK)
@@ -35,7 +37,7 @@ if (APPLE AND GGML_ACCELERATE)
3537 add_compile_definitions (ACCELERATE_NEW_LAPACK)
3638 add_compile_definitions (ACCELERATE_LAPACK_ILP64)
3739
38- set (GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} ${ACCELERATE_FRAMEWORK} )
40+ list ( APPEND GGML_EXTRA_LIBS ${ACCELERATE_FRAMEWORK} )
3941 else ()
4042 message (WARNING "Accelerate framework not found" )
4143 endif ()
@@ -87,7 +89,7 @@ if (GGML_METAL)
8789 COMMENT "Generate assembly for embedded Metal library"
8890 )
8991
90- set (GGML_SOURCES_METAL ${ GGML_SOURCES_METAL} ${METALLIB_EMBED_ASM} )
92+ list ( APPEND GGML_SOURCES_METAL ${METALLIB_EMBED_ASM} )
9193 else ()
9294 if (GGML_METAL_SHADER_DEBUG)
9395 # custom command to do the following:
@@ -132,7 +134,7 @@ if (GGML_METAL)
132134 )
133135 endif () # GGML_METAL_EMBED_LIBRARY
134136
135- set (GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS}
137+ list ( APPEND GGML_EXTRA_LIBS
136138 ${FOUNDATION_LIBRARY}
137139 ${METAL_FRAMEWORK}
138140 ${METALKIT_FRAMEWORK}
@@ -157,11 +159,11 @@ if (GGML_OPENMP)
157159
158160 add_compile_definitions (GGML_USE_OPENMP)
159161
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)
161163
162164 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" )
165167 endif ()
166168 else ()
167169 message (WARNING "OpenMP not found" )
@@ -244,8 +246,8 @@ if (GGML_BLAS)
244246 set (GGML_HEADERS_BLAS ../include /ggml-blas.h)
245247 set (GGML_SOURCES_BLAS ggml-blas.cpp)
246248
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} )
249251 else ()
250252 message (WARNING "BLAS not found, please refer to "
251253 "https://cmake.org/cmake/help/latest/module/FindBLAS.html#blas-lapack-vendors"
@@ -368,29 +370,29 @@ if (GGML_CUDA)
368370 if (GGML_STATIC)
369371 if (WIN32 )
370372 # 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)
372374 else ()
373375 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)
375377 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)
377379 endif ()
378380 endif ()
379381 else ()
380382 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)
382384 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)
384386 endif ()
385387 endif ()
386388
387389 if (GGML_CUDA_NO_VMM)
388390 # No VMM requested, no need to link directly with the cuda driver lib (libcuda.so)
389391 else ()
390392 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(...), ...
392394 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(...), ...
394396 endif ()
395397 endif ()
396398 else ()
@@ -495,7 +497,7 @@ if (GGML_HIPBLAS)
495497
496498 if (CXX_IS_HIPCC)
497499 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)
499501 else ()
500502 set_source_files_properties (${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE HIP)
501503 endif ()
@@ -504,7 +506,8 @@ if (GGML_HIPBLAS)
504506 message (FATAL_ERROR "Static linking not supported for HIP/ROCm" )
505507 endif ()
506508
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)
508511endif ()
509512
510513if (GGML_SYCL)
@@ -513,7 +516,8 @@ if (GGML_SYCL)
513516 endif ()
514517
515518 check_cxx_compiler_flag("-fsycl" SUPPORTS_SYCL)
516- if ( DEFINED ENV{ONEAPI_ROOT})
519+
520+ if (DEFINED ENV{ONEAPI_ROOT})
517521 message (STATUS "Using oneAPI Release SYCL compiler (icpx)." )
518522 elseif (SUPPORTS_SYCL)
519523 message (WARNING "Using open-source SYCL compiler (clang++). Didn't detect ENV {ONEAPI_ROOT}.
@@ -551,21 +555,27 @@ if (GGML_SYCL)
551555
552556 find_package (DNNL)
553557 message ("-- DNNL found:" ${DNNL_FOUND} )
558+
554559 if (GGML_SYCL_TARGET STREQUAL "INTEL" )
555560 add_compile_definitions (GGML_SYCL_DNNL=${DNNL_FOUND} )
556561 else ()
557562 add_compile_definitions (GGML_SYCL_DNNL=0)
558563 endif ()
564+
565+ if (${DNNL_FOUND} AND GGML_SYCL_TARGET STREQUAL "INTEL" )
566+ list (APPEND GGML_EXTRA_LIBS DNNL::dnnl)
567+ endif ()
568+
559569 if (WIN32 )
560570 find_package (IntelSYCL REQUIRED)
561571 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)
563573 else ()
564574 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)
566576 elseif (GGML_SYCL_TARGET STREQUAL "NVIDIA" )
567577 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)
569579 endif ()
570580 endif ()
571581 if (${DNNL_FOUND} AND GGML_SYCL_TARGET STREQUAL "INTEL" )
@@ -579,7 +589,7 @@ if (GGML_RPC)
579589 list (APPEND GGML_CDEF_PUBLIC GGML_USE_RPC)
580590
581591 if (WIN32 )
582- set (GGML_EXTRA_LIBS ${ GGML_EXTRA_LIBS} ws2_32)
592+ list ( APPEND GGML_EXTRA_LIBS ws2_32)
583593 endif ()
584594
585595 set (GGML_HEADERS_RPC ../include /ggml-rpc.h)
@@ -657,8 +667,8 @@ if (GGML_VULKAN)
657667 set (GGML_HEADERS_VULKAN ${CMAKE_CURRENT_SOURCE_DIR} /../include /ggml-vulkan.h ${_ggml_vk_header} )
658668 set (GGML_SOURCES_VULKAN ggml-vulkan.cpp ${_ggml_vk_source} )
659669
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} )
662672 else ()
663673 message (WARNING "Vulkan not found" )
664674 endif ()
@@ -817,8 +827,8 @@ if (GGML_KOMPUTE)
817827
818828 list (APPEND GGML_CDEF_PUBLIC GGML_USE_KOMPUTE)
819829
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} )
822832 else ()
823833 message (WARNING "Kompute not found" )
824834 endif ()
@@ -883,9 +893,10 @@ if (GGML_CANN)
883893 message (STATUS "CANN: CANN_INCLUDE_DIRS = ${CANN_INCLUDE_DIRS} " )
884894 message (STATUS "CANN: CANN_LIBRARIES = ${CANN_LIBRARIES} " )
885895
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+
889900 list (APPEND GGML_CDEF_PUBLIC GGML_USE_CANN)
890901 endif ()
891902 else ()
@@ -1322,12 +1333,14 @@ if (EMSCRIPTEN)
13221333 set_target_properties (ggml PROPERTIES COMPILE_FLAGS "-msimd128" )
13231334endif ()
13241335
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 )
13271338target_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} )
13291340target_compile_features (ggml PRIVATE c_std_11) # don't bump
13301341
1342+ list (REMOVE_DUPLICATES GGML_EXTRA_LIBS)
1343+
13311344target_link_libraries (ggml PRIVATE Threads::Threads ${GGML_EXTRA_LIBS} )
13321345
13331346find_library (MATH_LIBRARY m)
0 commit comments