Skip to content

Commit e78d986

Browse files
Support native Apple ARM64 (#461)
# Support native Apple ARM64 ### Linked issues n/a ### Summarize your change. Supporting both x86_64 and arm64 native build. You can build x86_64 on MacOS if you run the build under a terminal launched with `arch -x86_64` (using Rosetta). I made changes to some dependencies under `cmake/dependencies` to standardized the `configure`, `command` and `install` command used in `externalproject_add` since some dependencies were using a mix of CMake and Make command. ### Describe the reason for the change. Support native build of Apple chipset. ### Describe what you have tested and on which operating system. - [x] MacOS - [x] Windows (CI) - [x] Rocky Linux 9 (CI) ### Add a list of changes, and note any that might need special attention during the review. ### If possible, provide screenshots. --------- Signed-off-by: Cédrik Fuoco <[email protected]>
1 parent e31d1d0 commit e78d986

28 files changed

+184
-378
lines changed

cmake/defaults/cxx_clang_defaults.cmake

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ ELSE()
1313
)
1414
ENDIF()
1515

16+
IF(NOT RV_TARGET_APPLE_ARM64)
17+
SET(__compiler_options_x86_64 -msse -msse2 -msse3 -mmmx)
18+
ENDIF()
19+
20+
SET(__compiler_options__
21+
-Wall ${__compiler_options_x86_64}
22+
)
23+
1624
# Common options
1725
ADD_COMPILE_OPTIONS(
1826
${_verbose_invocation}
19-
-Wall
27+
${_compiler_options__}
2028
-Wnonportable-include-path
21-
-msse
22-
-msse2
23-
-msse3
24-
-mmmx
2529
)
2630

2731
IF(${CMAKE_BUILD_TYPE} STREQUAL "Release")

cmake/defaults/rv_targets.cmake

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ SET(CMAKE_SKIP_RPATH
99
)
1010

1111
IF(APPLE)
12+
# Only native builds are supported (x86_64 on Intel MacOS and ARM64 on Apple chipset).
13+
# Rosetta can be used to build x86_64 on Apple chipset.
14+
IF("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
15+
SET(RV_TARGET_APPLE_X86_64
16+
ON
17+
CACHE INTERNAL "Compile for x86_64 on Apple MacOS" FORCE
18+
)
19+
SET(__target_arch__ -DRV_ARCH_X86_64)
20+
ELSEIF("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "arm64")
21+
SET(RV_TARGET_APPLE_ARM64
22+
ON
23+
CACHE INTERNAL "Compile for arm64 on Apple MacOS" FORCE
24+
)
25+
SET(__target_arch__ -DRV_ARCH_ARM64)
26+
ENDIF()
27+
28+
MESSAGE(STATUS "Building for ${CMAKE_HOST_SYSTEM_PROCESSOR}")
29+
ADD_COMPILE_OPTIONS(${__target_arch__})
30+
1231
# Darwin is the name of the mach BSD-base kernel :-)
1332
SET(RV_TARGET_DARWIN
1433
BOOL TRUE "Detected target is Apple's macOS"
@@ -18,18 +37,6 @@ IF(APPLE)
1837
"Darwin"
1938
CACHE INTERNAL ""
2039
)
21-
SET(CMAKE_OSX_ARCHITECTURES
22-
"x86_64"
23-
CACHE STRING "Force compilation for Intel processors." FORCE
24-
)
25-
26-
SET(RV_OSX_EMULATION
27-
ON
28-
)
29-
SET(RV_OSX_EMULATION_ARCH
30-
"-x86_64"
31-
CACHE STRING "Architecture to use while building the dependencies" FORCE
32-
) # Set to empty string for native
3340

3441
# The code makes extensive use of the 'PLATFORM_DARWIN' definition
3542
SET(PLATFORM
@@ -145,4 +152,4 @@ ELSEIF(WIN32)
145152
ELSE()
146153
MESSAGE(FATAL_ERROR "Unsupported platform")
147154

148-
ENDIF()
155+
ENDIF()

cmake/dependencies/atomic_ops.cmake

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,6 @@ SET(_autogen_command
5656
sh ./autogen.sh
5757
)
5858

59-
IF(${RV_OSX_EMULATION})
60-
SET(_darwin_x86_64
61-
"arch" "${RV_OSX_EMULATION_ARCH}"
62-
)
63-
64-
SET(_make_command
65-
${_darwin_x86_64} ${_make_command}
66-
)
67-
SET(_configure_command
68-
${_darwin_x86_64} ${_configure_command}
69-
)
70-
SET(_autogen_command
71-
${_darwin_x86_64} ${_autogen_command}
72-
)
73-
ENDIF()
74-
7559
# Make sure NOT to enable GPL
7660
SET(_configure_args
7761
"--disable-gpl"

cmake/dependencies/boost.cmake

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,6 @@ ELSE()
159159
)
160160
ENDIF()
161161

162-
IF(${RV_OSX_EMULATION})
163-
SET(_darwin_x86_64
164-
"arch" "${RV_OSX_EMULATION_ARCH}"
165-
)
166-
167-
SET(_b2_command
168-
${_darwin_x86_64} ${_b2_command}
169-
)
170-
SET(_bootstrap_command
171-
${_darwin_x86_64} ${_bootstrap_command}
172-
)
173-
ENDIF()
174-
175162
IF(RV_TARGET_WINDOWS)
176163
SET(_boost_python_bin
177164
${RV_DEPS_BASE_DIR}/RV_DEPS_PYTHON3/install/python.exe
@@ -190,6 +177,13 @@ LIST(
190177
OUTPUT_VARIABLE _boost_with_list
191178
)
192179

180+
SET(__boost_arch__ x86)
181+
IF(APPLE)
182+
IF(RV_TARGET_APPLE_ARM64)
183+
SET(__boost_arch__ arm)
184+
ENDIF()
185+
ENDIF()
186+
193187
EXTERNALPROJECT_ADD(
194188
${_target}
195189
DEPENDS Python::Python
@@ -204,7 +198,7 @@ EXTERNALPROJECT_ADD(
204198
BUILD_COMMAND
205199
# Ref.: https://www.boost.org/doc/libs/1_70_0/tools/build/doc/html/index.html#bbv2.builtin.features.cflags Ref.:
206200
# https://www.boost.org/doc/libs/1_76_0/tools/build/doc/html/index.html#bbv2.builtin.features.cflags
207-
./b2 -a -q toolset=${_toolset} cxxstd=${RV_CPP_STANDARD} variant=${_boost_variant} link=shared threading=multi architecture=x86 address-model=64
201+
./b2 -a -q toolset=${_toolset} cxxstd=${RV_CPP_STANDARD} variant=${_boost_variant} link=shared threading=multi architecture=${__boost_arch__} address-model=64
208202
${_boost_with_list} ${_boost_b2_options} -j${_cpu_count} install --prefix=${_install_dir}
209203
INSTALL_COMMAND echo "Boost was both built and installed in the build stage"
210204
BUILD_IN_SOURCE TRUE

cmake/dependencies/dav1d.cmake

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,22 @@ SET(_make_command
5353
ninja
5454
)
5555

56-
IF(${RV_OSX_EMULATION})
57-
SET(_meson_cross_file
58-
"${PROJECT_SOURCE_DIR}/src/build/meson_arch_x86_64.txt"
59-
)
56+
IF(APPLE)
57+
# Cross-file must be specified because if Rosetta is used to compile for x86_64 from ARM64,
58+
# Meson still detects ARM64 as the default architecture.
59+
60+
IF(RV_TARGET_APPLE_X86_64)
61+
SET(_meson_cross_file
62+
"${PROJECT_SOURCE_DIR}/src/build/meson_arch_x86_64.txt"
63+
)
64+
ELSEIF(RV_TARGET_APPLE_ARM64)
65+
SET(_meson_cross_file
66+
"${PROJECT_SOURCE_DIR}/src/build/meson_arch_arm64.txt"
67+
)
68+
ENDIF()
69+
6070
SET(_configure_command
61-
${_configure_command} "--cross-file" ${_meson_cross_file}
71+
${_configure_command} "--cross-file" ${_meson_cross_file}
6272
)
6373
ENDIF()
6474

cmake/dependencies/ffmpeg.cmake

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,6 @@ SET(_configure_command
5252
sh ./configure
5353
)
5454

55-
IF(${RV_OSX_EMULATION})
56-
SET(_darwin_x86_64
57-
"arch" "${RV_OSX_EMULATION_ARCH}"
58-
)
59-
60-
SET(_make_command
61-
${_darwin_x86_64} ${_make_command}
62-
)
63-
SET(_configure_command
64-
${_darwin_x86_64} ${_configure_command}
65-
)
66-
ENDIF()
67-
6855
SET(_include_dir
6956
${_install_dir}/include
7057
)

cmake/dependencies/gc.cmake

Lines changed: 30 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
INCLUDE(ProcessorCount) # require CMake 3.15+
88
PROCESSORCOUNT(_cpu_count)
99

10-
SET(_target
11-
"RV_DEPS_GC"
12-
)
13-
14-
SET(_version
15-
"8.2.2"
16-
)
10+
RV_CREATE_STANDARD_DEPS_VARIABLES("RV_DEPS_GC" "8.2.2" "" "")
1711

1812
SET(_download_url
1913
"https://github.com/ivmai/bdwgc/archive/refs/tags/v${_version}.zip"
@@ -26,42 +20,16 @@ SET(_install_dir
2620
${RV_DEPS_BASE_DIR}/${_target}/install
2721
)
2822

29-
SET(_make_command
30-
make
31-
)
32-
SET(_autogen_command
33-
sh ./autogen.sh
34-
)
35-
SET(_configure_command
36-
sh ./configure
37-
)
38-
39-
IF(${RV_OSX_EMULATION})
40-
SET(_darwin_x86_64
41-
"arch" "${RV_OSX_EMULATION_ARCH}"
42-
)
43-
44-
SET(_make_command
45-
${_darwin_x86_64} ${_make_command}
46-
)
47-
SET(_autogen_command
48-
${_darwin_x86_64} ${_autogen_command}
49-
)
50-
SET(_configure_command
51-
${_darwin_x86_64} ${_configure_command}
23+
IF(RV_TARGET_LINUX)
24+
SET(_lib_dir
25+
${_install_dir}/lib64
5226
)
53-
ENDIF()
54-
IF(RV_TARGET_WINDOWS)
55-
# MSYS2/CMake defaults to Ninja
56-
SET(_make_command
57-
ninja
27+
ELSE()
28+
SET(_lib_dir
29+
${_install_dir}/lib
5830
)
5931
ENDIF()
6032

61-
SET(_lib_dir
62-
${_install_dir}/lib
63-
)
64-
6533
SET(_gc_lib_name
6634
${CMAKE_SHARED_LIBRARY_PREFIX}gc.1${CMAKE_SHARED_LIBRARY_SUFFIX}
6735
)
@@ -115,64 +83,33 @@ SET(_include_dir
11583
)
11684
FILE(MAKE_DIRECTORY ${_include_dir})
11785

86+
LIST(APPEND _configure_options "-Denable_parallel_mark=ON")
87+
LIST(APPEND _configure_options "-Denable_cplusplus=ON")
11888
IF(RV_TARGET_WINDOWS)
119-
SET(_cmake_configure_command
120-
${CMAKE_COMMAND}
121-
)
122-
LIST(APPEND _cmake_configure_command "-DCMAKE_INSTALL_PREFIX=${_install_dir}")
123-
LIST(APPEND _cmake_configure_command "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}")
124-
LIST(APPEND _cmake_configure_command "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
125-
LIST(APPEND _cmake_configure_command "-Denable_parallel_mark=ON")
126-
LIST(APPEND _cmake_configure_command "-Denable_cplusplus=ON")
127-
LIST(APPEND _cmake_configure_command "-DCMAKE_USE_WIN32_THREADS_INIT=1")
128-
LIST(APPEND _cmake_configure_command "${RV_DEPS_BASE_DIR}/${_target}/src")
129-
EXTERNALPROJECT_ADD(
130-
${_target}
131-
DOWNLOAD_NAME ${_target}_${_version}.zip
132-
DOWNLOAD_DIR ${RV_DEPS_DOWNLOAD_DIR}
133-
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
134-
SOURCE_DIR ${RV_DEPS_BASE_DIR}/${_target}/src
135-
INSTALL_DIR ${_install_dir}
136-
URL ${_download_url}
137-
URL_MD5 ${_download_hash}
138-
CONFIGURE_COMMAND ${_cmake_configure_command}
139-
BUILD_COMMAND ${_make_command} -j${_cpu_count}
140-
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ${RV_DEPS_BASE_DIR}/${_target}/src/include ${_include_dir}/gc
141-
COMMAND ${CMAKE_COMMAND} -E copy ${RV_DEPS_BASE_DIR}/${_target}/src/${_gc_lib_name} ${_gc_lib}
142-
BUILD_IN_SOURCE TRUE
143-
BUILD_ALWAYS FALSE
144-
BUILD_BYPRODUCTS ${_gc_byproducts}
145-
USES_TERMINAL_BUILD TRUE
146-
)
147-
ADD_LIBRARY(BDWGC::Gc STATIC IMPORTED GLOBAL)
89+
LIST(APPEND _configure_options "-DCMAKE_USE_WIN32_THREADS_INIT=1")
14890
ELSE()
149-
SET(_configure_args
150-
"--enable-cplusplus"
151-
)
152-
LIST(APPEND _configure_args "--prefix=${_install_dir}")
153-
154-
EXTERNALPROJECT_ADD(
155-
${_target}
156-
DOWNLOAD_NAME ${_target}_${_version}.zip
157-
DOWNLOAD_DIR ${RV_DEPS_DOWNLOAD_DIR}
158-
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
159-
SOURCE_DIR ${RV_DEPS_BASE_DIR}/${_target}/src
160-
INSTALL_DIR ${_install_dir}
161-
URL ${_download_url}
162-
URL_MD5 ${_download_hash}
163-
CONFIGURE_COMMAND ${_autogen_command} && ${_configure_command} ${_configure_args}
164-
BUILD_COMMAND ${_make_command} -j${_cpu_count}
165-
INSTALL_COMMAND ${_make_command} install
166-
COMMAND ${CMAKE_COMMAND} -E copy_directory ${_install_dir} ${CMAKE_BINARY_DIR}
167-
COMMAND ${CMAKE_COMMAND} -E copy_directory ${_install_dir}/lib ${RV_STAGE_LIB_DIR}
168-
BUILD_IN_SOURCE TRUE
169-
BUILD_ALWAYS FALSE
170-
BUILD_BYPRODUCTS ${_gc_byproducts}
171-
USES_TERMINAL_BUILD TRUE
172-
)
173-
ADD_LIBRARY(BDWGC::Gc SHARED IMPORTED GLOBAL)
91+
LIST(APPEND _configure_options "-DCMAKE_USE_PTHREADS_INIT=1")
17492
ENDIF()
17593

94+
EXTERNALPROJECT_ADD(
95+
${_target}
96+
DOWNLOAD_NAME ${_target}_${_version}.zip
97+
DOWNLOAD_DIR ${RV_DEPS_DOWNLOAD_DIR}
98+
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
99+
SOURCE_DIR ${RV_DEPS_BASE_DIR}/${_target}/src
100+
INSTALL_DIR ${_install_dir}
101+
URL ${_download_url}
102+
URL_MD5 ${_download_hash}
103+
CONFIGURE_COMMAND ${CMAKE_COMMAND} ${_configure_options}
104+
BUILD_COMMAND ${_cmake_build_command}
105+
INSTALL_COMMAND ${_cmake_install_command}
106+
BUILD_IN_SOURCE TRUE
107+
BUILD_ALWAYS FALSE
108+
BUILD_BYPRODUCTS ${_gc_byproducts}
109+
USES_TERMINAL_BUILD TRUE
110+
)
111+
ADD_LIBRARY(BDWGC::Gc STATIC IMPORTED GLOBAL)
112+
176113
ADD_DEPENDENCIES(BDWGC::Gc ${_target})
177114
SET_PROPERTY(
178115
TARGET BDWGC::Gc

cmake/dependencies/glew.cmake

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
INCLUDE(ProcessorCount) # require CMake 3.15+
88
PROCESSORCOUNT(_cpu_count)
99

10-
SET(_target
11-
"RV_DEPS_GLEW"
12-
)
13-
14-
SET(_version
15-
"e1a80a9f12d7def202d394f46e44cfced1104bfb"
16-
)
10+
RV_CREATE_STANDARD_DEPS_VARIABLES("RV_DEPS_GLEW" "e1a80a9f12d7def202d394f46e44cfced1104bfb" "make" "")
1711

1812
SET(_download_url
1913
"https://github.com/nigels-com/glew/archive/${_version}.zip"
@@ -50,20 +44,6 @@ SET(_glew_lib
5044
${_lib_dir}/${_glew_lib_name}
5145
)
5246

53-
SET(_make_command
54-
make
55-
)
56-
57-
IF(${RV_OSX_EMULATION})
58-
SET(_darwin_x86_64
59-
"arch" "${RV_OSX_EMULATION_ARCH}"
60-
)
61-
62-
SET(_make_command
63-
${_darwin_x86_64} ${_make_command}
64-
)
65-
ENDIF()
66-
6747
EXTERNALPROJECT_ADD(
6848
${_target}
6949
SOURCE_DIR ${RV_DEPS_BASE_DIR}/${_target}/src
@@ -72,7 +52,7 @@ EXTERNALPROJECT_ADD(
7252
URL_MD5 ${_download_hash}
7353
DOWNLOAD_NAME ${_target}_${_version}.zip
7454
DOWNLOAD_DIR ${RV_DEPS_DOWNLOAD_DIR}
75-
CONFIGURE_COMMAND cd auto && ${_make_command}
55+
CONFIGURE_COMMAND cd auto && ${_make_command} && cd .. && ${_make_command}
7656
BUILD_COMMAND ${_make_command} -j${_cpu_count} GLEW_DEST=${_install_dir}
7757
INSTALL_COMMAND ${_make_command} install GLEW_DEST=${_install_dir}
7858
BUILD_IN_SOURCE TRUE

0 commit comments

Comments
 (0)