Skip to content

Commit aeaf41c

Browse files
sidwats.watsa
andauthored
Macos ios build support (#151)
* Added x86 macro protection to avx code Signed-off-by: s.watsa <[email protected]> * Added UNIVERSAL definition to include both neon and avx codes for universal builds Signed-off-by: s.watsa <[email protected]> * Added toolchain file for ios arm64 build Signed-off-by: s.watsa <[email protected]> * Added toolchain for macos universal builds (both x86 and arm64) Signed-off-by: s.watsa <[email protected]> --------- Signed-off-by: s.watsa <[email protected]> Co-authored-by: s.watsa <[email protected]>
1 parent 0a681ce commit aeaf41c

File tree

6 files changed

+67
-3
lines changed

6 files changed

+67
-3
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ else()
8888
set(ARM "TRUE")
8989
endif()
9090

91+
# To build for universal architectures provide in command line: -DUNIVERSAL=TRUE
92+
if(NOT UNIVERSAL)
93+
set(UNIVERSAL "FALSE")
94+
else()
95+
add_definitions(-DUNIVERSAL=1)
96+
set(UNIVERSAL "TRUE")
97+
endif()
98+
9199
########################################
92100
# Compilation flags
93101
########################################

ios_arm64_toolchain.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Basic system configuration
2+
set(CMAKE_SYSTEM_NAME Darwin) # Darwin is the core of macOS/iOS
3+
set(CMAKE_SYSTEM_PROCESSOR arm64) # Target ARM64 architecture
4+
set(CMAKE_OSX_ARCHITECTURES arm64) # Build only for arm64 (no x86_64)
5+
set(CMAKE_OSX_DEPLOYMENT_TARGET 12.0) # Minimum iOS version support
6+
7+
# Compiler configuration
8+
set(CMAKE_C_COMPILER "/usr/bin/clang") # Path to Apple's clang for C
9+
set(CMAKE_CXX_COMPILER "/usr/bin/clang++") # Path to Apple's clang++ for C++
10+
11+
# SDK configuration
12+
set(CMAKE_OSX_SYSROOT iphoneos) # Use iOS SDK (automatically found by Xcode)
13+
14+
# Cross-compilation search behavior
15+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # Don't search for programs in sysroot
16+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) # Only search for libraries in sysroot
17+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # Only search for includes in sysroot
18+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) # Only search for packages in sysroot
19+
20+
# Compiler flags
21+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch arm64 -fembed-bitcode -isysroot ${CMAKE_OSX_SYSROOT}")
22+
# -arch arm64: Target ARM64 architecture
23+
# -fembed-bitcode: Include bitcode for App Store submission
24+
# -isysroot: Specify iOS SDK path
25+
26+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch arm64 -fembed-bitcode -isysroot ${CMAKE_OSX_SYSROOT}")
27+
# Same flags for C++ compilation
28+
29+
# Mark as iOS build
30+
set(IOS TRUE) # Can be used in CMakeLists.txt for iOS-specific logic

macos_universal_toolchain.cmake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
set(CMAKE_SYSTEM_NAME Darwin)
2+
set(CMAKE_SYSTEM_PROCESSOR universal)
3+
4+
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Build architectures for macOS")
5+
6+
# Standard compiler settings for macOS
7+
set(CMAKE_C_COMPILER "/usr/bin/clang")
8+
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
9+
10+
# Find programs in the host environment
11+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
12+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
13+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
14+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
15+
16+
# Disable codesigning for command-line tools to simplify builds
17+
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
18+
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
19+
20+
message(STATUS "Using macOS Universal Toolchain for OAPV.")
21+
message(STATUS "Target architectures: ${CMAKE_OSX_ARCHITECTURES}")
22+
message(STATUS "UNIVERSAL build option enabled: ${UNIVERSAL}")

src/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ endif()
3737

3838
if(ARM)
3939
set(SOURCE_FILES ${LIB_API_SRC} ${LIB_INC} ${LIB_BASE_SRC} ${LIB_BASE_INC} ${LIB_NEON_SRC} ${LIB_NEON_INC})
40+
elseif(UNIVERSAL)
41+
set(SOURCE_FILES ${LIB_API_SRC} ${LIB_INC} ${LIB_BASE_SRC} ${LIB_BASE_INC} ${LIB_SSE_SRC} ${LIB_SSE_INC} ${LIB_AVX_SRC} ${LIB_AVX_INC} ${LIB_NEON_SRC} ${LIB_NEON_INC})
4042
elseif(X86)
4143
set(SOURCE_FILES ${LIB_API_SRC} ${LIB_INC} ${LIB_BASE_SRC} ${LIB_BASE_INC} ${LIB_SSE_SRC} ${LIB_SSE_INC} ${LIB_AVX_SRC} ${LIB_AVX_INC})
4244
else()
@@ -106,7 +108,7 @@ if(MSVC)
106108
elseif(UNIX OR MINGW)
107109
if (ARM)
108110
set_property(SOURCE ${NEON} APPEND PROPERTY COMPILE_FLAGS "-flax-vector-conversions")
109-
elseif (X86)
111+
elseif (X86 OR UNIVERSAL)
110112
set_property(SOURCE ${SSE} APPEND PROPERTY COMPILE_FLAGS "-msse4.1")
111113
set_property(SOURCE ${AVX} APPEND PROPERTY COMPILE_FLAGS " -mavx2")
112114
endif()

src/avx/oapv_sad_avx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
#define _OAPV_SAD_AVX_H_
3434

3535
#include "oapv_def.h"
36+
#if X86_SSE
3637
#include <immintrin.h>
3738

38-
#if X86_SSE
3939
extern const oapv_fn_sad_t oapv_tbl_fn_sad_16b_avx[2];
4040
extern const oapv_fn_ssd_t oapv_tbl_fn_ssd_16b_avx[2];
4141
extern const oapv_fn_diff_t oapv_tbl_fn_diff_16b_avx[2];

src/avx/oapv_tq_avx.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "oapv_def.h"
3333
#include "oapv_tq_avx.h"
3434

35+
#if X86_SSE
3536
#ifndef _mm256_set_m128i
3637
#define _mm256_set_m128i(/* __m128i */ hi, /* __m128i */ lo) \
3738
_mm256_insertf128_si256(_mm256_castsi128_si256(lo), (hi), 0x1)
@@ -560,4 +561,5 @@ const oapv_fn_itx_adj_t oapv_tbl_fn_itx_adj_avx[2] =
560561
{
561562
oapv_adjust_itrans_avx,
562563
NULL,
563-
};
564+
};
565+
#endif /* X86_SSE */

0 commit comments

Comments
 (0)