@@ -72,7 +72,16 @@ if(CMAKE_OSX_ARCHITECTURES)
7272 # If multiple architectures are requested (universal build), pick only the first
7373 list (GET CMAKE_OSX_ARCHITECTURES 0 ARCH)
7474else ()
75- set (ARCH ${CMAKE_SYSTEM_PROCESSOR} )
75+ if (MSVC )
76+ if ("${MSVC_C_ARCHITECTURE_ID} " STREQUAL "ARM" OR "${MSVC_C_ARCHITECTURE_ID} " STREQUAL "ARMV7" )
77+ set (ARCH "arm" )
78+ elseif ("${MSVC_C_ARCHITECTURE_ID} " STREQUAL "ARM64" )
79+ set (ARCH "aarch64" )
80+ endif ()
81+ endif ()
82+ if (NOT ARCH)
83+ set (ARCH ${CMAKE_SYSTEM_PROCESSOR} )
84+ endif ()
7685endif ()
7786message (STATUS "Architecture: ${ARCH} " )
7887if (CMAKE_TOOLCHAIN_FILE)
@@ -156,7 +165,7 @@ elseif(MSVC)
156165 set (SSE2FLAG "/arch:SSE2" )
157166 endif ()
158167 if ("${ARCH} " MATCHES "arm" )
159- add_definitions (" -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1" )
168+ add_definitions (-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE)
160169 set (NEONFLAG "/arch:VFPv4" )
161170 endif ()
162171 if (WITH_NATIVE_INSTRUCTIONS)
@@ -174,13 +183,27 @@ else()
174183 message (STATUS "Ignoring WITH_NATIVE_INSTRUCTIONS; not implemented yet on this configuration" )
175184 endif ()
176185 endif ()
177- if (__GNUC__ AND "${ARCH} " MATCHES "arm" )
178- execute_process (COMMAND ${CMAKE_C_COMPILER} "-dumpmachine"
179- OUTPUT_VARIABLE GCC_MACHINE)
180- if ("${GCC_MACHINE} " MATCHES "eabihf" )
181- set (FLOATABI "-mfloat-abi=hard" )
186+ # Check support for ARM floating point
187+ if ("${ARCH} " MATCHES "arm" )
188+ if (__GNUC__)
189+ execute_process (COMMAND ${CMAKE_C_COMPILER} "-dumpmachine"
190+ OUTPUT_VARIABLE GCC_MACHINE)
191+ if ("${GCC_MACHINE} " MATCHES "eabihf" )
192+ set (FLOATABI "-mfloat-abi=hard" )
193+ else ()
194+ set (FLOATABI "-mfloat-abi=softfp" )
195+ endif ()
196+ endif ()
197+ # Check whether -mfpu=neon is available
198+ set (CMAKE_REQUIRED_FLAGS "-mfpu=neon" )
199+ check_c_source_compiles(
200+ "int main() { return 0; }"
201+ MFPU_NEON_AVAILABLE FAIL_REGEX "not supported" )
202+ set (CMAKE_REQUIRED_FLAGS)
203+ if (MFPU_NEON_AVAILABLE)
204+ set (NEONFLAG "${FLOATABI} -mfpu=neon" )
182205 else ()
183- set (FLOATABI "-mfloat-abi=softfp " )
206+ set (NEONFLAG " ${FLOATABI} " )
184207 endif ()
185208 endif ()
186209 if (NOT NATIVEFLAG)
@@ -201,7 +224,6 @@ else()
201224 endif ()
202225 if ("${ARCH} " MATCHES "arm" )
203226 set (ACLEFLAG "-march=armv8-a+crc" )
204- set (NEONFLAG "${FLOATABI} -mfpu=neon" )
205227 elseif ("${ARCH} " MATCHES "aarch64" )
206228 set (ACLEFLAG "-march=armv8-a+crc" )
207229 set (NEONFLAG "-march=armv8-a+crc+simd" )
@@ -212,7 +234,6 @@ else()
212234 set (PCLMULFLAG ${NATIVEFLAG} )
213235 if ("${ARCH} " MATCHES "arm" )
214236 set (ACLEFLAG "${NATIVEFLAG} " )
215- set (NEONFLAG "${FLOATABI} -mfpu=neon" )
216237 elseif ("${ARCH} " MATCHES "aarch64" )
217238 set (ACLEFLAG "${NATIVEFLAG} " )
218239 set (NEONFLAG "${NATIVEFLAG} " )
@@ -483,16 +504,6 @@ else()
483504endif ()
484505set (CMAKE_REQUIRED_FLAGS)
485506
486- # Check whether -mfpu=neon is available
487- set (CMAKE_REQUIRED_FLAGS "-mfpu=neon" )
488- check_c_source_compiles(
489- "int main()
490- {
491- return 0;
492- }"
493- MFPU_NEON_AVAILABLE FAIL_REGEX "not supported" )
494- set (CMAKE_REQUIRED_FLAGS)
495-
496507# FORCE_SSE2 option will only be shown if HAVE_SSE2_INTRIN is true
497508if ("${ARCH} " MATCHES "i[3-6]86" )
498509 cmake_dependent_option(FORCE_SSE2 "Always assume CPU is SSE2 capable" OFF "HAVE_SSE2_INTRIN" OFF )
@@ -542,39 +553,25 @@ if("${ARCH}" MATCHES "arm" OR "${ARCH}" MATCHES "aarch64")
542553 set (ZLIB_ARCH_SRCS ${ZLIB_ARCH_SRCS} ${ARCHDIR} /armfeature.c ${ARCHDIR} /fill_window_arm.c)
543554endif ()
544555if (WITH_OPTIM)
545- if ("${ARCH} " MATCHES "arm" )
546- if (WITH_ACLE)
547- set (ZLIB_ARCH_SRCS ${ZLIB_ARCH_SRCS} ${ARCHDIR} /crc32_acle.c ${ARCHDIR} /insert_string_acle.c)
548- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ACLEFLAG} " )
549- add_definitions ("-DARM_ACLE_CRC_HASH" )
550- add_feature_info(ACLE_CRC 1 "Support CRC hash generation using the ACLE instruction set, using \" ${ACLEFLAG} \" " )
551- endif ()
556+ if ("${ARCH} " MATCHES "arm" OR "${ARCH} " MATCHES "aarch64" )
552557 if (WITH_NEON)
553- if (MFPU_NEON_AVAILABLE)
554- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NEONFLAG} " )
555- endif ()
556- add_definitions ("-DARM_NEON_ADLER32" )
557- if (MSVC )
558- add_definitions ("-D__ARM_NEON__=1" )
559- endif (MSVC )
560558 set (ZLIB_ARCH_SRCS ${ZLIB_ARCH_SRCS} ${ARCHDIR} /adler32_neon.c)
559+ add_definitions (-DARM_NEON_ADLER32)
560+ add_intrinsics_option("${NEONFLAG} " )
561+ if (MSVC )
562+ add_definitions (-D__ARM_NEON__)
563+ endif ()
561564 add_feature_info(NEON_FILLWINDOW 1 "Support NEON instructions in fill_window_arm, using \" ${NEONFLAG} \" " )
562565 endif ()
563- elseif ("${ARCH} " MATCHES "aarch64" )
564566 if (WITH_ACLE)
565567 set (ZLIB_ARCH_SRCS ${ZLIB_ARCH_SRCS} ${ARCHDIR} /crc32_acle.c ${ARCHDIR} /insert_string_acle.c)
566- add_definitions ("-DARM_ACLE_CRC_HASH" )
568+ add_definitions (-DARM_ACLE_CRC_HASH)
569+ # For ARM aarch64, we need to check WITH_NEON first
570+ if ("${ARCH} " MATCHES "arm" OR NOT WITH_NEON)
571+ add_intrinsics_option("${ACLEFLAG} " )
572+ endif ()
567573 add_feature_info(ACLE_CRC 1 "Support CRC hash generation using the ACLE instruction set, using \" ${ACLEFLAG} \" " )
568574 endif ()
569- # We need to check WITH_NEON first
570- if (WITH_NEON)
571- add_definitions ("-DARM_NEON_ADLER32" )
572- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NEONFLAG} " )
573- set (ZLIB_ARCH_SRCS ${ZLIB_ARCH_SRCS} ${ARCHDIR} /adler32_neon.c)
574- add_feature_info(NEON_FILLWINDOW 1 "Support NEON instructions in fill_window_arm, using \" ${NEONFLAG} \" " )
575- elseif (WITH_ACLE)
576- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ACLEFLAG} " )
577- endif ()
578575 elseif ("${ARCHDIR} " MATCHES "arch/x86" )
579576 add_definitions ("-DX86_CPUID" )
580577 set (ZLIB_ARCH_SRCS ${ZLIB_ARCH_SRCS} ${ARCHDIR} /x86.c)
0 commit comments