Skip to content

Commit 5c6ab53

Browse files
committed
make MI_OPT_ARCH by default OFF except for arm64 where we assume v8.1-a for fast atomics
1 parent 4389034 commit 5c6ab53

File tree

1 file changed

+36
-41
lines changed

1 file changed

+36
-41
lines changed

CMakeLists.txt

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ option(MI_TRACK_VALGRIND "Compile with Valgrind support (adds a small overhea
1414
option(MI_TRACK_ASAN "Compile with address sanitizer support (adds a small overhead)" OFF)
1515
option(MI_TRACK_ETW "Compile with Windows event tracing (ETW) support (adds a small overhead)" OFF)
1616
option(MI_USE_CXX "Use the C++ compiler to compile the library (instead of the C compiler)" OFF)
17-
option(MI_OPT_ARCH "Only for optimized builds: turn on architecture specific optimizations (for arm64: '-march=armv8.1-a' (2016))" ON)
17+
option(MI_OPT_ARCH "Only for optimized builds: turn on architecture specific optimizations (for arm64: '-march=armv8.1-a' (2016))" OFF)
1818
option(MI_SEE_ASM "Generate assembly files" OFF)
1919
option(MI_OSX_INTERPOSE "Use interpose to override standard malloc on macOS" ON)
2020
option(MI_OSX_ZONE "Use malloc zone to override standard malloc on macOS" ON)
@@ -116,9 +116,44 @@ if("${CMAKE_BINARY_DIR}" MATCHES ".*(S|s)ecure$")
116116
set(MI_SECURE "ON")
117117
endif()
118118

119+
120+
# Determine architecture
121+
set(MI_OPT_ARCH_FLAGS "")
122+
set(MI_ARCH "unknown")
123+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86|i[3456]86)$" OR CMAKE_GENERATOR_PLATFORM MATCHES "^(x86|Win32)$")
124+
set(MI_ARCH "x86")
125+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|x64|amd64|AMD64)$" OR CMAKE_GENERATOR_PLATFORM STREQUAL "x64" OR "x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES) # must be before arm64
126+
set(MI_ARCH "x64")
127+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|armv[89].?|ARM64)$" OR CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64" OR "arm64" IN_LIST CMAKE_OSX_ARCHITECTURES)
128+
set(MI_ARCH "arm64")
129+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|armv[34567]|ARM)$")
130+
set(MI_ARCH "arm32")
131+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv|riscv32|riscv64)$")
132+
if(CMAKE_SIZEOF_VOID_P==4)
133+
set(MI_ARCH "riscv32")
134+
else()
135+
set(MI_ARCH "riscv64")
136+
endif()
137+
else()
138+
set(MI_ARCH ${CMAKE_SYSTEM_PROCESSOR})
139+
endif()
140+
message(STATUS "Architecture: ${MI_ARCH}") # (${CMAKE_SYSTEM_PROCESSOR}, ${CMAKE_GENERATOR_PLATFORM}, ${CMAKE_GENERATOR})")
141+
142+
# negative overrides (mainly to support vcpkg features)
143+
if(MI_NO_USE_CXX)
144+
set(MI_USE_CXX "OFF")
145+
endif()
146+
if(MI_NO_OPT_ARCH)
147+
set(MI_OPT_ARCH "OFF")
148+
elseif(MI_ARCH STREQUAL "arm64")
149+
set(MI_OPT_ARCH "ON") # enable armv8.1-a by default on arm64 unless MI_NO_OPT_ARCH is set
150+
endif()
151+
152+
119153
# -----------------------------------------------------------------------------
120154
# Process options
121155
# -----------------------------------------------------------------------------
156+
122157
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
123158
set(MI_CLANG_CL "ON")
124159
endif()
@@ -138,27 +173,10 @@ if(CMAKE_C_COMPILER_ID MATCHES "Intel")
138173
list(APPEND mi_cflags -Wall)
139174
endif()
140175

141-
# negative overrides (mainly to support vcpkg features)
142-
if(MI_NO_USE_CXX)
143-
set(MI_USE_CXX "OFF")
144-
endif()
145-
if(MI_NO_OPT_ARCH)
146-
set(MI_OPT_ARCH "OFF")
147-
endif()
148-
149-
150176
if(CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel")
151177
set(MI_USE_CXX "ON")
152178
endif()
153179

154-
if(CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo")
155-
if (NOT MI_OPT_ARCH)
156-
message(STATUS "Architecture specific optimizations are disabled (MI_OPT_ARCH=OFF)")
157-
endif()
158-
else()
159-
set(MI_OPT_ARCH OFF)
160-
endif()
161-
162180
if(MI_OVERRIDE)
163181
message(STATUS "Override standard malloc (MI_OVERRIDE=ON)")
164182
if(APPLE)
@@ -365,28 +383,6 @@ if(MI_WIN_USE_FIXED_TLS)
365383
list(APPEND mi_defines MI_WIN_USE_FIXED_TLS=1)
366384
endif()
367385

368-
# Determine architecture
369-
set(MI_OPT_ARCH_FLAGS "")
370-
set(MI_ARCH "unknown")
371-
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86|i[3456]86)$" OR CMAKE_GENERATOR_PLATFORM MATCHES "^(x86|Win32)$")
372-
set(MI_ARCH "x86")
373-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|x64|amd64|AMD64)$" OR CMAKE_GENERATOR_PLATFORM STREQUAL "x64" OR "x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES) # must be before arm64
374-
set(MI_ARCH "x64")
375-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|armv[89].?|ARM64)$" OR CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64" OR "arm64" IN_LIST CMAKE_OSX_ARCHITECTURES)
376-
set(MI_ARCH "arm64")
377-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|armv[34567]|ARM)$")
378-
set(MI_ARCH "arm32")
379-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv|riscv32|riscv64)$")
380-
if(CMAKE_SIZEOF_VOID_P==4)
381-
set(MI_ARCH "riscv32")
382-
else()
383-
set(MI_ARCH "riscv64")
384-
endif()
385-
else()
386-
set(MI_ARCH ${CMAKE_SYSTEM_PROCESSOR})
387-
endif()
388-
message(STATUS "Architecture: ${MI_ARCH}") # (${CMAKE_SYSTEM_PROCESSOR}, ${CMAKE_GENERATOR_PLATFORM}, ${CMAKE_GENERATOR})")
389-
390386
# Check /proc/cpuinfo for an SV39 MMU and limit the virtual address bits.
391387
# (this will skip the aligned hinting in that case. Issue #939, #949)
392388
if (EXISTS /proc/cpuinfo)
@@ -439,7 +435,6 @@ endif()
439435
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU|Intel" AND NOT CMAKE_SYSTEM_NAME MATCHES "Haiku")
440436
if(MI_OPT_ARCH)
441437
if(APPLE AND CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_OSX_ARCHITECTURES) # to support multi-arch binaries (#999)
442-
set(MI_OPT_ARCH_FLAGS "")
443438
if("arm64" IN_LIST CMAKE_OSX_ARCHITECTURES)
444439
list(APPEND MI_OPT_ARCH_FLAGS "-Xarch_arm64;-march=armv8.1-a")
445440
endif()

0 commit comments

Comments
 (0)