@@ -594,6 +594,13 @@ if (NOT MSVC)
594
594
endif ()
595
595
endif ()
596
596
597
+ function (add_compile_option_cpp ARG )
598
+ # Adds a compile option to C/C++ only, but not for Cuda.
599
+ # Use, e.g., for CPU-architecture flags.
600
+ add_compile_options ($< $< COMPILE_LANGUAGE:CXX> :${ARG} > )
601
+ add_compile_options ($< $< COMPILE_LANGUAGE:C> :${ARG} > )
602
+ endfunction ()
603
+
597
604
if ((${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" ) OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64" ) OR ("${CMAKE_GENERATOR_PLATFORM_LWR} " MATCHES "arm64" ))
598
605
message (STATUS "ARM detected" )
599
606
if (MSVC )
@@ -628,8 +635,7 @@ elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|i686|AMD64)$" OR "${CMAKE_GE
628
635
include (cmake/FindSIMD.cmake )
629
636
endif ()
630
637
if (LLAMA_AVX512 )
631
- add_compile_options ($< $< COMPILE_LANGUAGE:C> :/arch:AVX512> )
632
- add_compile_options ($< $< COMPILE_LANGUAGE:CXX> :/arch:AVX512> )
638
+ add_compile_option_cpp (/arch:AVX512 )
633
639
# MSVC has no compile-time flags enabling specific
634
640
# AVX512 extensions, neither it defines the
635
641
# macros corresponding to the extensions.
@@ -643,37 +649,35 @@ elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|i686|AMD64)$" OR "${CMAKE_GE
643
649
add_compile_definitions ($< $< COMPILE_LANGUAGE:CXX> :__AVX512VNNI__> )
644
650
endif ()
645
651
elseif (LLAMA_AVX2 )
646
- add_compile_options ($< $< COMPILE_LANGUAGE:C> :/arch:AVX2> )
647
- add_compile_options ($< $< COMPILE_LANGUAGE:CXX> :/arch:AVX2> )
652
+ add_compile_option_cpp (/arch:AVX2 )
648
653
elseif (LLAMA_AVX )
649
- add_compile_options ($< $< COMPILE_LANGUAGE:C> :/arch:AVX> )
650
- add_compile_options ($< $< COMPILE_LANGUAGE:CXX> :/arch:AVX> )
654
+ add_compile_option_cpp (/arch:AVX )
651
655
endif ()
652
656
else ()
653
657
if (LLAMA_NATIVE )
654
- add_compile_options (-march=native )
658
+ add_compile_option_cpp (-march=native )
655
659
endif ()
656
660
if (LLAMA_F16C )
657
- add_compile_options (-mf16c )
661
+ add_compile_option_cpp (-mf16c )
658
662
endif ()
659
663
if (LLAMA_FMA )
660
- add_compile_options (-mfma )
664
+ add_compile_option_cpp (-mfma )
661
665
endif ()
662
666
if (LLAMA_AVX )
663
- add_compile_options (-mavx )
667
+ add_compile_option_cpp (-mavx )
664
668
endif ()
665
669
if (LLAMA_AVX2 )
666
- add_compile_options (-mavx2 )
670
+ add_compile_option_cpp (-mavx2 )
667
671
endif ()
668
672
if (LLAMA_AVX512 )
669
- add_compile_options (-mavx512f )
670
- add_compile_options (-mavx512bw )
673
+ add_compile_option_cpp (-mavx512f )
674
+ add_compile_option_cpp (-mavx512bw )
671
675
endif ()
672
676
if (LLAMA_AVX512_VBMI )
673
- add_compile_options (-mavx512vbmi )
677
+ add_compile_option_cpp (-mavx512vbmi )
674
678
endif ()
675
679
if (LLAMA_AVX512_VNNI )
676
- add_compile_options (-mavx512vnni )
680
+ add_compile_option_cpp (-mavx512vnni )
677
681
endif ()
678
682
endif ()
679
683
elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "ppc64" )
0 commit comments