target_set_arch.cmake (2289B)
1 if (EMSCRIPTEN) 2 function(target_set_arch TARGET MODE ARCH) 3 target_compile_options(${TARGET} ${MODE} -msse4.1) 4 endfunction() 5 elseif (X86) 6 7 function(target_set_arch TARGET MODE ARCH) 8 9 set(ARCH_FLAGS_GNU_generic -DCMT_FORCE_GENERIC_CPU) 10 set(ARCH_FLAGS_GNU_sse2 -msse2) 11 set(ARCH_FLAGS_GNU_sse3 -msse3) 12 set(ARCH_FLAGS_GNU_ssse3 -mssse3) 13 set(ARCH_FLAGS_GNU_sse41 -msse4.1) 14 set(ARCH_FLAGS_GNU_sse42 -msse4.2) 15 set(ARCH_FLAGS_GNU_avx -msse4.2 -mavx) 16 set(ARCH_FLAGS_GNU_avx2 -msse4.2 -mavx2 -mfma) 17 set(ARCH_FLAGS_GNU_avx512 -msse4.2 -mavx2 -mfma -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl) 18 19 if (BITNESS64) 20 # SSE2 is part of x86_64 21 set(ARCH_FLAG_MS_SSE2) 22 else() 23 set(ARCH_FLAG_MS_SSE2 -arch:SSE2) 24 endif() 25 26 set(ARCH_FLAGS_MS_generic ${ARCH_FLAG_MS_SSE2} -DCMT_FORCE_GENERIC_CPU) 27 set(ARCH_FLAGS_MS_sse2 ${ARCH_FLAG_MS_SSE2}) 28 set(ARCH_FLAGS_MS_sse3 ${ARCH_FLAG_MS_SSE2} -D__SSE3__) 29 set(ARCH_FLAGS_MS_ssse3 ${ARCH_FLAG_MS_SSE2} -D__SSSE3__) 30 set(ARCH_FLAGS_MS_sse41 ${ARCH_FLAG_MS_SSE2} -D__SSE3__ -D__SSSE3__ -D__SSE4_1__) 31 set(ARCH_FLAGS_MS_sse42 ${ARCH_FLAG_MS_SSE2} -D__SSE3__ -D__SSSE3__ -D__SSE4_1__ -D__SSE4_2__) 32 set(ARCH_FLAGS_MS_avx -arch:AVX) 33 set(ARCH_FLAGS_MS_avx2 -arch:AVX2) 34 set(ARCH_FLAGS_MS_avx512 -arch:AVX512) 35 36 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") 37 set(CLANG 1) 38 else () 39 set(CLANG 0) 40 endif() 41 if (CLANG OR NOT MSVC) 42 # Reset previous arch flags 43 if (BITNESS64) 44 target_compile_options(${TARGET} ${MODE} -mno-sse3) 45 else() 46 target_compile_options(${TARGET} ${MODE} -mno-sse) 47 endif() 48 endif () 49 if (MSVC AND NOT CLANG) 50 target_compile_options(${TARGET} ${MODE} ${ARCH_FLAGS_MS_${ARCH}}) 51 else() 52 target_compile_options(${TARGET} ${MODE} ${ARCH_FLAGS_GNU_${ARCH}}) 53 endif () 54 endfunction() 55 56 else() 57 58 function(target_set_arch TARGET MODE ARCH) 59 endfunction() 60 61 endif ()