88import re
99
1010INTERMEDIATE_LIB_PATTERN = re .compile (r".*\.so\.\d+|.*\.\d+\.dylib$" ) # skip foo.so.1, foo.1.dylib etc
11+ MACOS_CMAKE_ARCH = {"x64" : "x86_64" , "arm64" : "arm64" }
12+ DEFAULT_MACOS_DEPLOYMENT_TARGET = {"x64" : "10.14" , "arm64" : "11.0" }
1113
1214
1315def get_os ():
@@ -34,11 +36,31 @@ def get_arch():
3436 return machine
3537
3638
37- def configure_cmake (build_dir , source_dir , options = [], env = None ):
39+ def get_target_arch (arch = None ):
40+ """Get the requested target architecture or fall back to the host arch."""
41+ return arch if arch else get_arch ()
42+
43+
44+ def get_cmake_configure_args (arch = None , macos_min_version = None ):
45+ """Get target-specific CMake configure arguments."""
46+ os_name = get_os ()
47+ arch_name = get_target_arch (arch )
48+ cmake_args = []
49+
50+ if os_name == "mac" :
51+ cmake_args .append (f"-DCMAKE_OSX_ARCHITECTURES={ MACOS_CMAKE_ARCH [arch_name ]} " )
52+ deployment_target = macos_min_version or DEFAULT_MACOS_DEPLOYMENT_TARGET [arch_name ]
53+ cmake_args .append (f"-DCMAKE_OSX_DEPLOYMENT_TARGET={ deployment_target } " )
54+
55+ return cmake_args
56+
57+
58+ def configure_cmake (build_dir , source_dir , options = None , env = None ):
3859 """Configure CMake with given options."""
60+ options = options or []
3961 options = options + ["-DCMAKE_BUILD_TYPE=Release" ]
4062 os .makedirs (build_dir , exist_ok = True )
41- cmake_cmd = ["cmake" , "-S" , source_dir , "-B" , build_dir ] + options
63+ cmake_cmd = ["cmake" ] + [ "-S" , source_dir , "-B" , build_dir ] + options
4264 print (f"Configuring CMake: { ' ' .join (cmake_cmd )} " )
4365
4466 result = subprocess .run (cmake_cmd , env = env )
@@ -116,7 +138,7 @@ def get_target(get_platform_name_func, variant_name, arch=None):
116138 """
117139 platform_name = get_platform_name_func ()
118140 os_name = get_os ()
119- arch_name = arch if arch else get_arch ( )
141+ arch_name = get_target_arch ( arch )
120142 target = f"{ os_name } -{ arch_name } -{ platform_name } -{ variant_name } "
121143 return target
122144
@@ -194,6 +216,7 @@ def build_project(
194216 get_env_func = None ,
195217 arch = None ,
196218 variant = None ,
219+ macos_min_version = None ,
197220):
198221 """Common build logic for all backends.
199222
@@ -206,6 +229,7 @@ def build_project(
206229 get_additional_files_func: Optional function that returns additional files
207230 get_env_func: Optional function that returns environment dict for cmake
208231 arch: Optional architecture to build for
232+ macos_min_version: Optional macOS deployment target override
209233 """
210234 # Check if platform module has get_variants function
211235 variants = []
@@ -225,6 +249,7 @@ def build_project(
225249
226250 # Get target for "any" variant to use for additional files
227251 target_any = get_target (get_platform_name_func , "any" , arch )
252+ cmake_args = get_cmake_configure_args (arch , macos_min_version )
228253
229254 # Get environment for cmake
230255 env = get_env_func (target_any ) if get_env_func else None
@@ -239,7 +264,7 @@ def build_project(
239264
240265 # Combine base compile flags with variant-specific flags
241266 base_options = get_compile_flags_func (target_any )
242- options = base_options + variant_compile_flags
267+ options = cmake_args + base_options + variant_compile_flags
243268
244269 # Resolve additional files if available
245270 additional_files = get_additional_files_func () if get_additional_files_func else []
0 commit comments